Apache MPM

Also known as: Multi-Processing Module · MPM

On this page 7

An Apache MPM, or Multi-Processing Module, is the component of the Apache HTTP Server that binds to network ports, accepts connections and dispatches them to processes or threads for handling. Among web servers, the MPM is what determines how Apache scales under concurrency, how much memory it consumes and which application integrations it supports.

Exactly one MPM is active at a time. On Unix-like systems the choice is among prefork, worker and event; on Windows Apache uses mpm_winnt. Since Apache 2.4 most distributions build the MPMs as loadable modules, so the choice is made in configuration rather than at compile time.

How an Apache MPM handles connections

An MPM sits between the operating system and the rest of Apache. A parent process, usually started as root, opens the listening sockets and then creates child processes that run under an unprivileged account. Depending on the MPM, each child serves one connection at a time or runs many worker threads, each serving its own connection.

The parent continually adjusts the pool. It spawns children when the number of idle workers falls below a threshold and retires children when too many sit idle, within the limits set by directives such as MaxRequestWorkers. Children can also be recycled after a set number of connections, which limits the impact of memory leaks in modules.

All other modules, such as mod_rewrite or mod_ssl, run inside the workers that the MPM provides. That is why the MPM choice affects thread safety requirements for every loaded module and for embedded language interpreters.

Prefork, worker and event compared

The three Unix MPMs differ in how they map connections to execution units. The table below summarizes the essential differences.

MPMExecution modelKeep-alive handlingMemory per connection
preforkOne single-threaded process per connectionProcess waits idleHigh
workerMultiple processes, many threads eachThread waits idleModerate
eventLike worker plus a listener threadIdle connections parked on listenerLow
mpm_winntOne process with many threads (Windows)Thread per connectionModerate
The Unix MPMs at a glance

Prefork isolates every request in its own process, so a crash affects only one connection and modules need not be thread-safe. The cost is memory: each process carries its own copy of the interpreter and data, which limits concurrency to a few hundred connections on typical hardware.

Worker runs threads inside fewer processes and shares memory between them, allowing far more concurrent connections. Event, the default on most modern builds, extends worker with a dedicated listener thread that holds idle keep-alive connections and hands them to a worker only when a new request arrives. This prevents slow or idle clients from occupying worker threads.

Key directives that tune an MPM

MPM tuning comes down to a small set of directives that define pool size and lifecycle. Their meaning varies slightly by MPM, as the table below shows.

DirectiveApplies toWhat it controls
MaxRequestWorkersAll Unix MPMsMaximum simultaneous connections served
ServerLimitAll Unix MPMsUpper bound on child processes
ThreadsPerChildworker, eventThreads created by each child
MinSpareThreads and MaxSpareThreadsworker, eventIdle thread pool range
MaxConnectionsPerChildAll Unix MPMsConnections before a child is recycled
AsyncRequestWorkerFactoreventExtra connections allowed per idle worker
Core MPM directives

The most important calculation is memory budgeting. Operators measure the resident memory of one child process, divide the memory available to Apache by that figure and set MaxRequestWorkers accordingly. Setting it too high leads to swapping under load, which degrades response times far more than queuing requests would.

Choosing an MPM for PHP and other applications

The traditional reason to run prefork is mod_php, which embeds the PHP interpreter inside Apache and is not reliably thread-safe with many extensions. Modern deployments avoid that constraint by running PHP in PHP-FPM and connecting through mod_proxy_fcgi, which lets Apache use the event MPM while PHP runs in its own process pool.

The following decision table matches common situations with a recommended MPM.

SituationRecommended MPMReason
Legacy site with mod_phppreforkInterpreter is not thread-safe
PHP through PHP-FPMeventApplication runs outside Apache
Reverse proxy to app serverseventMany idle keep-alive connections
Static files at high concurrencyeventLow memory per connection
Windows hostmpm_winntOnly MPM available on Windows
Non-thread-safe third-party modulepreforkProcess isolation required
Selecting an MPM by workload

When Apache acts as a reverse proxy in front of Gunicorn, Tomcat or another application server, the event MPM is usually the right default, because most of its connections are waiting on network input rather than performing work.

Limitations and common misconceptions

The event MPM is not fully asynchronous in the way Nginx is. A request that is actively being processed still occupies a thread until the response is complete, so long-running requests or slow back ends still consume workers. Event mainly improves the handling of idle and lingering connections.

  • Switching MPMs does not speed up slow application code; it changes concurrency and memory behavior, not execution time.
  • The server-status page from mod_status shows worker states and is the first tool for diagnosing exhausted pools.
  • TLS connections benefit from event, but older builds handed SSL keep-alive connections back to workers less efficiently.
  • Only one MPM may be loaded; loading two LoadModule lines for different MPMs prevents Apache from starting.

Put simply

Think of Apache as a restaurant and the MPM as the way the manager organizes the staff. Prefork gives every guest a private waiter, which is safe but expensive. Worker lets each waiter share a station with colleagues, so the same staff can serve more tables.

Event adds a host at the door who looks after guests who are only sitting and chatting, and calls a waiter only when someone is ready to order. Choosing the MPM means choosing how Apache spends its memory to serve many visitors at once.

In practice

A small agency hosts about 30 WordPress sites on a virtual server with 4 GB of memory. Apache runs prefork with mod_php, each child uses roughly 60 MB, and MaxRequestWorkers is limited to about 50. During a newsletter campaign, keep-alive connections fill every slot, visitors wait several seconds and the server begins to swap.

The administrator installs PHP-FPM, switches Apache to the event MPM and routes PHP files through mod_proxy_fcgi. Apache children now use only a few megabytes each, so MaxRequestWorkers is raised to 400 while PHP-FPM keeps a separate pool of 20 workers sized to the available memory.

During the next campaign, idle connections no longer block workers, swapping disappears and pages that previously stalled now load in well under a second. The change cost no new hardware, only a different MPM and process layout.