How can I diagnose my very slow Ruby startup times?

With breaks, when I type a command that includes Ruby (such as ruby somefile.rb

, rake

, rspec spec

or irb

) to perform the command takes a long time. For example, a few minutes ago it irb

took about a minute to start up . It took about a second a few seconds ago.

While waiting for the launch, irb

I pressed Control + T

several times. Some of the results I saw included:

load: 1.62  cmd: ruby 12374 uninterruptible 0.45u 0.13s
load: 1.62  cmd: ruby 12374 uninterruptible 0.48u 0.13s
load: 1.62  cmd: ruby 12374 uninterruptible 0.53u 0.15s

      

On OSX, this output represents "load, command run, pid, status and time of cpu and user usage". It looks like when I waited 53 seconds the CPU time was only 0.15 seconds.

My understanding of the load is that it is roughly "how many cores are in use" . For example, on a single-core system, 1.0 is fully used, but on a quad-core machine, it is 25%. I don't think it's a load issue because my machine is multi-core. Also, when it irb

starts up quickly, I can get one line of output from Control + T

which is also above 1.0

.

load: 1.22  cmd: ruby 12452 running 0.26u 0.02s

      

I also notice that in a good case the status is "running" rather than "no interruption".

How can I diagnose and fix these slow startups?

+3


source to share


1 answer


This is a long shot. Try to install haveged

.

I've seen this problem before. This solved it for me. Sometimes there is not enough entropy for libraries or Ruby elements trying to load a pool of random numbers.



If you notice that the time to start something goes quickly when you are typing more, moving your mouse, using a lot of network traffic, this is an entropy that will contradict most of what you think.

If the CPU and RAM usage is more, there is more interaction with the system, etc. - you think it will be slower, but in situations of entropy depletion, which is actually exactly what you need.

+1


source







All Articles