Reputation: 126042
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?
Upvotes: 3
Views: 925
Reputation: 5993
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.
Upvotes: 1