Apache2 Memory Usage

Apache2 Memory Usage

by Emma Richardson -
Number of replies: 10
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Help needed!!  My site has been crashing with 25 users logged in.

I have been messing with settings and tweaking apache like crazy but I always come back to the fact that each Apache2 process is using between 50-100MB ram.  This seams very high (everywhere I read says that each process should be using up to 20MB ram).  I have tweaked to the point and now added more RAM which has stopped crashing for now but can't help wondering why apache2 is using so much ram in the first place.

Specs:

Moodle 2.0 (latest build)

Debian Squeeze 2.6.32-5 running on Hyper-V so have same issue when it is on VMWare and using a different kernel. Currently on 64 bit but started on 32 bit.  (Migrated Moodle from one server to new current build.)

PHP 5.3.8-2

Currently running Apache 2.21 but same issue with Apache 2.18 - using Prefork. Have tweaked settings to current state of StartServers=5,MinSpareServers=2,MaxSpareServers=5,MaxClients=30, MaxRequests=100 and installed APC for optimization.

All my tweaks have helped but nothing has dropped the RAM usage per process.  Only constant is the Moodle site - just not sure where to look or am I wrong and is this a normal amount of RAM per process??

Any help would be greatly appreciated!

Emma

Average of ratings: -
In reply to Emma Richardson

Re: Apache2 Memory Usage

by Tom Kiesel -

Hi Emma,

I'm seeing about 65-90 MB resident memory use for each of my apache 2 processes, looking at RES in the top program.

I've got a 64 bit system as well, running version 2.2.16 of Apache with PHP loaded as an apache module, caching by APC.  Overall a similar system to yours.

I was running a 32 bit system last year, and like you saw the memory use lower back then with largely the same configuration.  My guess is that we're seeing a bit of the overhead of running 64 bit.

Average of ratings: Useful (1)
In reply to Tom Kiesel

Re: Apache2 Memory Usage

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Thanks, that helps a lot.  Now at least I know that it is not out of line which what it should be doing!

In reply to Emma Richardson

Re: Apache2 Memory Usage

by Tom Kiesel -

Glad I could help!  And I can confirm that more RAM definitely makes Moodle snappier (as if there was any doubt), especially with entire classes of students starting quizzes more-or-less simultaneously.

In reply to Emma Richardson

Re: Apache2 Memory Usage

by Andrew Lyons -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Hi Emma,

I know that this is a little late, but have you checked the memory consumption of your APC configuration? To do so, you'll need to download the apc.php file (not shipped with the Debian php-apc package) from http://svn.php.net/viewvc/pecl/apc/branches/APC_3_0/apc.php?revision=259553&view=co. Visit this in your browser and take a look at the Cache Full count" and the hit/miss ratio.

If you've got a positive "Cache Full count", then you need to give APC more memory. To do this, you'll also need to increase your kernal shmmax. In Debian, you can do this by looking at /etc/sysctl.conf. The APC memory setting is stored in /etc/php5/apache2/conf.d/apc.ini (see apc.shm_size). After changing this, you'll also need to restart apache (/etc/init.d/apache2 restart).

Setting this appropriately should bring your memory per-thread in apache down as pages use the APC opcode cache instead of compiling each php file as it's served.

Andrew
Average of ratings: Useful (1)
In reply to Andrew Lyons

Re: Apache2 Memory Usage

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Thanks Andrew.  I will look into this.  I have also been playing with lighttpd - any thoughts on that?

Emma

In reply to Emma Richardson

Re: Apache2 Memory Usage

by Andrew Lyons -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
I've heard lots of people using it, but it won't necessarily decrease your memory consumption significantly on it's own. I'll admit that I've not gotten around to trying it myself. I've also been meaning to have a play with nginx recently but again, time seems to get the better of me.

My suspicion though is that you'll find that in the first instance, installing and correctly configuring a php opcode cacher will significantly decrease per-thread memory consumption, and also make things a good deal faster. Just moving to lighttpd will just move the memory usage to a different process.

Andrew
In reply to Andrew Lyons

Re: Apache2 Memory Usage

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Lighttpd and nginx have come up a couple of times, haven't tested them myself:
- Some Tips on Getting nginx+php-fpm working, 21 October 2011
http://moodle.org/mod/forum/discuss.php?d=188653

- Nginx (fronteend) + Apache2 (backend) + Moodle, 27 August 2010
http://moodle.org/mod/forum/discuss.php?d=156803

- Nginx for our performance tweakers, 21 August 2008
http://moodle.org/mod/forum/discuss.php?d=103918

- Nginx + Moodle configuration tips, 5 September 2010
http://moodle.org/mod/forum/discuss.php?d=157382

- Nginx, 6 February 2011
http://moodle.org/mod/forum/discuss.php?d=168162

- lighttd vs. apache, 3 November 2007
http://moodle.org/mod/forum/discuss.php?d=83722

Coming back to the OP,

> I have been messing with settings and tweaking apache like crazy but I always come back to the fact that each Apache2 process is using between 50-100MB ram. This seams very high (everywhere I read says that each process should be using up to 20MB ram).

Do you mean the phrase "The general rule of thumb is that Moodle can support 50 concurrent users for every 1GB of RAM, ..." in the following pages?
http://docs.moodle.org/19/en/Installing_Moodle#Hardware
http://docs.moodle.org/20/en/Installing_Moodle#Hardware
http://docs.moodle.org/21/en/Installing_Moodle#Hardware

That was the rule of thumb at the time of 1.9. The wiki page is just copied into the other versions. Visit the "Documentation forum" http://moodle.org/mod/forum/view.php?id=5838 for details.

> I have tweaked to the point and now added more RAM which has stopped crashing for now but can't help wondering why apache2 is using so much ram in the first place.
>
> Specs:
> Moodle 2.0 (latest build)
> Debian Squeeze 2.6.32-5 running on Hyper-V so have same issue when it is on VMWare and using a different kernel. Currently on 64 bit but started on 32 bit. (Migrated Moodle from one server to new current build.)
> PHP 5.3.8-2
> Currently running Apache 2.21 but same issue with Apache 2.18 - using Prefork.

How much RAM have you allocated to the VM?

Genarally VMware has limitations when it comes to busy Moodle sites, and a 64 bit system needs more RAM than its 32 bit counterpart. Why do you use virtualization at all?
In reply to Visvanath Ratnaweera

Re: Apache2 Memory Usage

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Regarding '50 concurrent users' in that document - even if it were current, this is unlikely to refer to Apache processes so the 'divide 1GB by 50' definitely does not apply here anyhow.

Say there are 50 people actively using the system, probably they will only actually be making web requests for a small proportion of the time. I think that's what concurrent users means. (It is a rubbish way of judging performance as it totally depends on your site - e.g. if people mainly use forums or quiz, that's quite heavy vs. if they mainly just download a pdf file and then read it and then download the next pdf file - but that's by the by.)

For info, I just checked on our live systems. Not sure if this is a suitable way to check it, but the httpd processes on our Moodle 2.1-based systems seem to have a ResSet of about 100MB whereas on our (heavily customised) Moodle 1.9-based system it's about 150MB. Weird. I wouldn't have expected that. Probably nothing significant, or something to do with our customisations. Anyway, we're not getting 20MB, is the point. smile And incidentally, our 1.9 webservers have 8GB RAM and normally handle approx 400 'concurrent users' (defined as, number of different users accessing the system within a 5 minute period; divided by the number of servers). Coincidentally, it looks like we actually do allow about 20MB per concurrent user, although each Apache process is much bigger than that and I don't know if we are memory-limited anyhow, for all I know it would work fine with half the RAM... (Note: I am not responsible for running our servers, I just looked at the stats.)

--sam

Average of ratings: Useful (1)
In reply to Visvanath Ratnaweera

Re: Apache2 Memory Usage

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

I am currently running on HyperV with 4Gb ram dedicated to Moodle site.  We virtualize pretty much everything and I have always run my Moodle site through either HyperV or VMWare.  This is the first year that I have run into trouble but I am probably getting more use than previously as well.  Currently, I still have considerable slowdowns and a couple of students having their quiz kick them off when a class of 28 in on taking a quiz but the site is not crashing like before.  I just think that with my specs, the site should be able to handle 28 students taking a quiz without any problem but maybe I am just expecting too much!  This issue actually started when I had this on a 32 bit server so I see it definitely as an Apache issue.  

I am going to play with the APC settings (as suggested by previous answer) and lighttpd which I have running now on a test server and it definitely is using less RAM than Apache - just need to test it under load and make sure that there are no problems there.  I am definitely open to more suggestions and appreciate you taking the time to respond!

In reply to Emma Richardson

Re: Apache2 Memory Usage

by Andrew Lyons -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
We're also running some installations our customer's own virtualised environments.

In one I'm working on at present, we're running moodle 2.1 with about 700 daily active users (sorry - no idea what the 'concurrency' is off-hand) on:
* 64 bit dual core VMWare vsphere machine
* 8GB RAM
* Debian Squeeze amd64 installation
* apache2
* apc

The box has a load average of < 0.3 at all times, and our apache2 threads seems to have a RES of between 15m and 77m at present. We have 400+ MB of RAM completely unused, and 7.3Gb in the cache. Only 680Gb is actively used.

Our databases are stored on a separate db server which is (unfortunately) virtualised.

Virtualisation shouldn't cause any major issues - though virtualising a database server isn't great.
Also, using a 64-bit installation won't use a significant amount more memory - it will likely have a slightly higher memory overhead but I believe that this is passed to the host, not the instance. Without a 64-bit system, and 64-bit kernel you won't be able to access beyond the first 3.6GB RAM (okay... you could be running big-mem, but the overheads are just as high, if not higher).

Andrew
Average of ratings: Useful (2)