# Shared memory across mongrels

**URL:** <https://www.ruby-forum.com/t/shared-memory-across-mongrels/135329>\
**Category:** Mongrel\
**Created:** [April 21, 2008, 8:39am UTC](https://www.ruby-forum.com/t/shared-memory-across-mongrels/135329 "2008-04-21T08:39:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sgudibanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@sgudibanda](https://www.ruby-forum.com/u/sgudibanda)\
**Post date:** [April 21, 2008, 8:39am UTC](https://www.ruby-forum.com/t/shared-memory-across-mongrels/135329/1 "2008-04-21T08:39:43Z")

</div>

Hi,

I have written an application which on initiliazation calculates a graph  
based on data in DB. And then any updates on the graph(global variable)  
, i am doing both on graph and db.

Everything works fine as long as i work on single mongrel. When i use 2  
mongrels, second mongrel cannot see graph in the memory. It gets a null  
variable.

How do i do this so that graph built in the memory is accessible to all  
mongrels?

Regards,  
Sandeep G

---

<div class="post-metadata">

**Author:** ![sgudibanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@sgudibanda](https://www.ruby-forum.com/u/sgudibanda)\
**Post date:** [April 21, 2008, 3:45pm UTC](https://www.ruby-forum.com/t/shared-memory-across-mongrels/135329/2 "2008-04-21T15:45:02Z")

</div>

> How do i do this so that graph built in the memory is accessible to all  
> mongrels?  
> Save data to a DB, or to a session variable ?  
> remember it’s like having two separate processes–they don’t share  
> memory at all by default.  
> -R

---

<div class="post-metadata">

**Author:** ![sgudibanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@sgudibanda](https://www.ruby-forum.com/u/sgudibanda)\
**Post date:** [April 21, 2008, 3:57pm UTC](https://www.ruby-forum.com/t/shared-memory-across-mongrels/135329/3 "2008-04-21T15:57:41Z")

</div>

Any this really isn’t a “mongrel” issue, but more an issue with the  
framework you’re using.

---

<div class="post-metadata">

**Author:** ![sgudibanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@sgudibanda](https://www.ruby-forum.com/u/sgudibanda)\
**Post date:** [April 28, 2009, 7:53am UTC](https://www.ruby-forum.com/t/shared-memory-across-mongrels/135329/4 "2009-04-28T07:53:45Z")

</div>

Sandeep’s question initial really simple, yet nobody has given him a  
satisfactory answer.

I wonder if Rails 2.2 or later provides built in support to share memory  
between multiple mongrel servers. I read that Rails 2.2 was  
multi-threaded so technically shared memory should be an optin.

If not, Phusion Passenger makes similar claims, yet when I go through  
it’s doco I can’t find any relevant pointers.

Pete

---

<div class="post-metadata">

**Author:** ![sgudibanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@sgudibanda](https://www.ruby-forum.com/u/sgudibanda)\
**Post date:** [April 21, 2008, 5:31pm UTC](https://www.ruby-forum.com/t/shared-memory-across-mongrels/135329/5 "2008-04-21T17:31:33Z")

</div>

Sandeep  
you may use a different ruby process to contain this graph and your  
mongrel  
based rails processes may talk to this drb instance and access the  
graph. 2  
or more mongrel process do not share any data as they are completely  
different processes.

Piyush

---

<div class="post-metadata">

**Author:** ![sgudibanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@sgudibanda](https://www.ruby-forum.com/u/sgudibanda)\
**Post date:** [April 28, 2009, 6:18pm UTC](https://www.ruby-forum.com/t/shared-memory-across-mongrels/135329/6 "2009-04-28T18:18:37Z")

</div>

There is no such facility. Passenger can’t do it either, copy-on-write  
is an optimization, not a shared memory space.

Using a local memcached instance is the easiest way.

Multithreading is not shared memory across processes, but might give  
you enough throughput that you only need to run one mongrel; then the  
threads themselves will all share the same heap.

Evan
