httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier>
Subject Re: [users@httpd] HTTP server scalability
Date Wed, 10 Jun 2009 21:41:53 GMT
Complementary to what you will find in the on-line Apache documentation 
at, and painted with a very wide brush :

When you start Apache, a single main Apache process is started.
It reads and checks the configuration, and loads a series of core and 
add-on modules, as per your configuration.

When it is done with that phase, it starts either a number of child 
processes (in the "prefork" type of setup), or a number of "children 
threads" (in the "worker" type of setup).

Each of those is identical to the main Apache process that was built 
according to the configuration, but from now on the "main" process and 
the "children" will do different things.

The "main" process opens the listening TCP port (or ports), as described 
in the "Listen" configuration directive(s), and starts waiting for 
connections to that (or these) port(s).
When a connection comes in, it looks in the pool of available children 
processes/threads to find one that is inactive.  If it finds one, it 
passes the opened TCP connection to that child/thread, and goes back to 
listen for more new connections on the server listening port (typically, 
port 80).

The selected child/thread now "has" this TCP connection, and it reads 
and handles the HTTP request that came in on that connection.  While it 
is doing that, it is "busy", and the main process will not give it 
another connection to handle.

In the meantime, if another client connection happens to the main 
listening port, the main process will do the same again, this time 
finding another "idle" (available, not doing anything at the moment) 
child process/thread to pass this new connection to.

When the child/thread is done with processing a request, it lets the 
main Apache process know that it is idle (free) again, ready to handle 
another connection if one is pending.

The main Apache process does not handle requests.  Its job is to listen 
for connections on the listening server port, accept these connections, 
and pass them on to children processes/threads for processing.
In addition, it manages the pool of children processes/threads.  As the 
load varies, the main Apache process may decide to start more children 
processes/threads, or to kill off some that really have nothing to do.
This is controlled to some extent by a number of Apache configuration 
directives, such as the ones you find here :
(look for the directives starting in general with Max.. or Min.., and 
browse around)

When the main Apache process receives the command to shut down, it 
normally lets each busy child finish their current request, then kills 
them off, then exits itself.

The following is not specific to Apache, but relevant.

The listening TCP socket has a "wait queue". That means, if a client new 
connection occurs before Apache has had time to accept the previous one 
and hand it over to a child, the new connection will not be rejected 
right away, it will wait a while.  As soon as the main Apache process is 
done with passing the previous onnection to a child, it will pick up the 
first of these waiting connections, accept it, etc...
Then the next waiting one if any.
The maximum length of this queue varies; it is a TCP-level parameter.
If the rate of incoming connections is so high that Apache cannot cope, 
the queue will get longer, up to this limit.  If a new connection comes 
in when the limit of waiting ones is already reached, it will be 
rejected ("the server refused the connection").

This is how a webserver like Apache handles multiple requests 
"simultaneously".  It does not really accept new connections 
simultaneously, but accepting a connection and passing it on to a child 
is very fast.  The child then can take much more time to actually 
process this client request, while the main Apache is already accepting 
the next one, and so on.

At any one point in time, there could thus be 100 Apache children 
processes/threads in the process each of processing one client request 
and/or sending a response, each one over a "private" TCP connection 
between itself and the client browser.
There could also be 20 new connections in the queue for port 80, which 
the main Apache process has not had time to accept yet.

These numbers vary constantly up and down, as the number of requests 
(and the time to process each one of them) varies.

The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
   "   from the digest:
For additional commands, e-mail:

View raw message