Apache 2.0: Prefork vs. Worker MPM
Apache 2.0 has finally moved to a modular architecture for handling requests, known as Multi-Processing Modules (MPMs). For those of us on Linux and Solaris, the choice comes down to prefork or worker. Choosing wrong can lead to either a crashed server or a very slow one.
The Case for Prefork (The Safe Bet)
prefork is essentially the Apache 1.3 model. Each connection gets its own process.
- Pros: Completely thread-safe. If one request crashes a PHP module, only that process dies.
- Cons: Memory intensive. If you have 500 concurrent users, you have 500 copies of Apache and PHP in RAM.
If you are using legacy PHP modules or anything that isn't explicitly thread-safe (like some older GD or IMAP libs), stay with prefork.
The Case for Worker (The Performance Play)
worker uses a hybrid model: a few processes, each with many threads.
- Pros: Massive memory savings. Threads share memory, allowing you to handle thousands of connections on a modest server.
- Cons: One bad thread can take down the entire process (and all its threads). Everything must be thread-safe.
Benchmarking on Solaris
On Solaris, threads are "first-class citizens," and the worker MPM shines. On Linux 2.4, the "LinuxThreads" implementation is okay, but prefork still often wins in stability. However, with Linux 2.6 on the horizon and the New POSIX Threads Library (NPTL), worker is expected to become the king.
# httpd.conf - Worker Tuning
<IfModule worker.c>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
If you're building a static asset server or using a thread-safe language like Java (via mod_jk), worker is a no-brainer. If you're a PHP shop, keep an eye on your extensions before making the jump.