Apache Settings

Apache Settings

by Rocco Lewis -
Number of replies: 9
Hello,
I am runnig into Moodle slowdown when I have more than 15 simultaneous users.  Any I deas?

Our Setup:
Red Hat Linux 9
Moodle 1.6 (updated yesterday)
On a Dell Optiplex GX60 (with standard network card, 512 RAM, Celeron 2)

Some Data:
Process ID Owner Size Command
30706 apache 33300 kB [httpd]
30733 apache 33168 kB [httpd]
30677 apache 33008 kB [httpd]
30623 apache 32932 kB [httpd]
30771 apache 32848 kB [httpd]
28072 apache 32140 kB [httpd]
29884 apache 32024 kB [httpd]
30011 apache 31944 kB [httpd]
30749 apache 31936 kB [httpd]
30691 apache 31932 kB [httpd]
30585 apache 31912 kB [httpd]
30808 apache 31700 kB [httpd]
30801 apache 28496 kB [httpd]
30685 apache 26904 kB [httpd]
30764 apache 26884 kB [httpd]
30307 apache 26624 kB [httpd]
30692 apache 26592 kB [httpd]
30774 apache 26448 kB [httpd]
30760 apache 26420 kB [httpd]
30621 apache 26384 kB [httpd]
30622 apache 26380 kB [httpd]
30614 apache 26372 kB [httpd]
30763 apache 26368 kB [httpd]
30705 apache 26356 kB [httpd]
30595 apache 26336 kB [httpd]
30597 apache 26336 kB [httpd]
30324 apache 26332 kB [httpd]
30757 apache 26160 kB [httpd]
30780 apache 26132 kB [httpd]
30617 apache 26060 kB [httpd]
30762 apache 26056 kB [httpd]
30737 apache 26044 kB [httpd]
30620 apache 26036 kB [httpd]
30690 apache 26012 kB [httpd]
30734 apache 26004 kB [httpd]
30738 apache 26000 kB [httpd]
30673 apache 25976 kB [httpd]
30783 apache 25820 kB [httpd]
30703 apache 25664 kB [httpd]
3288 mysql 25228 kB [mysqld]
30308 apache 24984 kB [httpd]
30681 apache 24916 kB [httpd]
30788 apache 24908 kB [httpd]
30739 apache 24624 kB [httpd]
30770 apache 24412 kB [httpd]
30735 apache 24384 kB [httpd]
30745 apache 24352 kB [httpd]
30758 apache 24168 kB [httpd]
30755 apache 24164 kB [httpd]
30689 apache 24140 kB [httpd]
30795 apache 24140 kB [httpd]
3290 root 18308 kB /usr/sbin/httpd
30859 root 13328 kB /usr/local/webmin/proc/index_size.cgi
3339 root 9228 kB /usr/bin/perl /usr/local/webmin/miniserv.pl /etc/webmin/miniserv.conf
29748 theone 6876 kB [sshd]
29745 root 6752 kB /usr/sbin/sshd
29669 root 4376 kB -bash
29784 root 4376 kB bash
29749 theone 4296 kB -bash

Average of ratings: -
In reply to Rocco Lewis

Re: Apache Settings

by Rory Allford -

Hi,
You might want to go in for a bit of memory performance tuning; I'm no expert but here are my thoughts:

  • Apache is suffering process bloat (common with php and other dynamic content), and the memory each thread consumes will not automatically be freed: consider lowering MaxRequestsPerChild in httpd.conf to as low as 20-30 (if you set it any lower the overhead of forking begins to outweigh the benefits). Also check the memory_limit in php.ini, reduce it to at least 16M.
  • Once you've done this, check the process table again to see how much memory is consumed by each apache instance on average (should be much lower). As a rule of thumb, if you divide your total available ram (i.e. free memory when apache is not running) by this amount it will give you a value for MaxClients, and you can guesstimate StartServers, MinSpareServers, and MaxSpareServers similarly.
  • The other big memory hogger is mysql, and you should try tweaking the memory usage there as well (see http://dev.mysql.com/doc/refman/5.0/en/server-parameters.html).

There are more general factors to do with how your system is setup: What else is the server doing that could consume memory? Depending on your memory/processor balance should you recompile apache with preforking? Does your distro (e.g. Fedora) preload bloat? Tuning LAMP is a science in itself, and if you have the patience you can sometimes gain far greater performance improvements than just throwing more hardware at the problem. Having said that, in your case a bit more RAM wouldn't go amiss wink

As an example, our setup is a reasonably beefy dual xeon with raid1, dual NICs and 2G of RAM, running Gentoo:

In httpd.conf:
MaxKeepAliveRequests 150
KeepAliveTimeout 5 #occasional 56k user
<ifmodule>
StartServers 8
MinSpareServers 8
MaxSpareServers 15
MaxClients 250
MaxRequestsPerChild 30
</ifmodule>

In my.cnf:

key_buffer = 32M
max_allowed_packet = 1M
table_cache = 192 #Moodle uses a lot of tables
sort_buffer_size = 2M
net_buffer_length = 8K
read_buffer_size = 512K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M

Server stats page is here.

You could check the moodle documentation page, but you'll find more information on the more general topic of LAMP performance tuning by googling.

In reply to Rory Allford

Re: Apache Settings

by Dan Stowell -
Rory - I've added one or two of your tips to the docs page - I hope that is OK.
In reply to Dan Stowell

Re: Apache Settings

by Rory Allford -

No problem; nice work and keep it up! big grin

What I posted worked for me; each setup is different etc, so there's no one universal "perfect" config from a performance point of view - Perhaps Moodle will eventually get to the stage where it comes ready with a pretweaked LAMP setup (or even distro)...

In reply to Rory Allford

Re: Apache Settings

by Dave Briccetti -
Hi Rory. Thanks for the tips. When you say,

"reduce it to at least 16M"

do you mean reduce it as much as to 16M, perhaps more, to an even lower value? What's a good minimum value, I wonder. I'm seriously memory constrained.

Dave Briccetti
In reply to Dave Briccetti

Re: Apache Settings

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Reducing it to less than 16M might get you in trouble if your Moodle setup is using several filters (auto-glosary, mimetex, etc.). I would say 16 is the minimum these days.

Saludos. Iñaki.
In reply to Iñaki Arenaza

Re: Apache Settings

by Rory Allford -
Also you may want to temporarily raise it when running a lot of processing scripts, e.g. end of term stuff, or backup/restore.
Restoring an SQL database backup with a remote client also requires that net_buffer_length in my.cnf is raised to at least the size of the largest single query (additionally things like PMA would also need the Apache and PHP upload and memory limits set appropriately).
In reply to Rocco Lewis

Re: Apache Settings

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
512M ram????

I'm not surprised, this is way not enough memory to run this number of processes. Your apache process alone are consuming three times that. Your machine is going to be paging to disc like mad, which is of course very slow.

You are going to need to seriously upgrade your server.
In reply to Howard Miller

Re: Apache Settings

by Maik Riecken -

... or use lighttpd instead of apache if you don't want to upgrade hardware. lighttpd normally needs 50% less RAM than apache. PHP runs in fastCGI-Mode then - even more secure with basic settings.

Maik

In reply to Maik Riecken

Re: Apache Settings

by Randy Obert -
And would you post a link to a moodle site that is running this web server?