HTTP server benchmark

這邊預計要測試以下組合:

硬體配備:

備註:

Apache prefork with mod_php

使用 Apache prefork-mpm,設定如下:

<IfModule mpm_prefork_module>
    StartServers           100
    MinSpareServers        100
    MaxSpareServers        150
    MaxRequestWorkers      250
    MaxConnectionsPerChild   0
</IfModule>

目標頁面為 info.php

<?php

phpinfo();

Benchmark 設定

使用 ab (Apache Benchmark) 進行測試。

測試包含以下項目:

每個連線會連續發出 100 個 request 並持續到所有連線收到 response。

一次一個連線,並連續送出 1000 個 request:

ab -r -c 1 -n 1000 http://192.168.1.2/info.php

一次 10 個連線,每個連線均送出 1000 個 request:

ab -r -c 10 -n 10000 http://192.168.1.2/info.php

備註

concurrent = 1

Concurrency Level:      1
Time taken for tests:   3.444 seconds
Complete requests:      1000
Failed requests:        108
   (Connect: 0, Receive: 0, Length: 108, Exceptions: 0)
Write errors:           0
Total transferred:      63430882 bytes
HTML transferred:       63274882 bytes
Requests per second:    290.39 [#/sec] (mean)
Time per request:       3.444 [ms] (mean)
Time per request:       3.444 [ms] (mean, across all concurrent requests)
Transfer rate:          17987.75 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       1
Processing:     2    3   3.2      2      21
Waiting:        1    2   3.1      1      20
Total:          2    3   3.2      2      21

concurrent = 10

Concurrency Level:      10
Time taken for tests:   19.914 seconds
Complete requests:      10000
Failed requests:        977
   (Connect: 0, Receive: 0, Length: 977, Exceptions: 0)
Write errors:           0
Total transferred:      634308910 bytes
HTML transferred:       632748910 bytes
Requests per second:    502.15 [#/sec] (mean)
Time per request:       19.914 [ms] (mean)
Time per request:       1.991 [ms] (mean, across all concurrent requests)
Transfer rate:          31105.60 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.5      1      10
Processing:     2   19  69.6     13    1593
Waiting:        1   18  68.2     12    1592
Total:          2   20  69.6     14    1594

concurrent = 20

Concurrency Level:      20
Time taken for tests:   39.577 seconds
Complete requests:      20000
Failed requests:        18209
   (Connect: 0, Receive: 0, Length: 18209, Exceptions: 0)
Write errors:           0
Total transferred:      1268617791 bytes
HTML transferred:       1265497791 bytes
Requests per second:    505.34 [#/sec] (mean)
Time per request:       39.577 [ms] (mean)
Time per request:       1.979 [ms] (mean, across all concurrent requests)
Transfer rate:          31302.93 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.7      1      12
Processing:     2   38  91.8     30    2442
Waiting:        1   37  90.4     29    2442
Total:          2   40  91.8     31    2443

concurrent = 30

Concurrency Level:      30
Time taken for tests:   60.462 seconds
Complete requests:      30000
Failed requests:        2946
   (Connect: 0, Receive: 0, Length: 2946, Exceptions: 0)
Write errors:           0
Total transferred:      1902926705 bytes
HTML transferred:       1898246705 bytes
Requests per second:    496.18 [#/sec] (mean)
Time per request:       60.462 [ms] (mean)
Time per request:       2.015 [ms] (mean, across all concurrent requests)
Transfer rate:          30735.29 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.5      1      14
Processing:     2   59 117.0     48    7418
Waiting:        1   58 115.7     47    7417
Total:          2   60 117.1     49    7419

Concurrent = 50

Concurrency Level:      50
Time taken for tests:   105.159 seconds
Complete requests:      50000
Failed requests:        4883
   (Connect: 0, Receive: 0, Length: 4883, Exceptions: 0)
Write errors:           0
Total transferred:      3171544555 bytes
HTML transferred:       3163744555 bytes
Requests per second:    475.47 [#/sec] (mean)
Time per request:       105.159 [ms] (mean)
Time per request:       2.103 [ms] (mean, across all concurrent requests)
Transfer rate:          29452.56 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.6      1      47
Processing:     2  104 200.9     84    8817
Waiting:        2   99 160.2     83    8816
Total:          2  105 200.9     85    8818

Concurrent = 60

Concurrency Level:      60
Time taken for tests:   115.079 seconds
Complete requests:      60000
Failed requests:        5907
   (Connect: 0, Receive: 0, Length: 5907, Exceptions: 0)
Write errors:           0
Total transferred:      3805853381 bytes
HTML transferred:       3796493381 bytes
Requests per second:    521.38 [#/sec] (mean)
Time per request:       115.079 [ms] (mean)
Time per request:       1.918 [ms] (mean, across all concurrent requests)
Transfer rate:          32296.41 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.5      1      12
Processing:     4  114 138.1    100    5868
Waiting:        2  111 125.2     99    5867
Total:          4  115 138.1    101    5869

Concurrent = 90

Concurrency Level:      90
Time taken for tests:   173.422 seconds
Complete requests:      90000
Failed requests:        8845
   (Connect: 0, Receive: 0, Length: 8845, Exceptions: 0)
Write errors:           0
Total transferred:      5708780130 bytes
HTML transferred:       5694740130 bytes
Requests per second:    518.97 [#/sec] (mean)
Time per request:       173.422 [ms] (mean)
Time per request:       1.927 [ms] (mean, across all concurrent requests)
Transfer rate:          32146.89 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.5      1      12
Processing:     3  172 164.2    157   18894
Waiting:        2  168 138.5    156   18893
Total:          3  173 164.3    158   18895

Concurrent = 100

Concurrency Level:      100
Time taken for tests:   192.229 seconds
Complete requests:      100000
Failed requests:        10033
   (Connect: 0, Receive: 0, Length: 10033, Exceptions: 0)
Write errors:           0
Total transferred:      6343088820 bytes
HTML transferred:       6327488820 bytes
Requests per second:    520.21 [#/sec] (mean)
Time per request:       192.229 [ms] (mean)
Time per request:       1.922 [ms] (mean, across all concurrent requests)
Transfer rate:          32224.23 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   3.2      1    1002
Processing:     6  191 271.3    172   73425
Waiting:        5  188 260.8    171   73424
Total:          7  192 271.4    173   73425

Concurrent = 130

Concurrency Level:      130
Time taken for tests:   242.434 seconds
Complete requests:      130000
Failed requests:        12875
   (Connect: 0, Receive: 0, Length: 12875, Exceptions: 0)
Write errors:           0
Total transferred:      8246015609 bytes
HTML transferred:       8225735609 bytes
Requests per second:    536.23 [#/sec] (mean)
Time per request:       242.434 [ms] (mean)
Time per request:       1.865 [ms] (mean, across all concurrent requests)
Transfer rate:          33216.23 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2  23.1      1    1003
Processing:     3  241 130.0    226   12074
Waiting:        2  237 115.0    225   12074
Total:          3  242 131.7    227   12076

備註:Time per request (mean) 的數字是前一測試的 2 倍

Concurrent = 150

Concurrency Level:      150
Time taken for tests:   282.285 seconds
Complete requests:      150000
Failed requests:        14729
   (Connect: 0, Receive: 0, Length: 14729, Exceptions: 0)
Write errors:           0
Total transferred:      9514633552 bytes
HTML transferred:       9491233552 bytes
Requests per second:    531.38 [#/sec] (mean)
Time per request:       282.285 [ms] (mean)
Time per request:       1.882 [ms] (mean, across all concurrent requests)
Transfer rate:          32915.78 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   31 216.7      1   15033
Processing:     3  251 139.0    232   10376
Waiting:        2  247 114.2    231   10375
Total:          3  282 266.1    233   15457

Concurent = 160

Concurrency Level:      170
Time taken for tests:   317.403 seconds
Complete requests:      170000
Failed requests:        16740
   (Connect: 0, Receive: 5, Length: 16730, Exceptions: 5)
Write errors:           0
Total transferred:      10782807284 bytes
HTML transferred:       10756288376 bytes
Requests per second:    535.60 [#/sec] (mean)
Time per request:       317.403 [ms] (mean)
Time per request:       1.867 [ms] (mean, across all concurrent requests)
Transfer rate:          33175.80 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   62 306.8      1   31069
Processing:     3  255 628.6    233  102628
Waiting:        0  249 234.1    232   51562
Total:          4  317 709.2    235  103631

備註:Time per request (mean) 的數字開始往上飆

Concurrent = 200

Concurrency Level:      200
Time taken for tests:   412.996 seconds
Complete requests:      200000
Failed requests:        20032
   (Connect: 0, Receive: 50, Length: 19932, Exceptions: 50)
Write errors:           0
Total transferred:      12682435344 bytes
HTML transferred:       12651244548 bytes
Requests per second:    484.27 [#/sec] (mean)
Time per request:       412.996 [ms] (mean)
Time per request:       2.065 [ms] (mean, across all concurrent requests)
Transfer rate:          29988.67 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   91 412.2      1   63125
Processing:     3  287 1696.5    230  103192
Waiting:        0  256 342.9    230   51815
Total:          3  379 1780.0    233  106160

Apache mpm-worker + mod_proxy + php-fpm

Apache mpm-worker 的設定如下:

<IfModule mpm_worker_module>
    StartServers             3
    MinSpareThreads        100
    MaxSpareThreads        150
    ThreadsPerChild         25
    MaxRequestWorkers      400
    MaxConnectionsPerChild   0
</IfModule>

mod_proxy 為了 debug,apache document root 和 php-fpm document root 暫時設定成不同目錄。參數設定如下:

<IfModule proxy_module>
    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/home/www/data/zero/$1
</IfModule>

而 php-fpm (7.1) 的設定則保留預設值不更動:

listen = 127.0.0.1:9000

pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35

Concurrent = 1

Concurrency Level:      1
Time taken for tests:   2.572 seconds
Complete requests:      1000
Failed requests:        110
   (Connect: 0, Receive: 0, Length: 110, Exceptions: 0)
Write errors:           0
Total transferred:      59907879 bytes
HTML transferred:       59751879 bytes
Requests per second:    388.82 [#/sec] (mean)
Time per request:       2.572 [ms] (mean)
Time per request:       2.572 [ms] (mean, across all concurrent requests)
Transfer rate:          22747.63 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       4
Processing:     2    2   0.6      2       9
Waiting:        1    2   0.6      2       9
Total:          2    3   0.6      3      11

Concurrent = 10

Concurrency Level:      10
Time taken for tests:   21.550 seconds
Complete requests:      10000
Failed requests:        1008
   (Connect: 0, Receive: 0, Length: 1008, Exceptions: 0)
Write errors:           0
Total transferred:      599078889 bytes
HTML transferred:       597518889 bytes
Requests per second:    464.04 [#/sec] (mean)
Time per request:       21.550 [ms] (mean)
Time per request:       2.155 [ms] (mean, across all concurrent requests)
Transfer rate:          27148.14 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.6      1       9
Processing:     4   20  29.6     18     791
Waiting:        3   20  28.5     17     790
Total:          4   22  29.6     19     791

Concurrent = 20

Concurrency Level:      20
Time taken for tests:   41.767 seconds
Complete requests:      20000
Failed requests:        2062
   (Connect: 0, Receive: 0, Length: 2062, Exceptions: 0)
Write errors:           0
Total transferred:      1198157734 bytes
HTML transferred:       1195037734 bytes
Requests per second:    478.85 [#/sec] (mean)
Time per request:       41.767 [ms] (mean)
Time per request:       2.088 [ms] (mean, across all concurrent requests)
Transfer rate:          28014.52 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.6      1      10
Processing:    10   41  18.8     38     807
Waiting:        9   40  15.7     37     776
Total:         10   42  18.8     39     808

Concurrent = 30

Concurrency Level:      30
Time taken for tests:   63.062 seconds
Complete requests:      30000
Failed requests:        3015
   (Connect: 0, Receive: 0, Length: 3015, Exceptions: 0)
Write errors:           0
Total transferred:      1797236646 bytes
HTML transferred:       1792556646 bytes
Requests per second:    475.72 [#/sec] (mean)
Time per request:       63.062 [ms] (mean)
Time per request:       2.102 [ms] (mean, across all concurrent requests)
Transfer rate:          27831.48 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.6      1      11
Processing:     3   62  29.0     57     973
Waiting:        2   61  25.4     57     971
Total:          3   63  29.0     58     975

Concurrent = 50

Concurrency Level:      50
Time taken for tests:   104.370 seconds
Complete requests:      50000
Failed requests:        5135
   (Connect: 0, Receive: 0, Length: 5135, Exceptions: 0)
Write errors:           0
Total transferred:      2995394300 bytes
HTML transferred:       2987594300 bytes
Requests per second:    479.06 [#/sec] (mean)
Time per request:       104.370 [ms] (mean)
Time per request:       2.087 [ms] (mean, across all concurrent requests)
Transfer rate:          28027.08 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.6      1      18
Processing:    14  103  30.5     98    1156
Waiting:       10  102  26.7     97    1156
Total:         15  104  30.6     99    1157

Concurrent = 60

Concurrency Level:      60
Time taken for tests:   127.385 seconds
Complete requests:      60000
Failed requests:        5999
   (Connect: 0, Receive: 0, Length: 5999, Exceptions: 0)
Write errors:           0
Total transferred:      3594473363 bytes
HTML transferred:       3585113363 bytes
Requests per second:    471.01 [#/sec] (mean)
Time per request:       127.385 [ms] (mean)
Time per request:       2.123 [ms] (mean, across all concurrent requests)
Transfer rate:          27555.99 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.6      1      11
Processing:    16  126  36.1    119    1609
Waiting:       10  125  33.1    119    1609
Total:         17  127  36.2    121    1613

Concurrent = 90

Concurrency Level:      90
Time taken for tests:   192.103 seconds
Complete requests:      90000
Failed requests:        9158
   (Connect: 0, Receive: 0, Length: 9158, Exceptions: 0)
Write errors:           0
Total transferred:      5391709877 bytes
HTML transferred:       5377669877 bytes
Requests per second:    468.50 [#/sec] (mean)
Time per request:       192.103 [ms] (mean)
Time per request:       2.134 [ms] (mean, across all concurrent requests)
Transfer rate:          27408.92 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.6      1      15
Processing:    15  191  45.7    182    2196
Waiting:        9  189  40.7    181    1432
Total:         16  192  45.8    183    2197

Concurrent = 100

Concurrency Level:      100
Time taken for tests:   205.778 seconds
Complete requests:      100000
Failed requests:        10302
   (Connect: 0, Receive: 0, Length: 10302, Exceptions: 0)
Write errors:           0
Total transferred:      5990788583 bytes
HTML transferred:       5975188583 bytes
Requests per second:    485.96 [#/sec] (mean)
Time per request:       205.778 [ms] (mean)
Time per request:       2.058 [ms] (mean, across all concurrent requests)
Transfer rate:          28430.48 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.5      1      12
Processing:    17  205  35.1    196    1313
Waiting:       10  204  34.1    195    1313
Total:         17  206  35.2    197    1316

Concurrent = 130

Concurrency Level:      130
Time taken for tests:   273.013 seconds
Complete requests:      130000
Failed requests:        13339
   (Connect: 0, Receive: 0, Length: 13339, Exceptions: 0)
Write errors:           0
Total transferred:      7788025286 bytes
HTML transferred:       7767745286 bytes
Requests per second:    476.17 [#/sec] (mean)
Time per request:       273.013 [ms] (mean)
Time per request:       2.100 [ms] (mean, across all concurrent requests)
Transfer rate:          27857.63 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.6      1      62
Processing:    28  272  61.5    259    4925
Waiting:       13  270  56.3    259    4924
Total:         28  273  61.5    260    4926

Concurrent = 150

Concurrency Level:      150
Time taken for tests:   319.163 seconds
Complete requests:      150000
Failed requests:        15459
   (Connect: 0, Receive: 0, Length: 15459, Exceptions: 0)
Write errors:           0
Total transferred:      8986182836 bytes
HTML transferred:       8962782836 bytes
Requests per second:    469.98 [#/sec] (mean)
Time per request:       319.163 [ms] (mean)
Time per request:       2.128 [ms] (mean, across all concurrent requests)
Transfer rate:          27495.60 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   2.6      1    1003
Processing:    17  316 233.2    267   15293
Waiting:       11  315 232.5    267   15293
Total:         17  317 233.2    269   15294

Concurrent = 200

Concurrency Level:      200
Time taken for tests:   426.013 seconds
Complete requests:      200000
Failed requests:        20626
   (Connect: 0, Receive: 0, Length: 20626, Exceptions: 0)
Write errors:           0
Non-2xx responses:      1
Total transferred:      11981517680 bytes
HTML transferred:       11950317662 bytes
Requests per second:    469.47 [#/sec] (mean)
Time per request:       426.013 [ms] (mean)
Time per request:       2.130 [ms] (mean, across all concurrent requests)
Transfer rate:          27465.59 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   3.2      1    1002
Processing:    15  419 455.0    265   31069
Waiting:        5  417 454.7    265   31069
Total:         15  420 455.0    267   31071

concurrent = 1000

Concurrency Level:      1000
Time taken for tests:   2157.999 seconds
Complete requests:      1000000
Failed requests:        117658
   (Connect: 0, Receive: 3097, Length: 111464, Exceptions: 3097)
Write errors:           0
Non-2xx responses:      321
Total transferred:      59689428028 bytes
HTML transferred:       59533941418 bytes
Requests per second:    463.39 [#/sec] (mean)
Time per request:       2157.999 [ms] (mean)
Time per request:       2.158 [ms] (mean, across all concurrent requests)
Transfer rate:          27011.34 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  652 2253.4      1   63169
Processing:    70 1493 5523.6    758  207236
Waiting:        0 1216 1561.6    749  105186
Total:         90 2145 6034.7   1531  208239

備註:response time 完全沒有增加,真是太 magic 了

其他

Apache mpm-worker using mod_proxy to php-fpm (by unix socket)

同前一項測試,只是使用 unix socket 與 php-fpm 串接:

<IfModule proxy_module>
    ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/var/opt/remi/php71/run/php-fpm/php71-fpm.sock|fcgi://localhost/home/www/data/zero/
</IfModule>

Concurrent = 1

Concurrency Level:      1
Time taken for tests:   2.525 seconds
Complete requests:      1000
Failed requests:        95
   (Connect: 0, Receive: 0, Length: 95, Exceptions: 0)
Write errors:           0
Total transferred:      59908900 bytes
HTML transferred:       59752900 bytes
Requests per second:    396.10 [#/sec] (mean)
Time per request:       2.525 [ms] (mean)
Time per request:       2.525 [ms] (mean, across all concurrent requests)
Transfer rate:          23173.63 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.2      0       7
Processing:     2    2   0.8      2      13
Waiting:        1    2   0.8      1      12
Total:          2    3   0.9      2      13

Concurrent = 10

Concurrency Level:      10
Time taken for tests:   19.796 seconds
Complete requests:      10000
Failed requests:        980
   (Connect: 0, Receive: 0, Length: 980, Exceptions: 0)
Write errors:           0
Total transferred:      599088919 bytes
HTML transferred:       597528919 bytes
Requests per second:    505.15 [#/sec] (mean)
Time per request:       19.796 [ms] (mean)
Time per request:       1.980 [ms] (mean, across all concurrent requests)
Transfer rate:          29553.49 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.5      1       9
Processing:     7   19  28.8     17     756
Waiting:        6   18  28.3     16     756
Total:          7   20  28.8     18     757

Concurrent = 20

Concurrency Level:      20
Time taken for tests:   40.003 seconds
Complete requests:      20000
Failed requests:        2022
   (Connect: 0, Receive: 0, Length: 2022, Exceptions: 0)
Write errors:           0
Total transferred:      1198177747 bytes
HTML transferred:       1195057747 bytes
Requests per second:    499.97 [#/sec] (mean)
Time per request:       40.003 [ms] (mean)
Time per request:       2.000 [ms] (mean, across all concurrent requests)
Transfer rate:          29250.45 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.5      1       8
Processing:    10   39  25.8     36    1038
Waiting:        9   38  25.0     35    1038
Total:         11   40  25.8     37    1039

Concurrent = 30

Concurrency Level:      30
Time taken for tests:   58.068 seconds
Complete requests:      30000
Failed requests:        2938
   (Connect: 0, Receive: 0, Length: 2938, Exceptions: 0)
Write errors:           0
Total transferred:      1797266739 bytes
HTML transferred:       1792586739 bytes
Requests per second:    516.64 [#/sec] (mean)
Time per request:       58.068 [ms] (mean)
Time per request:       1.936 [ms] (mean, across all concurrent requests)
Transfer rate:          30225.81 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.5      1       8
Processing:    13   57  15.2     55     835
Waiting:        9   56  12.4     54     666
Total:         13   58  15.2     56     836

Concurrent = 50

Concurrency Level:      50
Time taken for tests:   95.847 seconds
Complete requests:      50000
Failed requests:        4965
   (Connect: 0, Receive: 0, Length: 4965, Exceptions: 0)
Write errors:           0
Total transferred:      2995444499 bytes
HTML transferred:       2987644499 bytes
Requests per second:    521.66 [#/sec] (mean)
Time per request:       95.847 [ms] (mean)
Time per request:       1.917 [ms] (mean, across all concurrent requests)
Transfer rate:          30519.88 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.5      1       9
Processing:    11   95  11.7     91     831
Waiting:        9   94  11.7     90     830
Total:         12   96  11.8     92     831

Concurrent = 60

Concurrency Level:      60
Time taken for tests:   115.929 seconds
Complete requests:      60000
Failed requests:        6108
   (Connect: 0, Receive: 0, Length: 6108, Exceptions: 0)
Write errors:           0
Total transferred:      3594533190 bytes
HTML transferred:       3585173190 bytes
Requests per second:    517.56 [#/sec] (mean)
Time per request:       115.929 [ms] (mean)
Time per request:       1.932 [ms] (mean, across all concurrent requests)
Transfer rate:          30279.60 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.5      1      12
Processing:    12  115  15.5    112     978
Waiting:       10  114  14.5    111     978
Total:         12  116  15.5    113     980

Concurrent = 90

Concurrency Level:      90
Time taken for tests:   175.606 seconds
Complete requests:      90000
Failed requests:        8887
   (Connect: 0, Receive: 0, Length: 8887, Exceptions: 0)
Write errors:           0
Total transferred:      5391800113 bytes
HTML transferred:       5377760113 bytes
Requests per second:    512.51 [#/sec] (mean)
Time per request:       175.606 [ms] (mean)
Time per request:       1.951 [ms] (mean, across all concurrent requests)
Transfer rate:          29984.40 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.5      1      23
Processing:    16  174  20.5    169    1963
Waiting:       10  174  20.4    168    1962
Total:         16  176  20.5    170    1964

Concurrent = 100

Concurrency Level:      100
Time taken for tests:   194.521 seconds
Complete requests:      100000
Failed requests:        10110
   (Connect: 0, Receive: 0, Length: 10110, Exceptions: 0)
Write errors:           0
Total transferred:      5990888763 bytes
HTML transferred:       5975288763 bytes
Requests per second:    514.08 [#/sec] (mean)
Time per request:       194.521 [ms] (mean)
Time per request:       1.945 [ms] (mean, across all concurrent requests)
Transfer rate:          30076.28 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.5      1      22
Processing:    17  193  19.9    190    1677
Waiting:       10  192  18.6    189    1014
Total:         18  194  19.9    191    1678

Concurrent = 130

Concurrency Level:      130
Time taken for tests:   254.946 seconds
Complete requests:      130000
Failed requests:        12984
   (Connect: 0, Receive: 0, Length: 12984, Exceptions: 0)
Write errors:           0
Total transferred:      7788155482 bytes
HTML transferred:       7767875482 bytes
Requests per second:    509.91 [#/sec] (mean)
Time per request:       254.946 [ms] (mean)
Time per request:       1.961 [ms] (mean, across all concurrent requests)
Transfer rate:          29832.27 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.5      1      11
Processing:    17  254  25.9    248    1040
Waiting:        9  253  25.8    248    1039
Total:         18  255  26.0    250    1041

Concurrent = 150

Concurrency Level:      150
Time taken for tests:   294.659 seconds
Complete requests:      150000
Failed requests:        15100
   (Connect: 0, Receive: 0, Length: 15100, Exceptions: 0)
Write errors:           0
Total transferred:      8986333144 bytes
HTML transferred:       8962933144 bytes
Requests per second:    509.06 [#/sec] (mean)
Time per request:       294.659 [ms] (mean)
Time per request:       1.964 [ms] (mean, across all concurrent requests)
Transfer rate:          29782.57 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   2.6      1    1002
Processing:    12  293  26.3    289    4252
Waiting:        5  293  26.2    288    4251
Total:         12  295  26.5    290    4253

Concurrent = 200

Concurrency Level:      200
Time taken for tests:   399.407 seconds
Complete requests:      200000
Failed requests:        20118
   (Connect: 0, Receive: 0, Length: 20118, Exceptions: 0)
Write errors:           0
Total transferred:      11981777559 bytes
HTML transferred:       11950577559 bytes
Requests per second:    500.74 [#/sec] (mean)
Time per request:       399.407 [ms] (mean)
Time per request:       1.997 [ms] (mean, across all concurrent requests)
Transfer rate:          29295.82 [Kbytes/sec] received

Concurrent = 1000

Concurrency Level:      1000
Time taken for tests:   1968.303 seconds
Complete requests:      1000000
Failed requests:        107190
   (Connect: 0, Receive: 1672, Length: 103846, Exceptions: 1672)
Write errors:           0
Total transferred:      59802945204 bytes
HTML transferred:       59647221012 bytes
Requests per second:    508.05 [#/sec] (mean)
Time per request:       1968.303 [ms] (mean)
Time per request:       1.968 [ms] (mean, across all concurrent requests)
Transfer rate:          29670.90 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  727 2374.7      1   63170
Processing:    47 1237 3517.2   1041  127335
Waiting:        0 1116 703.8   1040   53069
Total:         47 1964 4278.6   1073  127335

備註

使用 unix socket 來串接 apache 與 php-fpm,效果與使用 http proxy 還要好。

藉由上面的測試果可以注意到 Requests per second 平均增加了 40 個左右 (約 8 %)

Nginx + php-fpm

使用 nginx 將 requestw proxy 給 php-fpm 處理。

nginx 設定:

location ~ \.php* {
    root           /home/www/data;

    include        fastcgi_params;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
}

php-fpm 的設定維持預設值:

listen = 127.0.0.1:9000

pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35

Conrurrent = 1

Concurrency Level:      1
Time taken for tests:   2.644 seconds
Complete requests:      1000
Failed requests:        60
   (Connect: 0, Receive: 0, Length: 60, Exceptions: 0)
Write errors:           0
Total transferred:      66757930 bytes
HTML transferred:       66595930 bytes
Requests per second:    378.15 [#/sec] (mean)
Time per request:       2.644 [ms] (mean)
Time per request:       2.644 [ms] (mean, across all concurrent requests)
Transfer rate:          24653.06 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       2
Processing:     2    2   0.4      2      11
Waiting:        1    1   0.2      1       4
Total:          2    3   0.5      3      11

Conrurrent = 10

Concurrency Level:      10
Time taken for tests:   11.006 seconds
Complete requests:      10000
Failed requests:        1073
   (Connect: 0, Receive: 0, Length: 1073, Exceptions: 0)
Write errors:           0
Total transferred:      667578812 bytes
HTML transferred:       665958812 bytes
Requests per second:    908.57 [#/sec] (mean)
Time per request:       11.006 [ms] (mean)
Time per request:       1.101 [ms] (mean, across all concurrent requests)
Transfer rate:          59232.78 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.4      0      11
Processing:     3   11   1.3     10      21
Waiting:        2    8   1.3      8      20
Total:          4   11   1.2     11      23

Conrurrent = 20

Concurrency Level:      20
Time taken for tests:   21.821 seconds
Complete requests:      20000
Failed requests:        2052
   (Connect: 0, Receive: 0, Length: 2052, Exceptions: 0)
Write errors:           0
Total transferred:      1335157720 bytes
HTML transferred:       1331917720 bytes
Requests per second:    916.56 [#/sec] (mean)
Time per request:       21.821 [ms] (mean)
Time per request:       1.091 [ms] (mean, across all concurrent requests)
Transfer rate:          59753.33 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.5      0      11
Processing:     3   21   2.3     21      41
Waiting:        2   17   2.3     17      36
Total:          6   22   2.2     22      41

Conrurrent = 30

Concurrency Level:      30
Time taken for tests:   32.485 seconds
Complete requests:      30000
Failed requests:        27216
   (Connect: 0, Receive: 0, Length: 27216, Exceptions: 0)
Write errors:           0
Total transferred:      2002736618 bytes
HTML transferred:       1997876618 bytes
Requests per second:    923.51 [#/sec] (mean)
Time per request:       32.485 [ms] (mean)
Time per request:       1.083 [ms] (mean, across all concurrent requests)
Transfer rate:          60206.88 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.8      0      12
Processing:     7   32   2.2     32      56
Waiting:        4   26   2.5     25      51
Total:          7   32   2.0     32      56

Conrurrent = 50

Concurrency Level:      50
Time taken for tests:   54.582 seconds
Complete requests:      50000
Failed requests:        5026
   (Connect: 0, Receive: 0, Length: 5026, Exceptions: 0)
Write errors:           0
Total transferred:      3337894408 bytes
HTML transferred:       3329794408 bytes
Requests per second:    916.05 [#/sec] (mean)
Time per request:       54.582 [ms] (mean)
Time per request:       1.092 [ms] (mean, across all concurrent requests)
Transfer rate:          59720.00 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   1.3      1      13
Processing:    11   53   3.2     53      84
Waiting:        3   44   3.7     44      74
Total:         11   55   2.9     54      84

Conrurrent = 60

Concurrency Level:      60
Time taken for tests:   63.576 seconds
Complete requests:      60000
Failed requests:        6143
   (Connect: 0, Receive: 0, Length: 6143, Exceptions: 0)
Write errors:           0
Total transferred:      4005473189 bytes
HTML transferred:       3995753189 bytes
Requests per second:    943.75 [#/sec] (mean)
Time per request:       63.576 [ms] (mean)
Time per request:       1.060 [ms] (mean, across all concurrent requests)
Transfer rate:          61526.10 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   1.5      1      16
Processing:    14   62   4.0     62      96
Waiting:        3   51   4.9     50      88
Total:         15   64   3.6     63      96

Conrurrent = 90

Concurrency Level:      90
Time taken for tests:   96.609 seconds
Complete requests:      90000
Failed requests:        9177
   (Connect: 0, Receive: 0, Length: 9177, Exceptions: 0)
Write errors:           0
Total transferred:      6008209767 bytes
HTML transferred:       5993629767 bytes
Requests per second:    931.59 [#/sec] (mean)
Time per request:       96.609 [ms] (mean)
Time per request:       1.073 [ms] (mean, across all concurrent requests)
Transfer rate:          60733.55 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   1.9      1      19
Processing:    16   95   6.1     95     181
Waiting:        3   78   7.5     77     166
Total:         16   97   5.8     96     181

Conrurrent = 100

Concurrency Level:      100
Time taken for tests:   110.069 seconds
Complete requests:      100000
Failed requests:        10033
   (Connect: 0, Receive: 0, Length: 10033, Exceptions: 0)
Write errors:           0
Total transferred:      6675788874 bytes
HTML transferred:       6659588874 bytes
Requests per second:    908.53 [#/sec] (mean)
Time per request:       110.069 [ms] (mean)
Time per request:       1.101 [ms] (mean, across all concurrent requests)
Transfer rate:          59229.70 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   1.5      1      17
Processing:    15  108  10.0    107     165
Waiting:        3   89  11.3     87     158
Total:         15  110   9.7    109     166

Conrurrent = 130

Concurrency Level:      130
Time taken for tests:   141.054 seconds
Complete requests:      130000
Failed requests:        13194
   (Connect: 0, Receive: 0, Length: 13194, Exceptions: 0)
Write errors:           0
Total transferred:      8678525300 bytes
HTML transferred:       8657465300 bytes
Requests per second:    921.63 [#/sec] (mean)
Time per request:       141.054 [ms] (mean)
Time per request:       1.085 [ms] (mean, across all concurrent requests)
Transfer rate:          60084.24 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   1.6      1      22
Processing:    21  139  21.4    148     248
Waiting:        4  120  21.6    131     228
Total:         26  141  20.2    149     248

Conrurrent = 150

Concurrency Level:      150
Time taken for tests:   161.197 seconds
Complete requests:      150000
Failed requests:        15205
   (Connect: 0, Receive: 0, Length: 15205, Exceptions: 0)
Write errors:           0
Total transferred:      10013683104 bytes
HTML transferred:       9989383104 bytes
Requests per second:    930.54 [#/sec] (mean)
Time per request:       161.197 [ms] (mean)
Time per request:       1.075 [ms] (mean, across all concurrent requests)
Transfer rate:          60664.70 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   1.5      1      16
Processing:    20  159  21.9    159    1954
Waiting:        4  139  22.4    138    1950
Total:         21  161  21.9    161    1960

Conrurrent = 200

Concurrency Level:      200
Time taken for tests:   218.920 seconds
Complete requests:      200000
Failed requests:        20190
   (Connect: 0, Receive: 0, Length: 20190, Exceptions: 0)
Write errors:           0
Total transferred:      13351577585 bytes
HTML transferred:       13319177585 bytes
Requests per second:    913.58 [#/sec] (mean)
Time per request:       218.920 [ms] (mean)
Time per request:       1.095 [ms] (mean, across all concurrent requests)
Transfer rate:          59559.06 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2  18.0      1    1009
Processing:    25  216 168.2    203    7572
Waiting:        5  197 168.2    185    7562
Total:         30  219 168.9    204    7579

Conrurrent = 1000

Concurrency Level:      1000
Time taken for tests:   1396.733 seconds
Complete requests:      1000000
Failed requests:        998172
   (Connect: 0, Receive: 419, Length: 997334, Exceptions: 419)
Write errors:           0
Non-2xx responses:      2667
Total transferred:      66553749124 bytes
HTML transferred:       66391814410 bytes
Requests per second:    715.96 [#/sec] (mean)
Time per request:       1396.733 [ms] (mean)
Time per request:       1.397 [ms] (mean, across all concurrent requests)
Transfer rate:          46532.80 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  703 2690.1      2   63172
Processing:     7  687 2645.4    362  127326
Waiting:        4  615 531.3    342   13363
Total:         27 1390 3794.7    643  127326

注意:有非 200 的 response (Non-2xx responses)

Nginx + php-fpm using unix socket

與前一項測試沒有特別調整,僅將 php-fpm 改為 listen to unix socket:

 location ~ \.php* {
    root           /home/www/data;

    include        fastcgi_params;
    fastcgi_pass   unix:/var/opt/remi/php71/run/php-fpm/php71-fpm.sock;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
}

Concorrent = 1

Concurrency Level:      1
Time taken for tests:   2.820 seconds
Complete requests:      1000
Failed requests:        91
   (Connect: 0, Receive: 0, Length: 91, Exceptions: 0)
Write errors:           0
Total transferred:      66757900 bytes
HTML transferred:       66595900 bytes
Requests per second:    354.61 [#/sec] (mean)
Time per request:       2.820 [ms] (mean)
Time per request:       2.820 [ms] (mean, across all concurrent requests)
Transfer rate:          23118.08 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       2
Processing:     2    3   0.4      3      10
Waiting:        1    1   0.3      1      10
Total:          2    3   0.4      3      11

Concorrent = 10

Concurrency Level:      10
Time taken for tests:   10.485 seconds
Complete requests:      10000
Failed requests:        1028
   (Connect: 0, Receive: 0, Length: 1028, Exceptions: 0)
Write errors:           0
Total transferred:      667578856 bytes
HTML transferred:       665958856 bytes
Requests per second:    953.79 [#/sec] (mean)
Time per request:       10.485 [ms] (mean)
Time per request:       1.048 [ms] (mean, across all concurrent requests)
Transfer rate:          62180.37 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.4      0      11
Processing:     4   10   1.2     10      20
Waiting:        1    7   1.2      7      19
Total:          4   10   1.1     10      21

Concorrent = 20

Concurrency Level:      20
Time taken for tests:   20.870 seconds
Complete requests:      20000
Failed requests:        2003
   (Connect: 0, Receive: 0, Length: 2003, Exceptions: 0)
Write errors:           0
Total transferred:      1335157779 bytes
HTML transferred:       1331917779 bytes
Requests per second:    958.30 [#/sec] (mean)
Time per request:       20.870 [ms] (mean)
Time per request:       1.044 [ms] (mean, across all concurrent requests)
Transfer rate:          62474.41 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.5      0      10
Processing:     4   20   2.2     20      41
Waiting:        2   16   2.3     15      36
Total:          6   21   2.1     21      42

Concorrent = 30

Concurrency Level:      30
Time taken for tests:   31.168 seconds
Complete requests:      30000
Failed requests:        3138
   (Connect: 0, Receive: 0, Length: 3138, Exceptions: 0)
Write errors:           0
Total transferred:      2002736526 bytes
HTML transferred:       1997876526 bytes
Requests per second:    962.54 [#/sec] (mean)
Time per request:       31.168 [ms] (mean)
Time per request:       1.039 [ms] (mean, across all concurrent requests)
Transfer rate:          62750.85 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.6      1      11
Processing:     5   30   2.5     30      58
Waiting:        3   24   3.1     23      51
Total:          8   31   2.4     31      58

Concorrent = 50

Concurrency Level:      50
Time taken for tests:   50.873 seconds
Complete requests:      50000
Failed requests:        45619
   (Connect: 0, Receive: 0, Length: 45619, Exceptions: 0)
Write errors:           0
Total transferred:      3337894514 bytes
HTML transferred:       3329794514 bytes
Requests per second:    982.85 [#/sec] (mean)
Time per request:       50.873 [ms] (mean)
Time per request:       1.017 [ms] (mean, across all concurrent requests)
Transfer rate:          64075.07 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.9      1      12
Processing:     9   50   3.3     49      82
Waiting:        3   40   4.6     39      72
Total:         10   51   3.1     51      83

Concorrent = 60

Concurrency Level:      60
Time taken for tests:   60.940 seconds
Complete requests:      60000
Failed requests:        6048
   (Connect: 0, Receive: 0, Length: 6048, Exceptions: 0)
Write errors:           0
Total transferred:      4005473243 bytes
HTML transferred:       3995753243 bytes
Requests per second:    984.57 [#/sec] (mean)
Time per request:       60.940 [ms] (mean)
Time per request:       1.016 [ms] (mean, across all concurrent requests)
Transfer rate:          64187.60 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   1.0      1      15
Processing:    11   60   4.1     59     269
Waiting:        3   47   5.3     46      83
Total:         11   61   3.9     61     271

Concorrent = 90

Concurrency Level:      90
Time taken for tests:   90.695 seconds
Complete requests:      90000
Failed requests:        81665
   (Connect: 0, Receive: 0, Length: 81665, Exceptions: 0)
Write errors:           0
Total transferred:      6008209722 bytes
HTML transferred:       5993629722 bytes
Requests per second:    992.34 [#/sec] (mean)
Time per request:       90.695 [ms] (mean)
Time per request:       1.008 [ms] (mean, across all concurrent requests)
Transfer rate:          64693.84 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   1.3      1      15
Processing:    14   89   6.3     89     314
Waiting:        3   71   7.4     69     283
Total:         15   91   6.2     90     318

Concorrent = 100

Concurrency Level:      100
Time taken for tests:   99.303 seconds
Complete requests:      100000
Failed requests:        90843
   (Connect: 0, Receive: 0, Length: 90843, Exceptions: 0)
Write errors:           0
Total transferred:      6675788606 bytes
HTML transferred:       6659588606 bytes
Requests per second:    1007.02 [#/sec] (mean)
Time per request:       99.303 [ms] (mean)
Time per request:       0.993 [ms] (mean, across all concurrent requests)
Transfer rate:          65650.83 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   1.4      1      14
Processing:    15   97   5.9     97     153
Waiting:        3   77   8.2     76     143
Total:         15   99   5.7     99     153

Concorrent = 130

Concurrency Level:      130
Time taken for tests:   132.578 seconds
Complete requests:      130000
Failed requests:        128802
   (Connect: 0, Receive: 0, Length: 128802, Exceptions: 0)
Write errors:           0
Non-2xx responses:      1
Total transferred:      8678458623 bytes
HTML transferred:       8657398635 bytes
Requests per second:    980.56 [#/sec] (mean)
Time per request:       132.578 [ms] (mean)
Time per request:       1.020 [ms] (mean, across all concurrent requests)
Transfer rate:          63925.30 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   3.2      1    1004
Processing:     1  131  20.3    139     367
Waiting:        1  111  20.5    121     338
Total:          1  132  19.4    140    1108

注意:有 non-2xx error

Concorrent = 150

Concurrency Level:      150
Time taken for tests:   147.572 seconds
Complete requests:      150000
Failed requests:        19015
   (Connect: 0, Receive: 0, Length: 19015, Exceptions: 0)
Write errors:           0
Non-2xx responses:      4306
Total transferred:      9727597298 bytes
HTML transferred:       9703348970 bytes
Requests per second:    1016.45 [#/sec] (mean)
Time per request:       147.572 [ms] (mean)
Time per request:       0.984 [ms] (mean, across all concurrent requests)
Transfer rate:          64372.73 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   1.5      1      46
Processing:     1  146  25.6    149     416
Waiting:        0  125  22.6    128     346
Total:          3  147  25.7    151     420

注意:non-2xx error 約 3%

Concorrent = 200

Concurrency Level:      200
Time taken for tests:   125.650 seconds
Complete requests:      200000
Failed requests:        119747
   (Connect: 0, Receive: 0, Length: 119747, Exceptions: 0)
Write errors:           0
Non-2xx responses:      80253
Total transferred:      8019657351 bytes
HTML transferred:       7988220387 bytes
Requests per second:    1591.72 [#/sec] (mean)
Time per request:       125.650 [ms] (mean)
Time per request:       0.628 [ms] (mean, across all concurrent requests)
Transfer rate:          62329.40 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    3   2.5      2      25
Processing:     2  123  82.9    163     583
Waiting:        1  110  73.4    141     581
Total:          3  126  84.1    169     583

注意:有 non-2xx error,有約 37% 的 request 沒有正常執行

Conrurrent = 200 (double Nginx worker)

多加一個 Nginx worker,看看 non-2xx 的錯誤是不是 Nginx 那邊產生的。

Concurrency Level:      200
Time taken for tests:   125.650 seconds
Complete requests:      200000
Failed requests:        119747
   (Connect: 0, Receive: 0, Length: 119747, Exceptions: 0)
Write errors:           0
Non-2xx responses:      80253
Total transferred:      8019657351 bytes
HTML transferred:       7988220387 bytes
Requests per second:    1591.72 [#/sec] (mean)
Time per request:       125.650 [ms] (mean)
Time per request:       0.628 [ms] (mean, across all concurrent requests)
Transfer rate:          62329.40 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    3   2.5      2      25
Processing:     2  123  82.9    163     583
Waiting:        1  110  73.4    141     581
Total:          3  126  84.1    169     583

注意:還是有約 40% 的 non-2xx error

Conrurrent = 200 (double php-fpm proccess)

從前一項測試可以看出 non-2xx error 和 Nginx worker 沒關係。

這次把 php-fpm 的 process 數量限制放寬,看看狀況有沒有比較好:

pm.max_children = 100

測試結果

Concurrency Level:      200
Time taken for tests:   168.590 seconds
Complete requests:      200000
Failed requests:        49721
   (Connect: 0, Receive: 0, Length: 49721, Exceptions: 0)
Write errors:           0
Non-2xx responses:      33263
Total transferred:      11141621197 bytes
HTML transferred:       11109620353 bytes
Requests per second:    1186.31 [#/sec] (mean)
Time per request:       168.590 [ms] (mean)
Time per request:       0.843 [ms] (mean, across all concurrent requests)
Transfer rate:          64538.22 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   10  82.8      3    1017
Processing:     2  159  72.5    179     482
Waiting:        1  128  60.8    142     433
Total:          4  168 111.9    183    1442

注意:non-2xx 的 error 下降到約 16%,所以可能和 max_children 設定有關。

Concurrent = 200 (one half php-fpm process)

這次故意把 max_child 調低,看看是否會讓錯誤爆增:

pm.max_children = 25

測試結果:

Concurrency Level:      200
Time taken for tests:   74.952 seconds
Complete requests:      200000
Failed requests:        141886
   (Connect: 0, Receive: 0, Length: 141886, Exceptions: 0)
Write errors:           0
Non-2xx responses:      135173
Total transferred:      4370833600 bytes
HTML transferred:       4340055676 bytes
Requests per second:    2668.39 [#/sec] (mean)
Time per request:       74.952 [ms] (mean)
Time per request:       0.375 [ms] (mean, across all concurrent requests)
Transfer rate:          56948.58 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    3   1.7      3      19
Processing:     2   72  75.1     24     398
Waiting:        1   68  69.9     23     387
Total:          4   75  76.1     26     408

注意:non-2xx error 錯誤率上升到約 70%

PHP built-in server (PHP -S)

直接使用 php -s 來建立 HTTP service

Concurrent = 1

Concurrency Level:      1
Time taken for tests:   2.877 seconds
Complete requests:      1000
Failed requests:        95
   (Connect: 0, Receive: 0, Length: 95, Exceptions: 0)
Write errors:           0
Total transferred:      70524893 bytes
HTML transferred:       70358893 bytes
Requests per second:    347.62 [#/sec] (mean)
Time per request:       2.877 [ms] (mean)
Time per request:       2.877 [ms] (mean, across all concurrent requests)
Transfer rate:          23941.34 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       1
Processing:     2    3   5.8      2     185
Waiting:        1    1   5.8      1     184
Total:          2    3   5.8      3     186

Concurrent = 10

Concurrency Level:      10
Time taken for tests:   9.030 seconds
Complete requests:      10000
Failed requests:        1049
   (Connect: 0, Receive: 0, Length: 1049, Exceptions: 0)
Write errors:           0
Total transferred:      705248837 bytes
HTML transferred:       703588837 bytes
Requests per second:    1107.48 [#/sec] (mean)
Time per request:       9.030 [ms] (mean)
Time per request:       0.903 [ms] (mean, across all concurrent requests)
Transfer rate:          76273.98 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.2      0      11
Processing:     3    8   0.8      8      20
Waiting:        1    6   0.9      6      18
Total:          3    9   0.8      9      21

Concurrent = 30

Concurrency Level:      30
Time taken for tests:   26.815 seconds
Complete requests:      30000
Failed requests:        3055
   (Connect: 0, Receive: 0, Length: 3055, Exceptions: 0)
Write errors:           0
Total transferred:      2115746606 bytes
HTML transferred:       2110766606 bytes
Requests per second:    1118.78 [#/sec] (mean)
Time per request:       26.815 [ms] (mean)
Time per request:       0.894 [ms] (mean, across all concurrent requests)
Transfer rate:          77052.82 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.3      1      12
Processing:     3   26   2.9     26      57
Waiting:        1   24   2.9     24      53
Total:          5   27   2.8     27      57

Concurrent = 50

Concurrency Level:      50
Time taken for tests:   45.081 seconds
Complete requests:      50000
Failed requests:        5121
   (Connect: 0, Receive: 0, Length: 5121, Exceptions: 0)
Write errors:           0
Total transferred:      3526244279 bytes
HTML transferred:       3517944279 bytes
Requests per second:    1109.12 [#/sec] (mean)
Time per request:       45.081 [ms] (mean)
Time per request:       0.902 [ms] (mean, across all concurrent requests)
Transfer rate:          76387.26 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.3      1      12
Processing:     3   44   2.4     44      67
Waiting:        2   42   2.4     42      62
Total:          6   45   2.4     45      68

Concurrent = 60

Concurrency Level:      60
Time taken for tests:   54.506 seconds
Complete requests:      60000
Failed requests:        6241
   (Connect: 0, Receive: 0, Length: 6241, Exceptions: 0)
Write errors:           0
Total transferred:      4231493057 bytes
HTML transferred:       4221533057 bytes
Requests per second:    1100.80 [#/sec] (mean)
Time per request:       54.506 [ms] (mean)
Time per request:       0.908 [ms] (mean, across all concurrent requests)
Transfer rate:          75813.95 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.3      1      12
Processing:     4   54   2.7     54      81
Waiting:        2   51   2.7     51      74
Total:         11   54   2.7     54      82

Concurrent = 90

Concurrency Level:      90
Time taken for tests:   80.533 seconds
Complete requests:      90000
Failed requests:        9294
   (Connect: 0, Receive: 0, Length: 9294, Exceptions: 0)
Write errors:           0
Total transferred:      6347239635 bytes
HTML transferred:       6332299635 bytes
Requests per second:    1117.56 [#/sec] (mean)
Time per request:       80.533 [ms] (mean)
Time per request:       0.895 [ms] (mean, across all concurrent requests)
Transfer rate:          76968.59 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.5      1      16
Processing:    15   80   4.1     80     143
Waiting:        4   77   4.0     78     109
Total:         25   80   4.0     81     143

Concurrent = 100

Concurrency Level:      100
Time taken for tests:   90.078 seconds
Complete requests:      100000
Failed requests:        10373
   (Connect: 0, Receive: 0, Length: 10373, Exceptions: 0)
Write errors:           0
Total transferred:      7052488501 bytes
HTML transferred:       7035888501 bytes
Requests per second:    1110.15 [#/sec] (mean)
Time per request:       90.078 [ms] (mean)
Time per request:       0.901 [ms] (mean, across all concurrent requests)
Transfer rate:          76458.34 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.5      1      65
Processing:     4   89   5.3     89     366
Waiting:        3   87   5.0     87     293
Total:         13   90   5.2     90     367

Concurrent = 150

Concurrency Level:      150
Time taken for tests:   134.598 seconds
Complete requests:      150000
Failed requests:        15711
   (Connect: 0, Receive: 0, Length: 15711, Exceptions: 0)
Write errors:           0
Total transferred:      10578732585 bytes
HTML transferred:       10553832585 bytes
Requests per second:    1114.43 [#/sec] (mean)
Time per request:       134.598 [ms] (mean)
Time per request:       0.897 [ms] (mean, across all concurrent requests)
Transfer rate:          76752.76 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   15 130.9      1    7018
Processing:     5  120  19.9    118     918
Waiting:        3  117  19.8    116     915
Total:         25  134 134.0    119    7138

Concurrent = 200

Concurrency Level:      200
Time taken for tests:   183.453 seconds
Complete requests:      200000
Failed requests:        20663
   (Connect: 0, Receive: 0, Length: 20663, Exceptions: 0)
Write errors:           0
Total transferred:      14104977033 bytes
HTML transferred:       14071777033 bytes
Requests per second:    1090.20 [#/sec] (mean)
Time per request:       183.453 [ms] (mean)
Time per request:       0.917 [ms] (mean, across all concurrent requests)
Transfer rate:          75084.05 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   60 279.9      1   15030
Processing:     7  123  28.3    121    1728
Waiting:        3  121  28.2    118    1724
Total:         23  183 284.1    122   15151

Nginx proxy to php -S

應網友要求,補個 Nginx 使用 proxy 模式將 request 轉給 PHP built-in server。

Nginx 設定:

location ~ \.php* {
    proxy_pass http://127.0.0.1:8080;
}

PHP built-in server 啟動指令:

php -q -S 127.0.0.1:8080

Concurrent = 1

Concurrency Level:      1
Time taken for tests:   2.909 seconds
Complete requests:      1000
Failed requests:        100
   (Connect: 0, Receive: 0, Length: 100, Exceptions: 0)
Write errors:           0
Total transferred:      75226888 bytes
HTML transferred:       75042888 bytes
Requests per second:    343.82 [#/sec] (mean)
Time per request:       2.909 [ms] (mean)
Time per request:       2.909 [ms] (mean, across all concurrent requests)
Transfer rate:          25258.27 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       2
Processing:     2    3   0.4      3      11
Waiting:        1    1   0.3      1      11
Total:          2    3   0.5      3      11

Concurrent = 10

Concurrency Level:      10
Time taken for tests:   11.639 seconds
Complete requests:      10000
Failed requests:        1024
   (Connect: 0, Receive: 0, Length: 1024, Exceptions: 0)
Write errors:           0
Total transferred:      752268864 bytes
HTML transferred:       750428864 bytes
Requests per second:    859.19 [#/sec] (mean)
Time per request:       11.639 [ms] (mean)
Time per request:       1.164 [ms] (mean, across all concurrent requests)
Transfer rate:          63119.55 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.4      0      10
Processing:     3   11   1.6     11      23
Waiting:        2    8   1.3      8      19
Total:          3   12   1.5     11      24

Concurrent = 20

Concurrency Level:      20
Time taken for tests:   23.126 seconds
Complete requests:      20000
Failed requests:        2141
   (Connect: 0, Receive: 0, Length: 2141, Exceptions: 0)
Write errors:           0
Total transferred:      1504537621 bytes
HTML transferred:       1500857621 bytes
Requests per second:    864.82 [#/sec] (mean)
Time per request:       23.126 [ms] (mean)
Time per request:       1.156 [ms] (mean, across all concurrent requests)
Transfer rate:          63532.60 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.6      0      11
Processing:     4   22   2.6     22      45
Waiting:        3   17   2.6     17      38
Total:          6   23   2.5     23      45

Concurrent = 30

Concurrency Level:      30
Time taken for tests:   0.239 seconds
Complete requests:      174
Failed requests:        15
   (Connect: 0, Receive: 0, Length: 15, Exceptions: 0)
Write errors:           0
Total transferred:      13089481 bytes
HTML transferred:       13057465 bytes
Requests per second:    728.07 [#/sec] (mean)
Time per request:       41.205 [ms] (mean)
Time per request:       1.373 [ms] (mean, across all concurrent requests)
Transfer rate:          53486.99 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.8      1       3
Processing:     7   36   7.3     38      52
Waiting:        2   32   7.3     33      49
Total:          7   37   6.8     39      52

Concurrent = 50

Concurrency Level:      50
Time taken for tests:   56.123 seconds
Complete requests:      50000
Failed requests:        5356
   (Connect: 0, Receive: 0, Length: 5356, Exceptions: 0)
Write errors:           0
Total transferred:      3761344072 bytes
HTML transferred:       3752144072 bytes
Requests per second:    890.89 [#/sec] (mean)
Time per request:       56.123 [ms] (mean)
Time per request:       1.122 [ms] (mean, across all concurrent requests)
Transfer rate:          65448.34 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.8      1      13
Processing:     9   55   5.3     52      78
Waiting:        4   50   5.5     47      72
Total:         10   56   4.9     54      78

Concurrent = 60

Concurrency Level:      60
Time taken for tests:   67.097 seconds
Complete requests:      60000
Failed requests:        6276
   (Connect: 0, Receive: 0, Length: 6276, Exceptions: 0)
Write errors:           0
Total transferred:      4513612994 bytes
HTML transferred:       4502572994 bytes
Requests per second:    894.23 [#/sec] (mean)
Time per request:       67.097 [ms] (mean)
Time per request:       1.118 [ms] (mean, across all concurrent requests)
Transfer rate:          65693.62 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.7      1      15
Processing:    10   66   5.1     65     101
Waiting:        3   61   5.2     59      95
Total:         10   67   4.9     66     101

Concurrent = 90

Concurrency Level:      90
Time taken for tests:   100.547 seconds
Complete requests:      90000
Failed requests:        9465
   (Connect: 0, Receive: 0, Length: 9465, Exceptions: 0)
Write errors:           0
Total transferred:      6770419484 bytes
HTML transferred:       6753859484 bytes
Requests per second:    895.11 [#/sec] (mean)
Time per request:       100.547 [ms] (mean)
Time per request:       1.117 [ms] (mean, across all concurrent requests)
Transfer rate:          65758.00 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.6      1      15
Processing:    15  100   5.8    101     129
Waiting:        3   94   5.9     96     123
Total:         16  100   5.6    102     129

Concurrent = 100

Concurrency Level:      100
Time taken for tests:   113.825 seconds
Complete requests:      100000
Failed requests:        10591
   (Connect: 0, Receive: 0, Length: 10591, Exceptions: 0)
Write errors:           0
Total transferred:      7522688219 bytes
HTML transferred:       7504288219 bytes
Requests per second:    878.54 [#/sec] (mean)
Time per request:       113.825 [ms] (mean)
Time per request:       1.138 [ms] (mean, across all concurrent requests)
Transfer rate:          64541.08 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   8.4      1    1002
Processing:    15  113   6.5    114     366
Waiting:        3  107   6.4    109     282
Total:         17  114  10.4    115    1108

Concurrent = 130

Concurrency Level:      130
Time taken for tests:   147.841 seconds
Complete requests:      130000
Failed requests:        13766
   (Connect: 0, Receive: 0, Length: 13766, Exceptions: 0)
Write errors:           0
Total transferred:      9779494787 bytes
HTML transferred:       9755574787 bytes
Requests per second:    879.32 [#/sec] (mean)
Time per request:       147.841 [ms] (mean)
Time per request:       1.137 [ms] (mean, across all concurrent requests)
Transfer rate:          64598.33 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.6      1      13
Processing:    18  147   7.8    146     340
Waiting:        3  141   7.8    140     335
Total:         19  148   7.5    146     340

Concurrent = 150

Concurrency Level:      150
Time taken for tests:   173.944 seconds
Complete requests:      150000
Failed requests:        15717
   (Connect: 0, Receive: 0, Length: 15717, Exceptions: 0)
Write errors:           0
Total transferred:      11284032625 bytes
HTML transferred:       11256432625 bytes
Requests per second:    862.35 [#/sec] (mean)
Time per request:       173.944 [ms] (mean)
Time per request:       1.160 [ms] (mean, across all concurrent requests)
Transfer rate:          63351.32 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.7      1      13
Processing:    21  172 112.6    161    7176
Waiting:        4  167 112.6    155    7170
Total:         21  173 112.6    162    7176

Concurrent = 200

Concurrency Level:      200
Time taken for tests:   228.933 seconds
Complete requests:      200000
Failed requests:        20881
   (Connect: 0, Receive: 0, Length: 20881, Exceptions: 0)
Write errors:           0
Total transferred:      15045377083 bytes
HTML transferred:       15008577083 bytes
Requests per second:    873.62 [#/sec] (mean)
Time per request:       228.933 [ms] (mean)
Time per request:       1.145 [ms] (mean, across all concurrent requests)
Transfer rate:          64179.17 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.7      1      21
Processing:    28  227 287.0    160   15169
Waiting:        3  221 286.9    154   15163
Total:         35  228 286.9    161   15169

Concurrent = 1000

Concurrency Level:      1000
Time taken for tests:   1600.061 seconds
Complete requests:      1000000
Failed requests:        996130
   (Connect: 0, Receive: 57, Length: 996016, Exceptions: 57)
Write errors:           0
Non-2xx responses:      3984
Total transferred:      74924675843 bytes
HTML transferred:       74740772323 bytes
Requests per second:    624.98 [#/sec] (mean)
Time per request:       1600.061 [ms] (mean)
Time per request:       1.600 [ms] (mean, across all concurrent requests)
Transfer rate:          45728.64 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  840 2240.3      1   63169
Processing:     1  756 1204.6    568  127334
Waiting:        1  744 734.3    563   15858
Total:          2 1596 2594.6   1160  127334

備註:

Concurrent = 1000 (Nginx worker = 2)

Concurrency Level:      1000
Time taken for tests:   1193.307 seconds
Complete requests:      1000000
Failed requests:        951924
   (Connect: 0, Receive: 0, Length: 951924, Exceptions: 0)
Write errors:           0
Non-2xx responses:      48567
Total transferred:      71590560503 bytes
HTML transferred:       71407634869 bytes
Requests per second:    838.01 [#/sec] (mean)
Time per request:       1193.307 [ms] (mean)
Time per request:       1.193 [ms] (mean, across all concurrent requests)
Transfer rate:          58587.33 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1  18.3      1    3008
Processing:     0 1184 1741.1   1173   61029
Waiting:        0 1179 1741.1   1168   61029
Total:          1 1185 1741.8   1173   61029

備註:

總結

做完壓力測試以後有幾個可以討論、注意的地方:

Reference