1

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,

RickD
  • 145
  • 1
  • 2
  • 15

2 Answers2

2

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.

symcbean
  • 19,931
  • 1
  • 29
  • 49
1

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.
kubanczyk
  • 13,502
  • 5
  • 40
  • 55
  • 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 ? – RickD Nov 26 '12 at 11:15