modrails - rogue ruby processes consuming 100% cpu modrails - rogue ruby processes consuming 100% cpu ruby-on-rails ruby-on-rails

modrails - rogue ruby processes consuming 100% cpu


If you're using Linux, you can install the "strace" utility to see what the Ruby process is doing that's consuming all the CPU. That will give you a good low-level view. It should be available in your package manager. Then you can:

$ sudo strace -p 22710Process 22710 attached - interrupt to quit...lots of stuff...(press Ctrl+C)

Then, if you want to stop the process in the middle and dump a stack trace, you can follow the guide on using GDB in Ruby at http://eigenclass.org/hiki.rb?ruby+live+process+introspection, specifically doing:

gdb --pid=(ruby process)session-rubystdout_redirect(in other terminal) tail -f /tmp/ruby_debug.(pid)eval "caller"

You can also use the ruby-debug Gem to remotely connect to debug sockets you open up, described in http://duckpunching.com/passenger-mod_rails-for-development-now-with-debugger

There also seems to be a project on Github concerned with debugging Passenger instances that looks interesting, but the documentation is lacking:http://github.com/ddollar/socket-debugger/tree/master


I had a ruby process related to Phusion Passenger, which consumed lots of CPU, even though it should have been idle.

The problem went away after I ran

date -s "`date`"

as suggested in this thread. (That was on Debian Squeeze)

Apparently, the problem was related to a leap second, and could affect many other applications like MySQL, Java, etc. More info in this thread on lklm.


We saw something similar to this with very long running SQL queries.

MySQL would kill the queries because they exceeded the long running limit and the thread never realized that the query was dead.

You may want to check the database logs.