Re: HTTP server scalability

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thank you Andrew and Tom,
 
Thank you for your insightful replies.  These have definitely helped me in understanding the major issues.
 
At this moment I can not understand "How a 'Connecton' is passed from parent process to child process."
 
My understanding is
 
"a connection is a combination of (IP address + port.) and the parent process listens at one such address or multiple such addresses in virtual host interfaces."
 
Let us assume the parent process is listening to only one such address i.e. (IP address + port).  Then if this connection is passed to the child then this connection must be blocked and this is the only connection which will be multiplexed among several child processes as welll parent process.  My point is that concurrency can not be achieved on a single connection (IP address + port) unless I am missing something fundemental about the definition of "Connection."
 
Secondly if a connection is passed to the child then once again the child process will have to make a three way handshake to the original client to service the request.
 
I hope Andrew or someone from the group can clear my doubts.
 
Thanks.
 
Nagrik 

On Wed, Jun 10, 2009 at 2:41 PM, André Warnier <aw@xxxxxxxxxx> wrote:
Complementary to what you will find in the on-line Apache documentation at http://httpd.apache.org, 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 :
http://httpd.apache.org/docs/2.2/mod/directives.html
(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:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
 "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx




--
Thanks

Nagrik

[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux