# Swap problems with mongrel

**URL:** <https://www.ruby-forum.com/t/swap-problems-with-mongrel/122668>\
**Category:** Deployment\
**Created:** [December 10, 2007, 3:24pm UTC](https://www.ruby-forum.com/t/swap-problems-with-mongrel/122668 "2007-12-10T15:24:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![thabenksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@thabenksta](https://www.ruby-forum.com/u/thabenksta)\
**Post date:** [December 10, 2007, 3:24pm UTC](https://www.ruby-forum.com/t/swap-problems-with-mongrel/122668/1 "2007-12-10T15:24:26Z")

</div>

I have a Ubuntu linux setup with 512MB of RAM. We haven’t launched our  
site yet, so we only have about 100 unique visitors per day. Our site  
is very dynamic in nature (i.e. database driven). We are running Rails  
behind Apache 2.2 with 4 instances of Mongrel. However, we keep running  
out of memory and are swapping way too much.

My problem is very similar to what’s described here:  
[http://izumi.plan99.net/blog/?p=19](http://izumi.plan99.net/blog/?p=19)

Has anyone here run into this? I’m wondering what’s a good  
solution/workaround (e.g. JRuby instead of Mongrel, the fork() and  
ActiveRecord kluge).

Thanks.

---

<div class="post-metadata">

**Author:** ![thabenksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@thabenksta](https://www.ruby-forum.com/u/thabenksta)\
**Post date:** [December 11, 2007, 12:02pm UTC](https://www.ruby-forum.com/t/swap-problems-with-mongrel/122668/2 "2007-12-11T12:02:01Z")

</div>

4 mongrels should fit on 512 fine. does your app have a memory leak  
(ie  
do the mongrels grow in size over time?)  
are there other large packages that are taking lots of memory on your  
host?

as a baseline, 4 mongrels running rails on 512 sounds fine. you should  
look  
at what else is going on.

daniel

On Dec 10, 4:24 pm, Ben K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![thabenksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@thabenksta](https://www.ruby-forum.com/u/thabenksta)\
**Post date:** [December 11, 2007, 6:20pm UTC](https://www.ruby-forum.com/t/swap-problems-with-mongrel/122668/3 "2007-12-11T18:20:51Z")

</div>

Thanks, bakongo.

Since “top” always shows the 4 mongrel as the memory, I know the problem  
is with mongrel:

%MEM PID USER PR NI VIRT RES SHR S %CPU TIME+ COMMAND  
12.4 18763 root 16 0 109m 63m 3036 S 0 0:17.10  
mongrel\_rails  
12.4 18757 root 16 0 109m 63m 3020 S 0 0:16.86  
mongrel\_rails  
12.2 18760 root 16 0 108m 62m 3020 S 0 0:17.97  
mongrel\_rails  
12.1 18766 root 16 0 107m 62m 3040 S 0 0:16.13  
mongrel\_rails  
1.3 26804 root 16 0 55512 6992 3292 S 0 0:01.48 httpd  
1.2 3703 mysql 16 0 132m 6180 2692 S 0 0:13.91 mysqld

As for the memory leak, I’ll begin monitoring if the %MEM grows over  
time. I’m wondering if one of our plugins/gems is a problem (e.g.  
ferret) or even heavy SQL queries since our site is very dynamic in  
nature.

By the way, are there any good tools to detect if there is a memory  
leak?

Thanks again!

bakongo wrote:

> 4 mongrels should fit on 512 fine. does your app have a memory leak  
> (ie  
> do the mongrels grow in size over time?)  
> are there other large packages that are taking lots of memory on your  
> host?
> 
> as a baseline, 4 mongrels running rails on 512 sounds fine. you should  
> look  
> at what else is going on.
> 
> daniel
> 
> On Dec 10, 4:24 pm, Ben K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![thabenksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@thabenksta](https://www.ruby-forum.com/u/thabenksta)\
**Post date:** [December 11, 2007, 8:40pm UTC](https://www.ruby-forum.com/t/swap-problems-with-mongrel/122668/4 "2007-12-11T20:40:56Z")

</div>

Thanks, Daniel.

---

<div class="post-metadata">

**Author:** ![thabenksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@thabenksta](https://www.ruby-forum.com/u/thabenksta)\
**Post date:** [December 11, 2007, 6:55pm UTC](https://www.ruby-forum.com/t/swap-problems-with-mongrel/122668/5 "2007-12-11T18:55:18Z")

</div>

i guess i would try to figure out exactly under what conditions the  
memory  
runs out. if you figure our when this actually happens, you can go  
back  
to your rails production logs and see what triggered the fault, and  
work your  
way back from there. it may have nothing to do with the mongrels at  
all.

as for leaks, you could just use top every now and then and see if the  
mongrels are  
growing in size.  
also, you could just use 3 mongrels.

daniel

On Dec 11, 7:20 pm, Ben K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![thabenksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@thabenksta](https://www.ruby-forum.com/u/thabenksta)\
**Post date:** [December 12, 2007, 3:56pm UTC](https://www.ruby-forum.com/t/swap-problems-with-mongrel/122668/6 "2007-12-12T15:56:06Z")

</div>

Thanks, dima.

By the way, what’s a good way to determine how many mongrel instances  
are needed for a site?

Currently, we have 4 but I’m debating between reducing the instances to  
3 or, increasing our ISP account to give us 1GB RAM versus the existing  
512MB.

Thanks.

---

<div class="post-metadata">

**Author:** ![thabenksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@thabenksta](https://www.ruby-forum.com/u/thabenksta)\
**Post date:** [December 13, 2007, 10:37am UTC](https://www.ruby-forum.com/t/swap-problems-with-mongrel/122668/7 "2007-12-13T10:37:26Z")

</div>

How menu power does your site needs is more experimental then  
theoretical question.  
Nevertheless, be prepared to add more if need arises.

You have probably read this one but it is a good starting point.  
[http://mongrel.rubyforge.org/docs/how\_many\_mongrels.html](http://mongrel.rubyforge.org/docs/how_many_mongrels.html)

You should use YSlow to determine some points of optimization.  
[http://com3.devnet.re3.yahoo.com/performance/](http://com3.devnet.re3.yahoo.com/performance/)  
[http://com3.devnet.re3.yahoo.com/yslow/](http://com3.devnet.re3.yahoo.com/yslow/)

If you find some principle that we can use please share it.

On Dec 12, 3:56 pm, Ben K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![thabenksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@thabenksta](https://www.ruby-forum.com/u/thabenksta)\
**Post date:** [December 12, 2007, 9:08am UTC](https://www.ruby-forum.com/t/swap-problems-with-mongrel/122668/8 "2007-12-12T09:08:45Z")

</div>

We have also had a problem with very data base intensive site.  
The problems ware noticeable only on picks activity times.

You should try to cache as much as you can.

Nevertheless, analize the apache log files, rails log files, CPU and  
memory consumption and try to figure out what is going on.  
You can add some logging in some subsystems of your application to get  
a better inside view.

It’s “Sherlock Homes” activity but once you solve this issue you will  
be very proud of you self - and that’s what is all about.

On Dec 11, 8:40 pm, Ben K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![thabenksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@thabenksta](https://www.ruby-forum.com/u/thabenksta)\
**Post date:** [December 13, 2007, 6:14pm UTC](https://www.ruby-forum.com/t/swap-problems-with-mongrel/122668/9 "2007-12-13T18:14:12Z")

</div>

Thanks, dima. I wasn’t aware of either of the links/tools you  
mentioned, so this is great stuff!

I’ll definitely share any principles that worked for us.

Anil

dima wrote:

> How menu power does your site needs is more experimental then  
> theoretical question.  
> Nevertheless, be prepared to add more if need arises.
> 
> You have probably read this one but it is a good starting point.  
> [http://mongrel.rubyforge.org/docs/how\_many\_mongrels.html](http://mongrel.rubyforge.org/docs/how_many_mongrels.html)
> 
> You should use YSlow to determine some points of optimization.  
> [http://com3.devnet.re3.yahoo.com/performance/](http://com3.devnet.re3.yahoo.com/performance/)  
> [http://com3.devnet.re3.yahoo.com/yslow/](http://com3.devnet.re3.yahoo.com/yslow/)
> 
> If you find some principle that we can use please share it.
> 
> On Dec 12, 3:56 pm, Ben K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
