Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I diagnose my very slow Ruby startup times?

Tags:

macos

ruby

Intermittently, when I type a command that involves Ruby (like ruby somefile.rb, rake, rspec spec, or irb), it takes a long time for the command to execute. For example, a few minutes ago, it took about a minute for irb to start. A few seconds ago, it took about a second.

While waiting for irb to start, I pressed Control + T repeatedly. Some output 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 running, pid, status, and user and system CPU time used". It appears that when I had been waiting 53 seconds, the CPU time used was only 0.15 seconds.

My understanding of load is that it's roughly "how many cores are being used". Eg, on a one-core system, 1.0 is full utilization, but on a four-core machine, it's 25% utilization. I don't think the amount of load is the problem, because my machine is multi-core. Also, when irb starts quickly, I can get one line of output with Control + T that's also above 1.0.

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

I also notice that in the good case, the status is "running", not "uninterruptible".

How can I diagnose and fix these slow startups?

like image 472
Nathan Long Avatar asked Dec 11 '25 21:12

Nathan Long


1 Answers

This is a longshot. Try installing haveged.

  • http://freecode.com/projects/haveged

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

If you notice that the time for something to start goes quickly when you are typing more, moving your mouse, using a lot of network traffic -- then it's entropy, which would go against most of what you'd think.

If there is more processor and RAM usage, more interaction with the system, etc - you'd think it'd be slower, but in entropy depletion situations, that's actually exactly what you need.

like image 97
digitalextremist Avatar answered Dec 14 '25 12:12

digitalextremist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!