Apache prefork vs. worker
Tags:
I compiled 2 different versions of apache 2.2.4 on Solaris 10 (06/06, on a crappy U10, but...) one using the prefork MPM (compile --with-mpm=prefork) and the other using the worker MPM (compile --with-mpm=worker). Prefork is supposed to generally be better for single or dual cpu systems, and worker is supposed to be generally better for multi-CPU systems. The following are the Apache Bench results run against each build on an old Sun Ultra 10 with a single 440mhz CPU and 512m RAM. The server isn't impressive, but it works for bench-testing the MPMs...
I used the default settings for each MPM:
-------------------------------------------------------------
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
</IfModule>
<IfModule mpm_worker_module>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
-------------------------------------------------------------
and the siege tests were run with the following settings:
------------------------------------------------------------- concurrent = 10 time = 5M benchmark = true -------------------------------------------------------------
Apache Bench results for prefork:
-------------------------------------------------------------
% ./ab -n 10000 -c 10 http://192.168.1.80/index.html
...
Server Software: Apache/2.2.4
Server Hostname: 192.168.1.80
Server Port: 80
Document Path: /index.html
Document Length: 44 bytes
Concurrency Level: 10
Time taken for tests: 478.185521 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 3160000 bytes
HTML transferred: 440000 bytes
Requests per second: 20.91 [#/sec] (mean)
Time per request: 478.185 [ms] (mean)
Time per request: 47.819 [ms] (mean, across all concurrent requests)
Transfer rate: 6.45 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 95.4 0 3380
Processing: 1 472 1178.0 2 10139
Waiting: 0 41 389.2 0 10138
Total: 1 475 1182.0 2 10139
Percentage of the requests served within a certain time (ms)
50% 2
66% 2
75% 3
80% 4
90% 3372
95% 3377
98% 3379
99% 3381
100% 10139 (longest request)
-------------------------------------------------------------
Siege results for prefork:
------------------------------------------------------------- Lifting the server siege... done. Transactions: 6045 hits Availability: 100.00 % Elapsed time: 300.38 secs Data transferred: 0.25 MB Response time: 0.50 secs Transaction rate: 20.12 trans/sec Throughput: 0.00 MB/sec Concurrency: 9.97 Successful transactions: 6045 Failed transactions: 0 Longest transaction: 10.13 Shortest transaction: 0.00 -------------------------------------------------------------
Apache Bench results for worker:
-------------------------------------------------------------
% ./ab -n 10000 -c 10 http://192.168.1.80/index.html
...
Server Software: Apache/2.2.4
Server Hostname: 192.168.1.80
Server Port: 80
Document Path: /index.html
Document Length: 44 bytes
Concurrency Level: 10
Time taken for tests: 244.283673 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 3160000 bytes
HTML transferred: 440000 bytes
Requests per second: 40.94 [#/sec] (mean)
Time per request: 244.284 [ms] (mean)
Time per request: 24.428 [ms] (mean, across all concurrent requests)
Transfer rate: 12.63 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 75.4 0 3378
Processing: 1 239 870.1 1 11898
Waiting: 0 16 229.6 0 3388
Total: 1 241 872.9 1 11898
Percentage of the requests served within a certain time (ms)
50% 1
66% 2
75% 2
80% 2
90% 4
95% 3373
98% 3379
99% 3380
100% 11898 (longest request)
-------------------------------------------------------------
Siege results for worker:
------------------------------------------------------------- Lifting the server siege... done. Transactions: 11024 hits Availability: 100.00 % Elapsed time: 300.24 secs Data transferred: 0.46 MB Response time: 0.27 secs Transaction rate: 36.72 trans/sec Throughput: 0.00 MB/sec Concurrency: 9.91 Successful transactions: 11024 Failed transactions: 0 Longest transaction: 11.92 Shortest transaction: 0.00 -------------------------------------------------------------
So for this setup, the worker MPM was almost twice as fast as the prefork.
I'm going to run these same tests on a multi-cpu server and see what the results look like.
- theCamel's blog
- Add new comment
- 10318 reads

My server(2ghz opteron) ran prefork apache and it was sometimes being
overloaded with 500 concurrent processes. The cpu usage was low which was
puzzling. I tried changing over to worker MPM and its been running great.
Unfortunately, PHP5 does not work with the Worker MPM. On my Ubuntu server, PHP5 can only be installed with the Prefork MPM. Meaning that my server, which has 4 dual-core Opterons, is not being used optimally if I've understood correctly :-(
PHP5 can work with MPM Worker too. But you have to use CGI or FastCGI instead of Apache module. I've written some instructions on how to do it: Install Apache2 MPM Worker and PHP5 using mod_fcgid.