ubuntu - MaxRequestsPerChild

ubuntu - MaxRequestsPerChild

by Andrew Atkinson -
Number of replies: 9
Hello

I am trying to improve the performance of our moodle server

Ubuntu dapper 606lts with 2 dual processors and 2Gb ram. We have about 1400 users and get up to about 120 simultaneous connections.

following the documentation I am trying to change the MaxRequestsPerChild in httpd.conf.

So first, I have found out it is not in httpd.conf it is in apache2.conf but then the relevant section gives me this.

##
## Server-Pool Size Regulation (MPM specific)
##

# prefork MPM
# StartServers ......... number of server processes to start
# MinSpareServers ...... minimum number of server processes which are kept spare
# MaxSpareServers ...... maximum number of server processes which are kept spare
# MaxClients ........... maximum number of server processes allowed to start
# MaxRequestsPerChild .. maximum number of requests a server process serves
<IfModule prefork.c>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 20
MaxRequestsPerChild 0
</IfModule>

# pthread MPM
# StartServers ......... initial number of server processes to start
# MaxClients ........... maximum number of server processes allowed to start
# MinSpareThreads ...... minimum number of worker threads which are kept spare
# MaxSpareThreads ...... maximum number of worker threads which are kept spare
# ThreadsPerChild ...... constant number of worker threads in each server process
# MaxRequestsPerChild .. maximum number of requests a server process serves
<IfModule worker.c>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>

# perchild MPM
# NumServers ........... constant number of server processes
# StartThreads ......... initial number of worker threads in each server process
# MinSpareThreads ...... minimum number of worker threads which are kept spare
# MaxSpareThreads ...... maximum number of worker threads which are kept spare
# MaxThreadsPerChild ... maximum number of worker threads in each server process
# MaxRequestsPerChild .. maximum number of connections per server process (then it dies)
<IfModule perchild.c>
NumServers 5
StartThreads 5
MinSpareThreads 5
MaxSpareThreads 10
MaxThreadsPerChild 20
MaxRequestsPerChild 0
AcceptMutex fcntl
</IfModule>

What do I need to change?

thanks

Andrew
Average of ratings: -
In reply to Andrew Atkinson

Re: ubuntu - MaxRequestsPerChild

by Myles Carrick -
hi Andrew,

Mate is the DB on the same box? If so, I'd definitely suggest getting yourself some more memory. You're right, though - you can extract a lot better performance from the box by tuning Apache.

There's a reply to a post here by Rory Allford that is perhaps useful. Easy first steps I'd suggest making to your apache2.conf (yep - Ubuntu sticks things in different places):
  • Calculate MaxClients to
    total available memory for apache / memory footprint of each child process
    (use top to check out what's happening with your Apache processes)
  • Reduce MaxRequestsPerChild to 20-30 (0 means unlimited)
  • Reduce KeepAlivesTimeout to 2 (it's in a section higher up than the snippet you provided here)
In terms of where to make the change? Sections in the conf file are there for each of the different apache multi-processing modules, one of which is installed on your system. Synaptic should easily tell you which you have running... likely to be prefork i think if you're running phpaccelerator (if you're not - you should).

Go well,

Myles

In reply to Myles Carrick

Re: ubuntu - MaxRequestsPerChild

by Andrew Atkinson -
Myles

Still working up the confidence to do the above, but the more I read the differenct strands, it is slowly comming together. The simple guidence of linking the 3 choices with the apache version, has been a real help. Thanks

As for Memory usage, the only way I can check it is to fire up the GUI and use System Monitor. It shows all 4 processors, quite often hitting 100%, but the memory hardly moves away from 500Mb, is this a correct reading? if so why is the rest not been used?

I assume this is to do with the MaxClients?

thanks

Andrew
In reply to Andrew Atkinson

Re: ubuntu - MaxRequestsPerChild

by Myles Carrick -
hey Andrew,

Martin L might be able to chime in with some suggestions on this one...

The total memory usage for Apache should be roughly the MaxClients * the footprint of the typical Apache process.

Is it Apache processes that are maxing out your CPUs?

MC
In reply to Myles Carrick

Re: ubuntu - MaxRequestsPerChild

by Martín Langhoff -
Hola smile

in a split webserver / db server scenario, if Apache processes are killing your webserver I would say there is a problem or perhas the stats you are getting are not very accurate. Use the 'top' command line utility to get your readings. And as Myles says, your maxclients is too low.
In reply to Martín Langhoff

Re: ubuntu - MaxRequestsPerChild

by Andrew Atkinson -
Hello

this is what I get with top, when the CPU are running at full, and therefore the system has slowed down to a crawl.

myles carrick wrote
>Apache should be roughly the MaxClients * the footprint of the typical >Apache process

I have changed the maxclients to 250 but as I do not know how to work out the apache footprint I have copied it from another thread of a machine that was similar. (I know I have seen the answer to this somewhere on the forums but cannot find it now, sorry) Top shows that apache memory usage is 0.6-0.7% that would indicate a MaxClients at about 180. But 250 is not using all the memory

These are also now set
  • Reduce MaxRequestsPerChild to 20-30 (0 means unlimited)
  • Reduce KeepAlivesTimeout to 2


top - 09:25:21 up 31 days, 1:54, 2 users, load average: 19.62, 23.51, 17.25
Tasks: 139 total, 16 running, 122 sleeping, 0 stopped, 1 zombie
Cpu(s): 2.7% us, 2.7% sy, 94.4% ni, 0.0% id, 0.0% wa, 0.2% hi, 0.1% si
Mem: 2073976k total, 1667608k used, 406368k free, 211432k buffers
Swap: 4385704k total, 60k used, 4385644k free, 921320k cached


10689 www-data 25 10 29004 14m 3532 R 34 0.7 0:03.45 apache2
10895 www-data 26 10 25604 11m 3316 R 28 0.6 0:01.91 apache2
10911 www-data 26 10 25620 11m 3344 R 28 0.6 0:02.93 apache2
10019 www-data 26 10 27760 14m 4652 R 27 0.7 0:09.46 apache2
10643 www-data 26 10 28732 15m 4052 R 18 0.8 0:02.45 apache2
10675 www-data 26 10 25608 11m 3328 R 17 0.6 0:02.49 apache2
10896 www-data 26 10 25640 11m 3240 S 16 0.6 0:01.00 apache2
10910 www-data 26 10 25600 11m 3300 S 16 0.6 0:01.51 apache2
9968 www-data 25 10 29356 15m 4040 S 15 0.8 0:04.59 apache2
9599 www-data 26 10 26748 12m 3492 R 14 0.6 0:12.83 apache2
9899 www-data 26 10 29928 16m 4600 R 14 0.8 0:10.67 apache2
10876 www-data 26 10 25600 11m 3236 R 13 0.6 0:01.41 apache2
10599 www-data 25 10 26544 12m 3528 S 12 0.6 0:04.16 apache2
10387 www-data 26 10 26588 12m 3512 R 10 0.6 0:06.00 apache2
9636 www-data 26 10 29316 16m 4724 S 9 0.8 0:14.29 apache2
10673 www-data 25 10 25628 11m 3340 S 9 0.6 0:01.74 apache2
10890 www-data 25 10 25640 11m 3368 S 9 0.6 0:00.79 apache2
4610 root 15 0 31556 15m 6268 S 8 0.8 2078:58 Xorg
9673 www-data 25 10 26588 13m 4580 S 8 0.7 0:13.10 apache2
10150 www-data 25 10 25620 11m 3372 S 8 0.6 0:07.98 apache2
10879 www-data 25 10 25508 11m 3280 S 8 0.6 0:00.52 apache2
10662 www-data 25 10 25624 11m 3372 S 8 0.6 0:02.32 apache2
10878 www-data 25 10 25604 11m 3240 S 8 0.6 0:01.75 apache2
10319 www-data 26 10 26236 12m 3452 R 8 0.6 0:08.28 apache2
10687 www-data 25 10 25668 11m 3424 S 8 0.6 0:03.02 apache2
10619 www-data 26 10 25624 11m 3416 R 7 0.6 0:03.51 apache2
10730 www-data 26 10 0 0 0 Z 7 0.0 0:01.29 apache2 <defunct>
10149 www-data 25 10 26836 12m 3528 S 6 0.6 0:07.51 apache2
10885 www-data 26 10 25668 11m 3380 S 6 0.6 0:00.78 apache2
10877 www-data 27 10 25624 11m 3400 R 6 0.6 0:02.69 apache2
9865 www-data 25 10 25640 11m 3328 S 5 0.6 0:10.34 apache2
10641 www-data 26 10 25620 11m 3364 S 5 0.6 0:01.05 apache2

Thanks for the help, I am out of my depth. Buying more memory is an option, but only if it is using all that is there at the moment. What would be a recommended amount?

thanks

Andrew
In reply to Andrew Atkinson

Re: ubuntu - MaxRequestsPerChild

by James Dugal -
Do you have a PHP accelerator/cache enabled? This would eliminate the php parse/compile phase and thus should reduce the demand for CPUs. The MaxCLients setting would be something like 2GB/30MB, or 67. If you set MaxClients too large, you will allow a busy server to run out of memory! You should probably have more memory than 2GB based on your active client count, but that would be your secondary problem.
--James



In reply to James Dugal

Re: ubuntu - MaxRequestsPerChild

by Andrew Atkinson -
James

thanks, I am working on the accelerator, still gathering enough confidence/information to do it.
On the assumtion that I have now set maxClients too high, would that mean it would be using Swap memory, top reports the swap memory as not been used.

I will reduce it to 67 in a couple of days when I am next at the school.

New memory is on the way, but I still want to get the best performance out of what I have

thanks

Andrew
In reply to Andrew Atkinson

Re: ubuntu - MaxRequestsPerChild

by James Dugal -
Just FYI: I use APC cache and compile it from sources, but I needed phpize and apxs (which are in devel rpms in RHEL .. dunno about ubantu). I did find that I could NOT enable the optimize feature without a strange display of group submissions in forums. This was under Linux and Solaris. So I just use APC as a cache. It is a big help in achieving speedy performance. I allocate 56 MB of shared memory.
In reply to James Dugal

Re: ubuntu - MaxRequestsPerChild

by Myles Carrick -
APC on Ubuntu (Dapper and Edgy servers, anyway) is a cinch... couldn't be easier! From my install docs:

1. Install pear (and the various libraries for pecl to install)
apt-get install php-pear php5-dev apache2-threaded-dev

2. Fix a silly name/version change problem with apxs by adding a symbolic link to the right file
ln -s /usr/bin/apxs2 /usr/bin/apxs

3. Install apc
pecl install apc

4. Make sure that php knows to use it... edit /etc/php/apache2/php.ini and add
extension=apc.so

5. Restart Apache and you're away!
/etc/init.d/apache2 restart


Of course, try it out in your dev environment first... but it should yield significant benefits.

Cheers,

MC

NB. In my dev environment this worked perfectly... but a pecl setting shut me down on 64 bit Ubuntu... complained during the installation at step 3... something like "Fatal error: Allowed memory size of 8388608 bytes exhausted..." for some reason it's using its own ini values... (not either the php.ini values for cli or apache).

If so... edit /usr/share/php/pearcmd.php and add:
@ini_set('memory_limit', '16M');