AboutBlogContact
System EngineeringJune 18, 2002 2 min read 23

Apache 2.0: Prefork vs. Worker MPM (2002)

AunimedaAunimeda
📋 Table of Contents

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.

Read Also

Kafka: Zero-Copy and Why It's Fast (2015)aunimeda
System Engineering

Kafka: Zero-Copy and Why It's Fast (2015)

How does Kafka push gigabits of data on commodity hardware? The secret isn't in the code; it's in the Linux kernel's sendfile() call.

Memcached: Slab Allocation Internals (2007)aunimeda
System Engineering

Memcached: Slab Allocation Internals (2007)

Why is your cache server swapping? It's probably memory fragmentation. Let's look at how Memcached solves this with slabs.

Linux 2.6: The O(1) Scheduler Revolution (2003)aunimeda
System Engineering

Linux 2.6: The O(1) Scheduler Revolution (2003)

Linux 2.6.0 is out, and the new O(1) scheduler changes everything for high-load servers. No more linear scaling issues with process counts.

Need IT development for your business?

We build websites, mobile apps and AI solutions. Free consultation.

Get Consultation All articles