The number of options for tweaking apache is pretty overwhelming. Tuning apache depends on a number of factors - depending on how much resources you have to throw at it and how you decide to run your system, and what you want out of it. There's quite a few places out there that offer some advice (apache, Scrollbag general tuning, IBM network tuning, IBM svn).
I'm mostly interested in fast low memory setup of apache 2 on Linux. One of the first things to decide is what MPM mode you decide to use for your apache installation - there's bunch. In fact Apache2 supports three MPM's prefork, worker, and event. To check which one you're running use either:
apachectl -l which will list the compiled modules - where 'prefork.c', 'worker.c', or 'event.c' indicate the version in use. You can also check by running apache2 -V. To use a different one you usually have to load the appropriate package on your system - but it will depend on which modules you have installed - e.g. using PHP will result in MPM prefork as PHP is not entirely thread safe.
I am currently running in prefork (a bit old school but simpler). In this mode the number of httpd daemons started - which is mainly controlled by ServerLimit directive (and subsequently MaxClients) - whilst there are quite a few others control how many instances are started initially and kept spare etc. You need to make sure that your machine has enough memory to for the number of servers so the machine doesn't start to swap unnecessarily; Once you have sorted out the modules (see below) and config for the server you can see how much memory a single httpd instantiation uses (check using top command). Once you know how much one httpd uses then configure things so that ServerLimit * httpd_memory is less than the total amount of memory available on the system when apache is not running. You can check to see if you got it right by running the system up (with some requests and all servers started - you can set StartServers directive equal to Serverlimit for testing) and checking there is minimum swap activity - using the vmstat command - run it vmstat 5 and check that the so/si (swap out/in) columns are close to zero - if not then tweak down the number on ServerLimit.
Apache provides a vast array of modular functionality - through its loadable modules support. Firstly you want to go through you the modules that you need loaded for your setup, then comment out all the ones you don't need. Things like unneeded language modules (php, python etc) should be off, and stuff like mod_status (particularly ExtendedStatus) should be switched off once you have got your config sorted.
[8dec08] New page on apache optimisations.
[12sept12]: Added info on checking MPM in use.
No comments:
Post a Comment