Choosing the wrong Apache MPM and then tuning around the symptoms is one of the most common ways an Apache box ends up with 8 GB of RAM consumed by 250 idle workers. The MPM is the lowest-level decision in an Apache deployment — it determines whether the server scales by forking processes, by threads, or by a hybrid event loop. This article is the decision and the numbers we use for each model.
How to verify
Confirm which MPM is loaded and how it is configured. The MPM is a module, so it shows in apachectl -M; its config lives in /etc/apache2/mods-enabled/mpm_*.conf:
apachectl -M | grep mpm
cat /etc/apache2/mods-enabled/mpm_event.conf 2>/dev/null \
|| cat /etc/apache2/mods-enabled/mpm_prefork.conf 2>/dev/null
ps -eo pid,user,rss,vsz,cmd | grep apache2 | grep -v grep | head
sudo apache2ctl -t -D DUMP_RUN_CFG | grep -i mpm
ps shows the worker process count and resident memory per worker. Multiply RSS per worker by MaxRequestWorkers to get the worst-case memory ceiling.
Decision
Three MPMs ship with Apache 2.4:
- prefork — one process per connection, no threads. Each connection has its own address space, so any module is safe (including non-thread-safe ones like the bundled PHP SAPI). The classic Apache model. Heavy: each idle worker holds a full process’s worth of memory.
- worker — multiple processes, multiple threads per process. Each connection is handled by one thread. Lighter memory footprint than prefork. Requires every loaded module to be thread-safe.
- event — like worker, but a small pool of listener threads parks idle KeepAlive connections out of the request-serving thread pool. Lets a small number of threads handle thousands of slow/idle connections. The modern default.
The decision is mostly driven by what runs in-process:
mod_php(PHP module) — must use prefork. The bundled PHP SAPI is not thread-safe. This is the single biggest reason a 2026 Apache box might still be on prefork.- PHP-FPM (over
mod_proxy_fcgi) — use event. PHP runs in its own pool of FPM workers, Apache just proxies. No thread-safety constraint on Apache. - Reverse proxy front (Node/Python/Java/Go upstreams) — use event.
- Static content + occasional CGI — use event.
- CGI scripts that fork() heavily or call non-thread-safe libraries — use prefork if the CGI cannot be containerized.
For most modern deployments, the answer is event. The remaining prefork users are PHP applications still using mod_php — moving them to PHP-FPM and switching to event is the upgrade path, and is covered in Apache + PHP-FPM proxy.
How they differ in numbers
Approximate per-connection memory and CPU footprint on a typical Ubuntu Apache install:
- prefork — ~10-20 MB resident per process, one process per concurrent connection. At 100 concurrent users, expect 1-2 GB just for Apache workers.
- worker — ~10-20 MB per process, ~25 threads per process by default. Same 100 users fit in ~4 processes, ~80 MB total.
- event — same memory shape as worker, but idle KeepAlive connections cost roughly nothing because they are not bound to a thread. Same 100 users, but the box can hold 1000 KeepAlive idle connections without burning threads.
The relevant tuning directives, with defaults that we override most often:
# /etc/apache2/mods-enabled/mpm_event.conf
<IfModule mpm_event_module>
StartServers 4
MinSpareThreads 50
MaxSpareThreads 150
ThreadsPerChild 25
MaxRequestWorkers 400
MaxConnectionsPerChild 10000
ServerLimit 16
</IfModule>
MaxRequestWorkersis the hard ceiling on concurrent requests. The default of 150 is too low for any real site.ThreadsPerChild×ServerLimitmust be ≥MaxRequestWorkers. IfServerLimitis the default 16 andThreadsPerChildis 25,MaxRequestWorkerscannot exceed 400.MaxConnectionsPerChildrecycles a worker after this many connections — defends against slow memory leaks in modules. 10000 is a sensible value; 0 (default on event) means never recycle.
For prefork the directives are simpler:
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 150
MaxConnectionsPerChild 10000
</IfModule>
MaxRequestWorkers here is the number of processes — and the number of concurrent connections. For prefork, the math is straightforward: MaxRequestWorkers × (RSS per process) ≤ available RAM, with headroom for the OS and the PHP-FPM pool if present.
How to switch MPMs
Switching is a sequenced module swap, not a config edit:
sudo a2dismod mpm_prefork
sudo a2enmod mpm_event
sudo apache2ctl configtest
sudo systemctl restart apache2
If you have mod_php, that fails — mod_php requires prefork. Disable mod_php first, install PHP-FPM and mod_proxy_fcgi, wire the fcgi proxy to the PHP-FPM socket, then swap the MPM.
Common pitfalls
- Bumping
MaxRequestWorkerson prefork without checking memory headroom is how you OOM the box under a moderate spike — workers spawn faster than they release. - Event MPM under heavy KeepAlive does not need a high
MaxRequestWorkersfor idle connections, but it does need it for active request handling — sizing only by concurrent users underestimates. - A worker recycle (
MaxConnectionsPerChild) under heavy load briefly drops capacity while the new process spins up; staggered spawn helps but does not eliminate the dip. mod_statusexposes per-worker state — enable it on localhost only and look at it during load tests to see what the worker pool is actually doing.- A switch from prefork to event changes the request log line ordering (because of concurrent processing); downstream log parsers that assumed strict ordering break.
Stack Harbor sizes Apache MPMs from real traffic profiles — not from defaults, not from guesses. The work includes moving legacy mod_php sites to PHP-FPM, switching to event, and rightsizing the worker pool against the memory available. If your Apache fleet still runs prefork on boxes that no longer need it, that migration fits the Managed Operations workflow.