# Are Mongrel instances "sticky" with respect to sessions?

**URL:** <https://www.ruby-forum.com/t/are-mongrel-instances-sticky-with-respect-to-sessions/83157>\
**Category:** Rails\
**Created:** [January 23, 2007, 11:06pm UTC](https://www.ruby-forum.com/t/are-mongrel-instances-sticky-with-respect-to-sessions/83157 "2007-01-23T23:06:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [January 23, 2007, 11:06pm UTC](https://www.ruby-forum.com/t/are-mongrel-instances-sticky-with-respect-to-sessions/83157/1 "2007-01-23T23:06:07Z")

</div>

All,

If you deploy multiple Mongrel instances, is it possible to have  
affinity between a given session (e.g. session id) and a Mongrel  
instance? How is that done?

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [January 24, 2007, 3:55am UTC](https://www.ruby-forum.com/t/are-mongrel-instances-sticky-with-respect-to-sessions/83157/2 "2007-01-24T03:55:18Z")

</div>

On Jan 23, 2007, at 2:06 PM, Wes G. wrote:

> If you deploy multiple Mongrel instances, is it possible to have  
> affinity between a given session (e.g. session id) and a Mongrel  
> instance? How is that done?

Hello Wes.

Session affinity is generally achieved at the load balancer level,  
and Apache 2.2 supports this as well.

See [mod\_proxy - Apache HTTP Server Version 2.2](http://httpd.apache.org/docs/2.2/mod/mod_proxy.html) and search  
locally for lbmethod for details.

Why do you want session affinity? It makes a ton of sense is HUGE  
installations, but not so much for smaller ones.

–  
– Tom M., CTO  
– Engine Y., Ruby on Rails Hosting  
– Reliability, Ease of Use, Scalability  
– (866) 518-YARD (9273)

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [January 24, 2007, 4:51pm UTC](https://www.ruby-forum.com/t/are-mongrel-instances-sticky-with-respect-to-sessions/83157/3 "2007-01-24T16:51:44Z")

</div>

> Why do you want session affinity? It makes a ton of sense is HUGE  
> installations, but not so much for smaller ones.

Because I ended up having to use a custom in-memory persistence scheme  
to handle objects that were too large to place on the session (and would  
cause Rails to crash during session serialization/deserialization). So  
I have a hash which stores some larger things (parsed HTML and Excel  
spreadsheet data) that I would like to keep around across requests given  
the relatively high cost of generating them.

If I need to go to two or more Mongrels (which I almost certainly will),  
the hashes will be private to each Mongrel instance (Ruby process) and  
won’t be shared. Which of course, implies that I might end up  
generating these objects up to N times where N is the number of Mongrel  
instances.

So I would like to either take advantage of session affinity for a given  
Mongrel process to be sure that a given artifact generated on behalf of  
a given user and managed in my hash is only generated once.

If session affinity doesn’t work with Mongrel, then I guess I can look  
into Drb.

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [January 24, 2007, 4:54pm UTC](https://www.ruby-forum.com/t/are-mongrel-instances-sticky-with-respect-to-sessions/83157/4 "2007-01-24T16:54:50Z")

</div>

Tom M. wrote:

> Session affinity is generally achieved at the load balancer level,  
> and Apache 2.2 supports this as well.
> 
> See [mod\_proxy - Apache HTTP Server Version 2.2](http://httpd.apache.org/docs/2.2/mod/mod_proxy.html) and search  
> locally for lbmethod for details.

Tom,

Thanks. Just looked at the Apache docs. and I see how this appears to  
be supported.

Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [January 24, 2007, 6:38pm UTC](https://www.ruby-forum.com/t/are-mongrel-instances-sticky-with-respect-to-sessions/83157/5 "2007-01-24T18:38:57Z")

</div>

Wes G. wrote:

> 

…

> If session affinity doesn’t work with Mongrel, then I guess I can look  
> into Drb.
> 
> Thanks,  
> Wes

Check out memcached -

[http://nubyonrails.com/articles/2006/08/17/memcached-basics-for-rails](http://nubyonrails.com/articles/2006/08/17/memcached-basics-for-rails)

sounds like your scheme implements a subset of what memcached already  
does.

HTH,

-b
