The Worker MPM in Apache 2.2 implements a hybrid multi-process/multi-threaded model. The key directives in httpd.conf are:
<IfModule mpm_worker_module> StartServers 2 MaxClients 150 MinSpareThreads 25 MaxSpareThreads 75 ThreadsPerChild 25 MaxRequestsPerChild 0 </IfModule>
More processes advantages:
- Better isolation - crashing threads won't bring down entire server
- Better for CPU-bound workloads (avoids GIL contention in some cases)
- Easier to scale vertically on multi-core systems
More threads advantages:
- Lower memory overhead (shared address space)
- Faster context switching between requests
- Better for I/O-bound workloads handling many concurrent connections
For a database-heavy application (I/O bound):
<IfModule mpm_worker_module> ServerLimit 16 ThreadLimit 64 StartServers 4 MaxClients 800 # 16 processes * 50 threads ThreadsPerChild 50 MinSpareThreads 50 MaxSpareThreads 200 </IfModule>
For CPU-intensive processing:
<IfModule mpm_worker_module> ServerLimit 32 ThreadLimit 25 StartServers 8 MaxClients 800 # 32 processes * 25 threads ThreadsPerChild 25 MinSpareThreads 50 MaxSpareThreads 150 </IfModule>
Always test with your specific workload using tools like ab (Apache Bench):
ab -n 1000 -c 100 http://yourserver/test.php
Monitor memory usage per process:
ps -ylC httpd --sort:rss
High CPU usage: Reduce ThreadsPerChild and increase ServerLimit
Memory exhaustion: Reduce total threads (MaxClients = ServerLimit × ThreadsPerChild)
Connection timeouts: Verify MaxRequestsPerChild isn't causing frequent restarts
The Worker MPM in Apache 2.2 uses a hybrid approach combining processes and threads. The key configuration directives are:
<IfModule mpm_worker_module> ServerLimit 16 StartServers 4 MaxClients 400 MinSpareThreads 25 MaxSpareThreads 75 ThreadsPerChild 25 MaxRequestsPerChild 0 </IfModule>
More processes advantages:
- Better isolation - crashes affect fewer connections
- Easier to debug with traditional tools
- Better for environments with thread-unsafe libraries
More threads advantages:
- Lower memory overhead (shared address space)
- Faster context switching
- Better for CPU-bound workloads
Memory-constrained environment:
# Optimize for memory efficiency ThreadsPerChild 50 MaxClients 500 ServerLimit 10
High-traffic dynamic content:
# Balance isolation and performance ThreadsPerChild 25 MaxClients 400 ServerLimit 16
Test configuration comparing different setups:
ab -n 10000 -c 100 http://localhost/test.php # Configuration A (more processes) ServerLimit 20 ThreadsPerChild 10 MaxClients 200 # Configuration B (more threads) ServerLimit 10 ThreadsPerChild 25 MaxClients 250
Memory leaks: Use lower ThreadsPerChild when dealing with leaky modules
Stability problems: Increase processes if experiencing random crashes
Connection limits: Calculate MaxClients based on available RAM
MaxClients = (Total RAM - OS overhead) / (Memory per process)
For newer Apache versions, consider:
- Event MPM for better async handling
- PHP-FPM for separating web server from application processing