views:

716

answers:

8

Hi all, I'm running into a problem in a Rails application. After some hours, the application seems to start hanging, and I wasn't able to find where the problem was. There was nothing relevant in the log files, but when I tried to get the url from a browser nothing happened (like mongrel accept the request but wasn't able to respond).

What do you think I can test to understand where the problem is?

Thanks for your help!

A: 

Are you sure the problem is caused by Mongrel? Have you tried running your application under WEBrick?

Can Berk Güder
A: 

There are a few things you can check, but since you say there's nothing in the logs to indicate error, it sounds like you might be running into a bug when using the log rotation feature of the Logger class. It causes mongrel to lock up. Instead of relying on Logger to rotate your logs, consider using logrotate or some other external log rotation service.

wulong
A: 

Does this happen at a set number of hours/days every time? How much RAM do you have?

Ryan Bigg
A: 

I had this same problem. The couple options I had narrowed it down to were MySQL adapter related. I was running on Red Hat Enterprise Linux 4 (or 5) and the app would hang after a given amount of idle time.

One suggested solution was to compile native MySQL bindings, I had been using the pure Ruby one.

The other was to set the timeout on the MySQL adapter higher than what the connection would idle out on. (I don't have the specific configuration recorded, but as I recall it was in environment.rb and it was some class variable in the mysql adapter.)

I don't recall if either of those solutions fixed it, we moved to Ubuntu shortly after that and hadn't had a problem since.

Otto
+1  A: 

I might get voted down for dodging the question, but I recently moved from nginx + mongrel to mod_rails and have been really impressed. Moving to a much simpler setup will undoubtedly save me headaches in the future.

It was a really easy transition, I'd highly recommend it.

Kevin Davis
A: 

Check the Mongrel FAQ: http://mongrel.rubyforge.org/wiki/FAQ

From my experience, mongrel hangs when:

  • the log file got too big (hundreds of megabytes in size). you have to setup log rotation.
  • the MySQL driver times out you have to change the timeout settings of your MySQL driver by adding this to your environment.rb: ActiveRecord::Base.verification_timeout = 14400 (this is further explained in the deployment section of the FAQ)
Radamanthus
A: 

We have experienced this same issue. First off, install the mongrel_proctitle gem

http://github.com/rtomayko/mongrel_proctitle/tree/master

This gem/plugin will allow you to view the mongrel processes via "ps" and you can see if a Mongrel is hung. An issue we have seen with Mongrel is that it will happily accept connections and enqueue them, then wedge itself. This plugin will help you see when a Mongrel has been wedged but then you must use another monitoring app to actually restart a a wedged Mongrel, something like Monit or God

You might also want to consider putting a more balanced reverse proxy in front of your Mongrels, something HAproxy, instead of nginx, Apache or Lighttpd. With a setting of "maxconn 1" in HAproxy you can assure that the queue is being maintained by HAproxy versus Mongrel. The other reverse proxies (nginx, Apache, Lighttpd) only do round-robin which means that they can load up your Mongrel queue, inadvertently.

My personal choice is God as it is much more flexible.

tl;dr Install this gem plugin and keep an eye on your Mongrels. Try Apache+Phusion Passenger.

Cody Caughlan
God is... quite unreliable in certain environments. I prefer Monit because it works everywhere.
Bob Aman
A: 

Unfortunately, Rails (and thereby Mongrel) using up too much memory over time and crashing is a known problem (50K+ Google entries for "Ruby, rails, crashing, memory"). The current ruby interpreter has the property that it sometimes simply fails entirely to give memory back to the system - it may reuse the memory it has but it won't give it up.

There are numerous schemes for monitoring, killing and restarting Mongrel instances in a production environment - for example: (choosing at random) rails monitor . Until the problem is fixed more decisively, one of these may be your best bet.

Joe Soul-bringer