# Threading Rails

**URL:** <https://www.ruby-forum.com/t/threading-rails/147029>\
**Category:** Mongrel\
**Created:** [August 27, 2008, 7:00pm UTC](https://www.ruby-forum.com/t/threading-rails/147029 "2008-08-27T19:00:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Parker\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/eada6e/32.png) [@Parker\_T](https://www.ruby-forum.com/u/Parker_T)\
**Post date:** [August 27, 2008, 7:00pm UTC](https://www.ruby-forum.com/t/threading-rails/147029/1 "2008-08-27T19:00:24Z")

</div>

Hey,

We (Pivotal Labs) have bee experimenting with Mongrel and Rails Edge  
to see what happens if we remove the mutex around the dispatch to  
Rails, our goal being to reduce memory usage in virtualized  
environments where memory is tight. We’re pretty happy with the  
results and ready to put together a real patch for Mongrel to allow  
users to run Rails this way. So, we’re ready to patch Mongrel to  
support this.

It probably doesn’t make sense to just remove the handler’s mutex  
around dispatch as this could lead to num-processors threads in rails  
concurrently. Probably we’ll want to limit that separately. I’m  
thinking we should patch the handler to optionally allow threading,  
then make mongrel\_rails support this + a limit on how many requests to  
process concurrenty.

I’m wondeing what kind of patch you would want, and whether anyone has  
suggestions.

Thanks,

pt.

---

<div class="post-metadata">

**Author:** ![Parker\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/eada6e/32.png) [@Parker\_T](https://www.ruby-forum.com/u/Parker_T)\
**Post date:** [August 27, 2008, 10:19pm UTC](https://www.ruby-forum.com/t/threading-rails/147029/2 "2008-08-27T22:19:50Z")

</div>

isn’t rails 2.2 / edge supposed to have threading built in ? or am I  
missing  
something here ?

also mongrel can handle multiple threads well . In fact I have tried it  
in  
mongrel handlers and it works very well (for 75 concurrent requests each  
taking 5 minutes to complete).

---

<div class="post-metadata">

**Author:** ![Parker\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/eada6e/32.png) [@Parker\_T](https://www.ruby-forum.com/u/Parker_T)\
**Post date:** [August 27, 2008, 10:29pm UTC](https://www.ruby-forum.com/t/threading-rails/147029/3 "2008-08-27T22:29:47Z")

</div>

On Wed, Aug 27, 2008 at 9:38 PM, Piyush R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> isn’t rails 2.2 / edge supposed to have threading built in ? or am I missing  
> something here ?

Rails 2.2 is thread-safe. This doesn’t mean that it is automatically  
used this way.

> also mongrel can handle multiple threads well . In fact I have tried it in  
> mongrel handlers and it works very well (for 75 concurrent requests each  
> taking 5 minutes to complete).

Mongrel can handle multiple threads, but Rails runs inside a big  
lock/mutex (because until 2.2 it isn’t thread-safe).

This whole discussion is about changing/removing the lock.

Jonathan

–  
Jonathan W.  
[http://blog.innerewut.de](http://blog.innerewut.de)  
[http://twitter.com/jweiss](http://twitter.com/jweiss)

---

<div class="post-metadata">

**Author:** ![Parker\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/eada6e/32.png) [@Parker\_T](https://www.ruby-forum.com/u/Parker_T)\
**Post date:** [August 28, 2008, 4:01am UTC](https://www.ruby-forum.com/t/threading-rails/147029/4 "2008-08-28T04:01:00Z")

</div>

FYI, we are pretty much done with this:

[http://github.com/pivotal/mongrel/tree/master](http://github.com/pivotal/mongrel/tree/master)

We’ll probably test it a bit more tomorrow and then release it into the  
wild.

Any feedback would be appreciated.

Thanks,

pt.
