Nginx与Webman在不同场景下的ab与wrk压测结果
关于Nginx的压测
Nginx 默认配置下本机压测试:
ab: Requests per second: 255460.47 [#/sec] (mean) wrk: Requests/sec: 382319.95
[apple-ec@centos ~]$ ab -c100 -n100000 -k http://127.0.0.1/ This is ApacheBench, Version 2.3 <$Revision: 1843412 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient) Completed 10000 requests Completed 20000 requests Completed 30000 requests Completed 40000 requests Completed 50000 requests Completed 60000 requests Completed 70000 requests Completed 80000 requests Completed 90000 requests Completed 100000 requests Finished 100000 requests Server Software: nginx/1.14.1 Server Hostname: 127.0.0.1 Server Port: 80 Document Path: / Document Length: 4057 bytes Concurrency Level: 100 Time taken for tests: 0.391 seconds Complete requests: 100000 Failed requests: 0 Keep-Alive requests: 99044 Total transferred: 429595220 bytes HTML transferred: 405700000 bytes Requests per second: 255460.47 [#/sec] (mean) Time per request: 0.391 [ms] (mean) Time per request: 0.004 [ms] (mean, across all concurrent requests) Transfer rate: 1071724.57 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.1 0 2 Processing: 0 0 0.2 0 3 Waiting: 0 0 0.2 0 3 Total: 0 0 0.2 0 3 Percentage of the requests served within a certain time (ms) 50% 0 66% 0 75% 0 80% 1 90% 1 95% 1 98% 1 99% 1 100% 3 (longest request)
[apple-ec@centos bin]$ wrk -t12 -c1000 -d30s http://127.0.0.1/ Running 30s test @ http://127.0.0.1/ 12 threads and 1000 connections Thread Stats Avg Stdev Max +/- Stdev Latency 3.26ms 3.30ms 43.48ms 85.87% Req/Sec 32.06k 4.01k 64.10k 67.50% 11507842 requests in 30.10s, 46.04GB read Requests/sec: 382319.95 Transfer/sec: 1.53GB
非本机: ab: Requests per second: 45526.73 [#/sec] (mean) wrk: Requests/sec: 33207.26
╰─ ➜ data ab -c100 -n100000 -k http://centos.orb.local/ This is ApacheBench, Version 2.3 <$Revision: 1903618 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking centos.orb.local (be patient) Completed 10000 requests Completed 20000 requests Completed 30000 requests Completed 40000 requests Completed 50000 requests Completed 60000 requests Completed 70000 requests Completed 80000 requests Completed 90000 requests Completed 100000 requests Finished 100000 requests Server Software: nginx/1.14.1 Server Hostname: centos.orb.local Server Port: 80 Document Path: / Document Length: 4057 bytes Concurrency Level: 100 Time taken for tests: 2.197 seconds Complete requests: 100000 Failed requests: 0 Keep-Alive requests: 99050 Total transferred: 429595250 bytes HTML transferred: 405700000 bytes Requests per second: 45526.73 [#/sec] (mean) Time per request: 2.197 [ms] (mean) Time per request: 0.022 [ms] (mean, across all concurrent requests) Transfer rate: 190996.73 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.2 0 5 Processing: 0 2 1.3 2 25 Waiting: 0 2 1.3 2 25 Total: 0 2 1.3 2 25 Percentage of the requests served within a certain time (ms) 50% 2 66% 2 75% 2 80% 2 90% 3 95% 4 98% 7 99% 8 100% 25 (longest request)
╰─ ➜ data wrk -t12 -c1000 -d30s http://centos.orb.local/ Running 30s test @ http://centos.orb.local/ 12 threads and 1000 connections Thread Stats Avg Stdev Max +/- Stdev Latency 4.99ms 2.23ms 83.37ms 90.22% Req/Sec 3.92k 1.27k 8.31k 70.27% 999200 requests in 30.09s, 4.00GB read Socket errors: connect 758, read 0, write 0, timeout 0 Requests/sec: 33207.26 Transfer/sec: 136.05MB
webman:
本机测试, ab: Requests per second: 169148.07 [#/sec] (mean) wrk: Requests/sec: 733838.88
[apple-ec@centos webman]$ ab -c100 -n100000 -k http://0.0.0.0:8787/ This is ApacheBench, Version 2.3 <$Revision: 1843412 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 0.0.0.0 (be patient) Completed 10000 requests Completed 20000 requests Completed 30000 requests Completed 40000 requests Completed 50000 requests Completed 60000 requests Completed 70000 requests Completed 80000 requests Completed 90000 requests Completed 100000 requests Finished 100000 requests Server Software: workerman Server Hostname: 0.0.0.0 Server Port: 8787 Document Path: / Document Length: 1770 bytes Concurrency Level: 100 Time taken for tests: 0.591 seconds Complete requests: 100000 Failed requests: 0 Keep-Alive requests: 100000 Total transferred: 189300000 bytes HTML transferred: 177000000 bytes Requests per second: 169148.07 [#/sec] (mean) Time per request: 0.591 [ms] (mean) Time per request: 0.006 [ms] (mean, across all concurrent requests) Transfer rate: 312692.67 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.3 0 14 Processing: 0 1 0.3 1 14 Waiting: 0 1 0.3 1 4 Total: 0 1 0.4 1 15 Percentage of the requests served within a certain time (ms) 50% 1 66% 1 75% 1 80% 1 90% 1 95% 1 98% 1 99% 1 100% 15 (longest request)
[apple-ec@centos webman]$ wrk -t20 -c1000 -d30s http://0.0.0.0:8787/ Running 30s test @ http://0.0.0.0:8787/ 20 threads and 1000 connections Thread Stats Avg Stdev Max +/- Stdev Latency 2.29ms 3.23ms 85.90ms 87.80% Req/Sec 36.96k 5.03k 68.40k 70.78% 22087730 requests in 30.10s, 38.94GB read Requests/sec: 733838.88 Transfer/sec: 1.29GB
非本机测试: ab: Requests per second: 77372.01 [#/sec] (mean) wrk: Requests/sec: 84638.98
╰─ ➜ data ab -c100 -n100000 -k http://centos.orb.local:8787/ This is ApacheBench, Version 2.3 <$Revision: 1903618 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking centos.orb.local (be patient) Completed 10000 requests Completed 20000 requests Completed 30000 requests Completed 40000 requests Completed 50000 requests Completed 60000 requests Completed 70000 requests Completed 80000 requests Completed 90000 requests Completed 100000 requests Finished 100000 requests Server Software: workerman Server Hostname: centos.orb.local Server Port: 8787 Document Path: / Document Length: 1770 bytes Concurrency Level: 100 Time taken for tests: 1.292 seconds Complete requests: 100000 Failed requests: 0 Keep-Alive requests: 100000 Total transferred: 189300000 bytes HTML transferred: 177000000 bytes Requests per second: 77372.01 [#/sec] (mean) Time per request: 1.292 [ms] (mean) Time per request: 0.013 [ms] (mean, across all concurrent requests) Transfer rate: 143032.44 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.1 0 4 Processing: 1 1 0.3 1 9 Waiting: 0 1 0.3 1 9 Total: 1 1 0.3 1 9 Percentage of the requests served within a certain time (ms) 50% 1 66% 1 75% 1 80% 1 90% 2 95% 2 98% 2 99% 2 100% 9 (longest request)
╰─ ➜ data wrk -t12 -c1000 -d30s http://centos.orb.local:8787/ Running 30s test @ http://centos.orb.local:8787/ 12 threads and 1000 connections Thread Stats Avg Stdev Max +/- Stdev Latency 2.80ms 620.59us 18.55ms 86.07% Req/Sec 7.09k 3.70k 18.40k 76.97% 2539814 requests in 30.01s, 4.48GB read Socket errors: connect 758, read 0, write 0, timeout 0 Requests/sec: 84638.98 Transfer/sec: 152.80MB
本机测试:
nginx 转 webman
ab: Requests per second: 216965.86 [#/sec] (mean)
wrk: Requests/sec: 252283.54
nginx 配置: keepalive 10240;
upstream webman { server 127.0.0.1:8787; keepalive 10240; }
Nginx 的 keepalive 功能是指在客户端和服务器之间保持一个长连接,即使没有数据传输,连接也不会立即关闭。这样,当客户端需要再次发送请求时,可以重用这个已经建立的连接,而不需要重新建立一个新的连接。这可以减少连接建立和关闭的开销,提高网络传输效率。
具体来说,Nginx 的 keepalive 功能包括以下几个方面:
keepalive_timeout:设置连接的超时时间。如果连接在指定的时间内没有任何数据传输,连接将被关闭。
keepalive_requests:设置每个连接可以处理的请求数量。当达到指定的请求数量后,连接将被关闭。
keepalive_disable:在某些情况下,可以禁用 keepalive 功能。例如,当客户端不支持 keepalive 时。
TCP keepalive:Nginx 还可以利用 TCP 的 keepalive 机制,定期发送心跳包,检测连接是否仍然有效。
通过合理配置 keepalive 参数,可以提高 Nginx 服务器的性能和响应速度,同时减少网络拥塞和资源浪费。
[apple-ec@centos webman]$ ab -c100 -n100000 -k http://127.0.0.1:801/ This is ApacheBench, Version 2.3 <$Revision: 1843412 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient) Completed 10000 requests Completed 20000 requests Completed 30000 requests Completed 40000 requests Completed 50000 requests Completed 60000 requests Completed 70000 requests Completed 80000 requests Completed 90000 requests Completed 100000 requests Finished 100000 requests Server Software: nginx/1.14.1 Server Hostname: 127.0.0.1 Server Port: 801 Document Path: / Document Length: 1770 bytes Concurrency Level: 100 Time taken for tests: 0.461 seconds Complete requests: 100000 Failed requests: 0 Keep-Alive requests: 99050 Total transferred: 193295250 bytes HTML transferred: 177000000 bytes Requests per second: 216965.86 [#/sec] (mean) Time per request: 0.461 [ms] (mean) Time per request: 0.005 [ms] (mean, across all concurrent requests) Transfer rate: 409555.38 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.1 0 2 Processing: 0 0 0.2 0 4 Waiting: 0 0 0.2 0 4 Total: 0 0 0.2 0 5 Percentage of the requests served within a certain time (ms) 50% 0 66% 1 75% 1 80% 1 90% 1 95% 1 98% 1 99% 1 100% 5 (longest request)
[apple-ec@centos webman]$ wrk -t20 -c1000 -d30s http://127.0.0.1:801/ Running 30s test @ http://127.0.0.1:801/ 20 threads and 1000 connections Thread Stats Avg Stdev Max +/- Stdev Latency 4.32ms 3.35ms 88.64ms 76.44% Req/Sec 12.69k 1.03k 22.59k 75.93% 7592316 requests in 30.09s, 13.67GB read Requests/sec: 252283.54 Transfer/sec: 465.06MB
当upstream 去除 keepalive 10240 时:
ab: Requests per second: 50820.24 [#/sec] (mean)
wrk: Requests/sec: 74059.91
[apple-ec@centos webman]$ ab -c100 -n100000 -k http://127.0.0.1:801/ This is ApacheBench, Version 2.3 <$Revision: 1843412 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient) Completed 10000 requests Completed 20000 requests Completed 30000 requests Completed 40000 requests Completed 50000 requests Completed 60000 requests Completed 70000 requests Completed 80000 requests Completed 90000 requests Completed 100000 requests Finished 100000 requests Server Software: nginx/1.14.1 Server Hostname: 127.0.0.1 Server Port: 801 Document Path: / Document Length: 1770 bytes Concurrency Level: 100 Time taken for tests: 1.968 seconds Complete requests: 100000 Failed requests: 0 Keep-Alive requests: 99048 Total transferred: 193295240 bytes HTML transferred: 177000000 bytes Requests per second: 50820.24 [#/sec] (mean) Time per request: 1.968 [ms] (mean) Time per request: 0.020 [ms] (mean, across all concurrent requests) Transfer rate: 95930.76 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.1 0 4 Processing: 0 2 1.3 2 13 Waiting: 0 2 1.3 2 13 Total: 0 2 1.3 2 13 Percentage of the requests served within a certain time (ms) 50% 2 66% 2 75% 3 80% 3 90% 4 95% 4 98% 5 99% 6 100% 13 (longest request)
[apple-ec@centos webman]$ wrk -t20 -c1000 -d30s http://127.0.0.1:801/ Running 30s test @ http://127.0.0.1:801/ 20 threads and 1000 connections Thread Stats Avg Stdev Max +/- Stdev Latency 14.03ms 9.28ms 147.26ms 66.22% Req/Sec 3.72k 702.15 8.08k 71.14% 2228639 requests in 30.09s, 4.01GB read Requests/sec: 74059.91 Transfer/sec: 136.52MB
外部访问:
当upstream 配置 keepalive 10240 时:
ab: Requests per second: 64062.28 [#/sec] (mean)
wrk: Requests/sec: 33219.76
╰─ ➜ data ab -c100 -n100000 -k http://centos.orb.local:801/ This is ApacheBench, Version 2.3 <$Revision: 1903618 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking centos.orb.local (be patient) Completed 10000 requests Completed 20000 requests Completed 30000 requests Completed 40000 requests Completed 50000 requests Completed 60000 requests Completed 70000 requests Completed 80000 requests Completed 90000 requests Completed 100000 requests Finished 100000 requests Server Software: nginx/1.14.1 Server Hostname: centos.orb.local Server Port: 801 Document Path: / Document Length: 1770 bytes Concurrency Level: 100 Time taken for tests: 1.561 seconds Complete requests: 100000 Failed requests: 0 Keep-Alive requests: 99063 Total transferred: 193295315 bytes HTML transferred: 177000000 bytes Requests per second: 64062.28 [#/sec] (mean) Time per request: 1.561 [ms] (mean) Time per request: 0.016 [ms] (mean, across all concurrent requests) Transfer rate: 120927.13 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.5 0 71 Processing: 0 2 2.4 1 82 Waiting: 0 2 2.4 1 82 Total: 0 2 2.5 1 83 Percentage of the requests served within a certain time (ms) 50% 1 66% 1 75% 2 80% 2 90% 2 95% 2 98% 3 99% 6 100% 83 (longest request)
╰─ ➜ data wrk -t12 -c1000 -d30s http://centos.orb.local:801 Running 30s test @ http://centos.orb.local:801 12 threads and 1000 connections Thread Stats Avg Stdev Max +/- Stdev Latency 2.52ms 2.71ms 192.00ms 98.03% Req/Sec 5.83k 2.38k 12.61k 70.47% 1000075 requests in 30.10s, 1.80GB read Socket errors: connect 758, read 0, write 0, timeout 0 Requests/sec: 33219.76 Transfer/sec: 61.24MB
当upstream 去除 keepalive 10240 时:
ab: Requests per second: 31519.29 [#/sec] (mean)
wrk: Requests/sec: 33246.48
╰─ ➜ data ab -c100 -n100000 -k http://centos.orb.local:801/ This is ApacheBench, Version 2.3 <$Revision: 1903618 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking centos.orb.local (be patient) Completed 10000 requests Completed 20000 requests Completed 30000 requests Completed 40000 requests Completed 50000 requests Completed 60000 requests Completed 70000 requests Completed 80000 requests Completed 90000 requests Completed 100000 requests Finished 100000 requests Server Software: nginx/1.14.1 Server Hostname: centos.orb.local Server Port: 801 Document Path: / Document Length: 1770 bytes Concurrency Level: 100 Time taken for tests: 3.173 seconds Complete requests: 100000 Failed requests: 0 Keep-Alive requests: 99049 Total transferred: 193295245 bytes HTML transferred: 177000000 bytes Requests per second: 31519.29 [#/sec] (mean) Time per request: 3.173 [ms] (mean) Time per request: 0.032 [ms] (mean, across all concurrent requests) Transfer rate: 59497.36 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.1 0 6 Processing: 0 3 2.4 2 43 Waiting: 0 3 2.4 2 43 Total: 0 3 2.4 3 43 Percentage of the requests served within a certain time (ms) 50% 3 66% 3 75% 4 80% 4 90% 6 95% 8 98% 10 99% 12 100% 43 (longest request)
╰─ ➜ data wrk -t12 -c1000 -d30s http://centos.orb.local:801 Running 30s test @ http://centos.orb.local:801 12 threads and 1000 connections Thread Stats Avg Stdev Max +/- Stdev Latency 6.19ms 6.30ms 1.06s 91.23% Req/Sec 3.20k 1.22k 6.17k 61.87% 1000000 requests in 30.08s, 1.80GB read Socket errors: connect 758, read 0, write 0, timeout 0 Requests/sec: 33246.48 Transfer/sec: 61.29MB
nginx + php-fpm: Requests/sec: 20535.69
╰─ ➜ data wrk -t12 -c1000 -d30s http://xxx.com/test.php Running 30s test @ http://xxx.com/test.php 12 threads and 1000 connections Thread Stats Avg Stdev Max +/- Stdev Latency 11.62ms 3.44ms 43.59ms 73.09% Req/Sec 1.72k 723.25 3.27k 59.64% 617088 requests in 30.05s, 206.56MB read Socket errors: connect 757, read 103, write 0, timeout 0 Requests/sec: 20535.69 Transfer/sec: 6.87MB
nginx + php-fpm + yii2: Requests/sec: 433.89
╰─ ➜ data wrk -t12 -c1000 -d30s http://xxx.com/docs/ Running 30s test @ http://xxx.com/docs/ 12 threads and 1000 connections Thread Stats Avg Stdev Max +/- Stdev Latency 511.23ms 103.30ms 880.40ms 69.09% Req/Sec 37.24 24.08 148.00 69.28% 13062 requests in 30.10s, 7.26MB read Socket errors: connect 757, read 103, write 0, timeout 33 Non-2xx or 3xx responses: 42 Requests/sec: 433.89 Transfer/sec: 246.92KB