FastCGI + PHP
I run this webserver on a VPS hosted by quantact so the lower the memory usage, the
lower my monthly bill. This has led me to be pretty stingy with memory usage.
While using mod_php, each apache process was around 25MB each. Since switching
to PHP running as a fastcgi my apache processes are down to around 2MB with a
couple of php process at around 25MB.
Configuration
I followed these instructions to set everything up. The only real gotcha’s I ran into were
ensuring the file permissions were correct as php is now running as a different
user that www-data.
Benchmarks
I use ab to beat on the server a bit in both configurations, below are the results for mod_php:
Server Software: Apache/2.2.9
Server Hostname: www.digitaldogma.org
Server Port: 80
Document Path: /2010/10/09/monitoring-with-cacti
Document Length: 20745 bytes
Concurrency Level: 25
Time taken for tests: 45.775 seconds
Complete requests: 1000
Failed requests: 229
(Connect: 0, Receive: 0, Length: 229, Exceptions: 0)
Write errors: 0
Non-2xx responses: 96
Total transferred: 17081694 bytes
HTML transferred: 16537051 bytes
Requests per second: 21.85 [#/sec] (mean)
Time per request: 1144.374 [ms] (mean)
Time per request: 45.775 [ms] (mean, across all concurrent requests)
Transfer rate: 364.42 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 74 82 4.6 81 107
Processing: 80 1048 746.3 936 8988
Waiting: 80 863 586.0 757 6633
Total: 163 1131 746.0 1019 9069
Percentage of the requests served within a certain time (ms)
50% 1019
66% 1185
75% 1299
80% 1384
90% 1734
95% 2181
98% 3174
99% 3940
100% 9069 (longest request)
and for FastCGI:
Server Software: Apache/2.2.9
Server Hostname: www.digitaldogma.org
Server Port: 80
Document Path: /2010/10/09/monitoring-with-cacti
Document Length: 20745 bytes
Concurrency Level: 25
Time taken for tests: 52.335 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 21287344 bytes
HTML transferred: 20748806 bytes
Requests per second: 19.11 [#/sec] (mean)
Time per request: 1308.374 [ms] (mean)
Time per request: 52.335 [ms] (mean, across all concurrent requests)
Transfer rate: 397.22 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 74 82 4.9 81 123
Processing: 316 1201 234.2 1136 2588
Waiting: 155 1025 232.3 960 2408
Total: 398 1283 234.4 1219 2667
Percentage of the requests served within a certain time (ms)
50% 1219
66% 1317
75% 1401
80% 1469
90% 1577
95% 1710
98% 1928
99% 2103
100% 2667 (longest request)
When I first looked at the results, it appears that the mod_php config was faster based on the Time per request, but then I noticed the Failed requests numbers. Of the 1000 requests, 229 had failed on the mod_php server, looking in the error logs I find quite a few of these:
[error] (12)Cannot allocate memory: fork: Unable to fork new process
Looks like the mod_php exhausted the system memory and wasn’t able to process all the requests. This would account for the faster response times, as it doesn’t take much to reply with an error :).
The above has cemented my decision to go with FastCGI on my hosted VPN. If you are able to throw more memory at it I get the feeling mod_php would be faster (note the max connect times, as the first hit need to spawn the fastcgi process), but for my small site and limited resources (money and ram :) FastCGI is the way to go.
I’ve never really stopped messing around with this. Originally I was using mod_fastcgi, but since have switched to the newer mod_fcgid which seems much more predictable in how many processes are spawned.
So I started using WP Super Cache (http://wordpress.org/extend/plugins/wp-super-cache/) and it blows both of these out of the water.
This makes sense as it’s essentially serving static html pages.