OpenSSL causing very slow Rails boot time on Windows

前端 未结 3 1457
别那么骄傲
别那么骄傲 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:

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

提交回复
热议问题