OpenSSL导致Windows上的Rails引导时间非常慢 [英] OpenSSL causing very slow Rails boot time on Windows
问题描述
我在Ruby on Rails的运行速度非常慢时遇到问题.我在Windows 8计算机上使用Ruby 2.1.3p242和Rails 4.2.1.
I'm having a problem with Ruby on Rails running extremely slowly. I'm using Ruby 2.1.3p242 and Rails 4.2.1 on a Windows 8 machine.
每当我运行任何需要Rails引导的东西(包括测试)时,它都将花费很长时间来启动和运行.我在干净安装的rails上对config/environment.rb中的Benchmark进行了一些调用:
Whenever I run anything that requires rails to boot (including tests) it takes a long time to get up and running. I put some calls to Benchmark in config/environment.rb on a clean install of rails:
require File.expand_path('../application', __FILE__)
User cpu System Cpu Total Cpu elapsed time
0.000000 0.000000 0.000000 (0.000000)
Rails.application.initialize!
15.282000 2.891000 18.173000 ( 18.201173)
很明显,Rails.application.initialize
花费很长的时间才能考虑干净安装.
Clearly Rails.application.initialize
is taking an absurdly long time considering its a clean install.
预先感谢您的帮助
Edit-1:我在具有4GB RAM的双核i3 4010u@1.7GHZ上运行.我认为我的机器并不会太糟糕,因为它可以很好地运行大多数事情.
Edit-1: I'm running on a dual core i3 4010u@1.7GHZ with 4gb of RAM. I don't think my machine is too bad as it runs most things very well.
我在Rails.application.initialize
上运行ruby-prof
并找到了罪魁祸首.一个进程占用了85%的运行时间:
Edit-2: I ran ruby-prof
on Rails.application.initialize
and found the culprit. A process was taking up 85% of the run time:
<Module::SecureRandom>#random_bytes
<Module::OpenSSL::Random>#random_bytes
这显然是在Ruby21/lib/ruby/2.1.0/securerandom.rb#62
中发生的
我在该文件中查找了第62行,这就是我发现的内容:
This is apparently occuring in Ruby21/lib/ruby/2.1.0/securerandom.rb#62
I looked up line 62 in that file and this is what I found:
return OpenSSL::Random.random_bytes(n)
所以有人知道这意味着什么吗?
So anyone have any idea what this means?
推荐答案
Edit-2:我在Rails.application.initialize上运行ruby-prof,发现 罪魁祸首.一个进程占用了85%的运行时间:
Edit-2: I ran ruby-prof on Rails.application.initialize and found the culprit. A process was taking up 85% of the run time:
<Module::SecureRandom>#random_bytes
<Module::OpenSSL::Random>#random_bytes
是的,在Windows上,用于为随机数生成器提供种子的OpenSSL代码是有问题的.请参阅OpenSSL Wiki上的随机数和Windows问题.
Yeah, the OpenSSL code for seeding the random number generator is problematic on Windows. See Random Numbers and Windows Issues on the OpenSSL wiki.
return OpenSSL::Random.random_bytes(n)
所以有人知道这意味着什么吗?
So anyone have any idea what this means?
Ruby返回随机数.在这种情况下,由于未提供其他种子,因此OpenSSL将在使用RAND_poll
重新调整随机数之前自动对自身进行种子处理.
Ruby is returning random numbers. In this case, OpenSSL will autoseed itself before retuning random number with RAND_poll
since no other seed was provided.
Ruby应该不调用RAND_poll
或允许它被库隐式调用.如果尚未为随机数生成器添加种子,则库将通过内部调用RAND_poll
自动为其自身添加种子.
Ruby should not call RAND_poll
or allow it to be implicitly called by the library. If the random number generator has not been seeded, then the library will automatically seed itself by calling RAND_poll
internally.
相反,Ruby应该使用 CryptGenRandom
,然后调用OpenSSL的RAND_seed
.这样可以避免调用RAND_poll
.
Rather, Ruby should read bytes from the OS using CryptGenRandom
, and then call OpenSSL's RAND_seed
. That will avoid the call to RAND_poll
.
这篇关于OpenSSL导致Windows上的Rails引导时间非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!