The Preforking Model

Apache (on Unix) is a preforking model server. The parent process is responsible only for forking child processes; it does not serve any requests or service any network sockets. The child processes actually process connections; they serve multiple connections (one at a time) before dying. The parent spawns new or kills off old children in response to changes in the load on the server (it does so by monitoring a scoreboard that the children keep up to date).

This model for servers offers a robustness that other models do not. In particular, the parent code is very simple, and with a high degree of confidence the parent will continue to do its job without error. The children are complex, and when you add in third-party code via modules, you risk segmentation faults and other forms of corruption. Even should such a thing happen, it only affects one connection and the server continues serving requests. The parent quickly replaces the dead child.

Preforking is also very portable across dialects of Unix. Historically, this has been an important goal for Apache, and it continues to remain so.

The preforking model comes under criticism for various performance aspects. Of particular concern are the overhead of forking a process, the overhead of context switches between processes, and the memory overhead of having multiple processes. Furthermore, it does not offer as many opportunities for data-caching between requests (such as a pool of mmapped files). Various other ...

Get Web Performance Tuning now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.