Swap problems with mongrel

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

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.

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. [email protected]

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. [email protected]

Thanks, Daniel.

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. [email protected]

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.

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

You should use YSlow to determine some points of optimization.
http://com3.devnet.re3.yahoo.com/performance/
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. [email protected]

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. [email protected]

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

You should use YSlow to determine some points of optimization.
http://com3.devnet.re3.yahoo.com/performance/
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. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs