Occasionally hanging requests

this is almost the easiest bug in the world to reproduce.

  1. set up 3 mongrels behind ngnix.
  2. add ‘sleep 20’ to one controller action
  3. open up 1 browser window and hit the sleep action
  4. open up another browser window and hit any other action over and
    over
  5. watch as every 3rd request hangs

this may seem like a contrived test but when that ‘sleep 20’ is
actually a long running db query you’ll see very quickly how it can
adversely affect your site.

the problem seems to be that nginx will keep forwarding requests to
mongrel since mongrel will happily accept them. the mutexed rails
thread is hanging and not mongrel. you can also reproduce this issue
with apache and mod_proxy_balancer.

wait… i think i figured it out. set the number of mongrel threads to
1 when you start up mongrel (via -n 1). seems like this should be the
default when you have a proxy in front of mongrel.

This is because rails is single-threaded and cannot handle more than
one request at a time. Try HAproxy, which has a more intelligent load
balancer which can limit number of simultaneous connections to a
backend (in mongrel’s case running rails, it should be 1).

Try swiftiply and evented mongrels too and see how it goes for you.

Later,
Vish

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs