OpenSSL causing very slow Rails boot time on Windows

前端 未结 3 1456
别那么骄傲
别那么骄傲 2021-01-18 21:24

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.

Whenever I run anything that req

相关标签:
3条回答
  • 2021-01-18 22:10

    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
    

    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 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 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.

    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.

    0 讨论(0)
  • 2021-01-18 22:13

    I have been a windows rails dev for a while now. I have never solved this rails startup issue. Running a microsecond Rspec test takes rails 22 seconds to load on my PC. When I (temporarily) comment out the line in securerandom.rb (all ruby versions) and replace it with a hardcoded return the startup time is reduced to 10 seconds.

    #return OpenSSL::Random.random_bytes(n)
    return "\xD3\x04F\f0\xD6{G\xB9\x81"
    
    0 讨论(0)
  • 2021-01-18 22:18

    Putting this in my config/application.rb (before require 'rails/all') speeds up rails s by 10-15 seconds on windows.

    require 'securerandom'
    SecureRandom.hex(16)
    
    0 讨论(0)
提交回复
热议问题