During our sale, we had one particular request that came in and wedged the application: every time it hit, the mongrel process size zoomed steadily up to 500Mb, so we had to kill it. But finding out which request was doing this was tricky. The log files didn't help—with the amount of traffic we were getting, it was a small needle and a large haystack.
Eventually, we found the culprit. But it would have been a lot easier if I'd thought of this hack on Friday, and not after the sale ended.
If you put this into your application controller:
before_filter :set_process_name_from_request
def set_process_name_from_request
$0 = request.path[0,16]
end
after_filter :unset_process_name_from_request
def unset_process_name_from_request
$0 = request.path[0,15] + "*"
end
then Ruby will set the cmd field in your process control block to the first 16 characters of the request path. You can then use top to see what request is being handled by each mongrel.
Once the request has been handled, an asterisk sign is appended, so you can see the last URL when a mongrel becomes idle.
If your version of top doesn't show the short command by default, use the c keyboard command to see it.
This is probably common knowledge, but I thought it was cool.
A plugin that we had used for similar purpose:
http://purefiction.net/mongrel_proctitle/
Though it is more useful to track slow requests. Your idea of tracking what a instance was doing last is interesting.
Posted by: Deepak Kumar | November 30, 2008 at 11:49 PM
Thx a lot!
BTW: is there any possible PHP do it, too?
Posted by: magician | December 03, 2008 at 12:47 AM
Not common knowledge, and definitely cool. Thanks!
Posted by: Harold | December 04, 2008 at 04:19 PM
Thanks a lot. That was very useful. Implemented on all my ruby on rails websites :-)
Posted by: jm | December 10, 2008 at 02:32 AM
Hadn't thunk it. Gracias!
Posted by: bug | March 25, 2009 at 05:14 PM