Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Can any confirm how Apache spawns new children ?

As in if I connect to a webserver (HTTP 1.0 / no keep alive) and issue a HTTP /GET I will be spawned a new HTTPD child. If then issue another HTTP /GET then a new TCP connection will be built. However will I use the same child process of would I spawn a new one ?

Also if I was using HTTP 1.1 (with keep-alive) and reused the same TCP connection, would the httpd process/spawning be any different to that if I wasnt using keepalive ?

Thanks,

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

if I connect to a webserver (HTTP 1.0 / no keep alive) and issue a HTTP /GET I will be spawned a new HTTPD child

No, for the TCP handshake to complete, you've already got a process to handle your request. Since you mention 'processes' this implies you're talking about pre-fork MPM. In which case, the server should already have a pool of available child processes - one of these acquires a mutex to pick up the next incoming connection.

The thread based server works in a similar manner.

The event based server is a completely different kettle of fish and doesn't spawn threads/processes.

If then issue another HTTP /GET...will I use the same child process

No. And even if you know that you have a keepalive connection, there is no state retained by the server - hence you have to treat it as if it were a new process.

share|improve this answer
    
No - how do you get that from my answer? –  symcbean Nov 29 '12 at 9:18
add comment

There is no universal setting, as this is the most crucial aspect of http server's performance. Generally, Apache tries hard to avoid forking (or spawning, as you've called it). Check this out:

http://www.stepwise.hk/blog/check-if-apache-running-prefork-or-worker/

Multi-Processing Modules (MPMs) are Apache modules that manage the network connections and dispatching the requests. There are two common MPMs available for Apache2, namely, mpm_prefork_module and mpm_worker_module. The mpm_prefork_module uses the traditional model of one process per request, while the mpm_worker_module uses the threaded model which uses multiple processes, each with multiple threads to get better performance with lower overhead.

Manuals for Apache 2.4 says:

When building Apache, you must choose an MPM to use. There are platform-specific MPMs for some platforms: mpm_netware, mpmt_os2, and mpm_winnt [for any MS Windows version]. For general Unix-type systems, there are several MPMs from which to choose. The choice of MPM can affect the speed and scalability of the httpd:

  • The worker MPM uses multiple child processes with many threads each. Each thread handles one connection at a time. Worker generally is a good choice for high-traffic servers because it has a smaller memory footprint than the prefork MPM.
  • The event MPM is threaded like the Worker MPM, but is designed to allow more requests to be served simultaneously by passing off some processing work to supporting threads, freeing up the main threads to work on new requests.
  • The prefork MPM uses multiple child processes with one thread each. Each process handles one connection at a time.
share|improve this answer
    
Yep I am using prefork. So if I have this right a new TCP connection is assigned to a new process. However I would of thought it would be better for it to use an exsisting process ? –  felix001 Nov 26 '12 at 11:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.