Understanding Apache MPMs: Prefork, Worker, and Event Explained
This article explains the three stable Apache MPM modes—prefork, worker, and event—their compilation options, configuration directives, performance characteristics, and practical testing results, helping administrators choose the right processing model for high‑concurrency web servers.
For Apache 2.4.10 (released July 21, 2014) there are three stable Multi‑Processing Modules (MPMs): prefork, worker, and event, representing the evolution of Apache's processing models.
# httpd -V
Server version: Apache/2.4.10 (Unix)
Server built: Dec 29 2014 11:23:13
Server's Module Magic Number: 20120211:36
Server loaded: APR 1.5.1, APR-UTIL 1.5.3
Compiled using: APR 1.5.1, APR-UTIL 1.5.3
Architecture: 64-bit
Server MPM: event
threaded: yes (fixed thread count)
forked: yes (variable process count)When compiling Apache you can select an MPM with the configure flag: --with-mpm=prefork|worker|event Or build all three as shared modules: --enable-mpms-shared=all In httpd.conf you load the desired MPM module (the .so files are generated in the modules directory):
#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
LoadModule mpm_worker_module modules/mod_mpm_worker.so
#LoadModule mpm_event_module modules/mod_mpm_event.so1. prefork MPM
Prefork is the oldest and most stable mode. Apache forks a number of child processes at startup; each process handles one request with a single thread. Advantages: mature, stable, compatible with all modules, no thread‑safety concerns (e.g., mod_php). Disadvantages: higher memory usage per process and poorer performance under high concurrency because requests wait in a queue for an available process.
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 250
MaxConnectionsPerChild 0
</IfModule>2. worker MPM
Worker combines multiple processes with multiple threads per process. Each child process creates several threads, each handling a request, reducing memory consumption compared with prefork and improving performance under high load. The mixed model improves stability: if a thread crashes, only its process is affected, not the whole server.
Advantages: lower memory footprint, better high‑concurrency performance. Disadvantages: must handle thread‑safety; long‑lived keep‑alive connections can tie up threads, potentially exhausting the thread pool.
<IfModule mpm_worker_module>
StartServers 3
MinSpareThreads 75
MaxSpareThreads 250
ThreadsPerChild 25
MaxRequestWorkers 400
MaxConnectionsPerChild 0
</IfModule>3. event MPM
Event is the newest stable mode, similar to worker but adds a dedicated thread to manage keep‑alive connections, preventing idle threads from consuming resources. This improves request handling in high‑concurrency scenarios. Event falls back to worker when incompatible modules are loaded. It requires Linux 2.6+ with epoll support. Modern Apache also supports SSL with event, although older documentation claimed otherwise.
<IfModule mpm_event_module>
StartServers 3
MinSpareThreads 75
MaxSpareThreads 250
ThreadsPerChild 25
MaxRequestWorkers 400
MaxConnectionsPerChild 0
</IfModule>Performance testing
Using ab with 200 concurrent connections and 200,000 requests, the three MPMs showed similar throughput for static HTML:
prefork: 9556 QPS
worker : 11038 QPS
event : 10224 QPSFor a simple PHP script ( echo "hello world";) the results were:
prefork: 6094 QPS
worker : 7411 QPS
event : 7089 QPSFor PHP, FastCGI or php‑fpm is recommended. Modern browsers open multiple keep‑alive connections per domain, making high concurrency a common scenario. While Apache remains mature, Nginx often outperforms it in many use cases due to its lighter architecture.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
