Why do you have multiple copies of "httpd" running on your web server, even though you have only got one process in startup? It's because httpd spawns child processes which allow it to be handling several customers at the same time rather than have them stand in line and be processed sequentially. It's sensible / necessary because some of the clients may be a little bit slow (waiting on resources such as disc or network transfer) and rather than wait, the cpu should get on with other jobs.
There are various different models available within httpd ... I'm looking at the default prefork module here, and it's very tune-able. To understand how, I'll compare it with a supermarket checkout.
A supermarket has a certain amount of space available with checkouts installed, but when they open they only open a few at first. As they get busier, more are opened to keep ahead of the rush up to the maximum they have capacity for, and as business drops off, they will close some down - but they'll never drop below a minimum waiting to serve. After a certain number of customers, they may choose to service and then reopen a checkout.
Let's see how the mpm_prefork module does that. Firstly, in the httpd.conf file, you'll enable the extra configuration file to allow you to move it away from all the defaults:
# Server-pool management (MPM specific)
Include conf/extra/httpd-mpm.conf
The change was as simple as removing a
#. Then make changes to the file in the
extra subdirectory to reflect the new configuration you want. Let me translate the default into Supermarket terms:
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
</IfModule>
"Our store has 150 checkouts. Five of them are manned when the store is initially opened for business, and we always keep at least five in hand waiting to serve customers who walk up (until all are open). At times that our checkout staff are handling customers quicker than they're arriving, we'll close checkouts but we'll keep at least ten open anyway in case more people walk up. We do not set a limit for the number of customers an individual operator / checkout looks after in a single opening."
There is further tuning of the checkout behaviour which can be changed too, via other defaults. Once again, if you want to change these parameters you need to enable the settings via an extra file - here's the modified line (again, uncommenting is all I changed) in the httpd.conf:
# Various default settings
Include conf/extra/httpd-default.conf
And here are the default settings that I'm interested in:
Timeout 300
MaxKeepAliveRequests 100
KeepAliveTimeout 5
"If someone walks up to a checkout but then doesn't actually give the clerk anything to checkout or just stops, give that person 300 seconds to actually get on with something before you chuck 'em and move on to the next customer. When you finish selling something to someone, pause for up to 5 seconds to see if they have another item to purchase as well. But only a hundred of the checkouts may be tied up in this wait state at any time".
There are several different approaches to tuning these settings ... and also to tuning any back room services (such as MySQL) which the staff on the checkouts will be using:
• you could increase the number of checkouts available in order to reduce the amount of shutting down and starting up necessary, and to ensure that you have plenty of staff available at peak times or ...
• you could trim back and have a limited number of checkouts available that move quickly from one customer to the next, scarsely pausing for the slowcoaches.
The defaults are pretty middle - of - the - road, and the fact that you are reading this article is likely to mean you have issues -
so have a look at the underlying cause before you do too much and be prepared to do a few tests!. Monitoring tools include
top, vmstat and uptime from Linux, the
Apache Server Status page from httpd that you can enable,
mysqladmin status from MySQL ... and you can use tools such as
ab and
jmeter to generate traffic flows too to test your system.
To conclude - three sample (amended) configuration files ...
Keeping a lot more checkouts open (but be careful that you don't end up paying so much overtime (i.e. using swap space) that you loose more that you gain:
<IfModule mpm_prefork_module>
StartServers 10
MinSpareServers 10
MaxSpareServers 25
MaxClients 250
MaxRequestsPerChild 10000
</IfModule>
For a system which has limited memory ("you don't really want the expense and time consuming trouble of serving people in a portacabin, so make the very best use of your limited floor space!"):
<IfModule mpm_prefork_module>
StartServers 4
MinSpareServers 4
MaxSpareServers 8
MaxClients 35
MaxRequestsPerChild 10000
</IfModule>
And here are some tunings for the default file:
Timeout 60
MaxKeepAliveRequests 20
KeepAliveTimeout 3
Here's the rationale behind that one: "It's a fast moving site, and (let's face it!) people will get bored after waiting for a minute - so may as well time out them. Keep the number of checkouts waiting for a further purchase down; avoid the danger of the whole store being clogged up with checkouts waiting for Mrs Jones to run back for some sugar, or for Johnny Smith to dash over and get an extra Mars bar because he hadn't noticed the 2 for 1 offer. And keep the time that Mrs J and Johnny are allowed for such antisocial actions down."
[Sample file]; The image illustrating this article is public domain.
detail.
(written 2009-02-26, updated 2010-10-28)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
A601 - Web Application Deployment - Apache httpd - an overview [576] Why run two different web servers - (2006-01-25)
[659] Web Application Components - (2006-03-28)
[924] The LAMP Cookbook - Linux, Apache, MySQL, PHP / Perl - (2006-11-13)
[1265] Apache, Tomcat, Jakarta, httpd, web server - what are they? - (2007-07-13)
[1593] Keep the client experience easy - single server contact point - (2008-03-27)
[1897] Keeping on an even keel - (2008-11-21)
[2016] Apache httpd and Apache Tomcat miscellany - (2009-01-30)
[2038] Sticky Sessions with mod_jk (httpd to Tomcat) - (2009-02-12)
[2063] Internal Dummy Connections on Apache httpd - (2009-03-02)
[2077] Why put Apache httpd in front of Apache Tomcat - (2009-03-12)
[2186] An FAQ on the Apache httpd and Apache Tomcat web servers, and on using them together - (2009-05-17)
[4064] Apache httpd - a robust, open source web server - (2013-04-16)
[4434] Public training courses - upcoming dates - (2015-02-21)
Some other Articles
Invoker and cgi servlets on Tomcat 6Train and Coach fares from London (and airports) to MelkshamWeb Site Loading - experiences and some solutions sharedEffect on server when memory runs out and swapping startsTuning httpd / the supermarket checkout comparisonWhat a difference a MySQL Index madeHow was my web site compromised?A Presentation about our company - web and PHPWhy the Pony Tail?Why Choose Well House Consultants for your course?