Configuring Apache with FastCGI PHP-FPM for a Slim Application

Benchmarking Speed

I didn’t feel much of a speed increase, but the stats say there was one. Here are some runs comparing PHP without FastCGI, and PHP with FastCGI. Then, I compared FastCGI over TCP/IP, and FastCGI over Unix domain sockets.

Here’s the command:

ab -n 1000 -c 30 -k -H "Authorization: bearer secretkeywenthere" http://riceball.lo/legacy-sitemap/api/

30 request processes, making a total of 1000 requests. -k turns on keep-alive, because the servers have Keep Alive on. -H passes a token to access the API.

The page returned a string. It didn’t dig into the application. The computer is an AMD 630 X4 with 12 Gigs of RAM running Ubuntu 16.10.

The results are from the second execution of the command.

Plain PHP (with Zend Opcache)

Concurrency Level:      30
Time taken for tests:   2.072 seconds
Complete requests:      1000
Failed requests:        0
Keep-Alive requests:    1000
Total transferred:      772030 bytes
HTML transferred:       158000 bytes
Requests per second:    482.66 [#/sec] (mean)
Time per request:       62.155 [ms] (mean)
Time per request:       2.072 [ms] (mean, across all concurrent requests)
Transfer rate:          363.90 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.9      0      12
Processing:     5   61  25.0     59     173
Waiting:        1   61  25.0     59     173
Total:          5   61  25.1     59     185

Percentage of the requests served within a certain time (ms)
  50%     59
  66%     70
  75%     76
  80%     81
  90%     94
  95%    104
  98%    123
  99%    131
 100%    185 (longest request)

PHP-FPM with Unix Domain Socket

Concurrency Level:      30
Time taken for tests:   1.631 seconds
Complete requests:      1000
Failed requests:        0
Keep-Alive requests:    1000
Total transferred:      772030 bytes
HTML transferred:       158000 bytes
Requests per second:    613.02 [#/sec] (mean)
Time per request:       48.938 [ms] (mean)
Time per request:       1.631 [ms] (mean, across all concurrent requests)
Transfer rate:          462.18 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.3      0       8
Processing:     5   48  20.8     47     142
Waiting:        1   48  20.8     47     142
Total:          5   49  20.7     47     142

Percentage of the requests served within a certain time (ms)
  50%     47
  66%     55
  75%     62
  80%     65
  90%     75
  95%     85
  98%     95
  99%    108
 100%    142 (longest request)

PHP-FPM with TCP Sockets

Concurrency Level:      30
Time taken for tests:   2.109 seconds
Complete requests:      1000
Failed requests:        0
Keep-Alive requests:    1000
Total transferred:      772030 bytes
HTML transferred:       158000 bytes
Requests per second:    474.05 [#/sec] (mean)
Time per request:       63.285 [ms] (mean)
Time per request:       2.109 [ms] (mean, across all concurrent requests)
Transfer rate:          357.40 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   2.5      0      17
Processing:     5   62  24.2     60     149
Waiting:        5   62  24.2     60     149
Total:          5   63  24.0     61     149

Percentage of the requests served within a certain time (ms)
  50%     61
  66%     71
  75%     78
  80%     83
  90%     95
  95%    108
  98%    116
  99%    122
 100%    149 (longest request)

The winner: PHP-FPM with Unix domain sockets

Plain old mod_php and PHP-FPM running over sockets performed similarly: around 480 requests per second.

PHP-FPM running over Unix sockets came in at 613 requests per second. That’s around 28% faster.

I don’t have tools set up to measure the memory usage.

Leave a Reply