# Occasionally hanging requests

**URL:** <https://www.ruby-forum.com/t/occasionally-hanging-requests/117775>\
**Category:** Deployment\
**Created:** [October 20, 2007, 2:30am UTC](https://www.ruby-forum.com/t/occasionally-hanging-requests/117775 "2007-10-20T02:30:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![famoseagle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecc23a/32.png) [@famoseagle](https://www.ruby-forum.com/u/famoseagle)\
**Post date:** [October 20, 2007, 2:30am UTC](https://www.ruby-forum.com/t/occasionally-hanging-requests/117775/1 "2007-10-20T02:30:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![famoseagle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecc23a/32.png) [@famoseagle](https://www.ruby-forum.com/u/famoseagle)\
**Post date:** [October 20, 2007, 2:50am UTC](https://www.ruby-forum.com/t/occasionally-hanging-requests/117775/2 "2007-10-20T02:50:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![famoseagle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecc23a/32.png) [@famoseagle](https://www.ruby-forum.com/u/famoseagle)\
**Post date:** [October 20, 2007, 9:05am UTC](https://www.ruby-forum.com/t/occasionally-hanging-requests/117775/3 "2007-10-20T09:05:54Z")

</div>

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
