一、环境介绍
- linux centos7
- php7.1.18
- go1.12.1
- 2核4G内存
二、代码
- swoole代码
on("start", function ($server) { echo "Swoole http server is started at http://127.0.0.1:9501\n";});$http->on("request", function ($request, $response) { $response->header("Content-Type", "text/html"); $response->end("Hello World\n");});$http->start();
- golang 代码
package mainimport ( "io" "net/http")func main() { http.ListenAndServe("0.0.0.0:9502", http.HandlerFunc(handle))}func handle(rw http.ResponseWriter, r *http.Request) { rw.Header().Set("Content-Type", "text/html") io.WriteString(rw, "Hello World\n")}
三、开始测试
3.1 ab -n 100 -c 10
swoole
Document Path: /Document Length: 12 bytesConcurrency Level: 10Time taken for tests: 0.014 secondsComplete requests: 100Failed requests: 0Write errors: 0Total transferred: 16000 bytesHTML transferred: 1200 bytesRequests per second: 6957.01 [#/sec] (mean)Time per request: 1.437 [ms] (mean)Time per request: 0.144 [ms] (mean, across all concurrent requests)Transfer rate: 1087.03 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 0 0.1 0 1Processing: 0 1 0.3 1 2Waiting: 0 1 0.2 1 1Total: 1 1 0.3 1 2Percentage of the requests served within a certain time (ms) 50% 1 66% 1 75% 1 80% 2 90% 2 95% 2 98% 2 99% 2 100% 2 (longest request)
golang
Server Software:Server Hostname: 127.0.0.1Server Port: 9502Document Path: /Document Length: 12 bytesConcurrency Level: 10Time taken for tests: 0.021 secondsComplete requests: 100Failed requests: 0Write errors: 0Total transferred: 11300 bytesHTML transferred: 1200 bytesRequests per second: 4760.54 [#/sec] (mean)Time per request: 2.101 [ms] (mean)Time per request: 0.210 [ms] (mean, across all concurrent requests)Transfer rate: 525.33 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 0 0.2 0 1Processing: 0 1 0.8 1 8Waiting: 0 1 0.7 1 7Total: 0 1 0.8 1 8Percentage of the requests served within a certain time (ms) 50% 1 66% 2 75% 2 80% 2 90% 2 95% 2 98% 2 99% 8 100% 8 (longest request)
3.2 ab -n 1000 -c 100
swoole
Server Software: swoole-http-serverServer Hostname: 127.0.0.1Server Port: 9501Document Path: /Document Length: 12 bytesConcurrency Level: 100Time taken for tests: 0.094 secondsComplete requests: 1000Failed requests: 0Write errors: 0Total transferred: 160000 bytesHTML transferred: 12000 bytesRequests per second: 10680.68 [#/sec] (mean)Time per request: 9.363 [ms] (mean)Time per request: 0.094 [ms] (mean, across all concurrent requests)Transfer rate: 1668.86 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 2 1.2 2 6Processing: 2 7 3.0 6 14Waiting: 0 6 2.5 5 13Total: 4 9 2.9 8 18Percentage of the requests served within a certain time (ms) 50% 8 66% 9 75% 10 80% 11 90% 13 95% 14 98% 17 99% 17 100% 18 (longest request)
golang
Server Software:Server Hostname: 127.0.0.1Server Port: 9502Document Path: /Document Length: 12 bytesConcurrency Level: 100Time taken for tests: 0.107 secondsComplete requests: 1000Failed requests: 0Write errors: 0Total transferred: 113000 bytesHTML transferred: 12000 bytesRequests per second: 9331.75 [#/sec] (mean)Time per request: 10.716 [ms] (mean)Time per request: 0.107 [ms] (mean, across all concurrent requests)Transfer rate: 1029.77 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 1 1.4 1 6Processing: 1 9 5.3 8 35Waiting: 0 8 5.0 7 34Total: 1 10 4.9 9 38Percentage of the requests served within a certain time (ms) 50% 9 66% 11 75% 13 80% 14 90% 17 95% 18 98% 20 99% 25 100% 38 (longest request)
3.3 ab -n 10000 -c 1000
swoole
Server Software: swoole-http-serverServer Hostname: 127.0.0.1Server Port: 9501Document Path: /Document Length: 12 bytesConcurrency Level: 1000Time taken for tests: 0.868 secondsComplete requests: 10000Failed requests: 0Write errors: 0Total transferred: 1600000 bytesHTML transferred: 120000 bytesRequests per second: 11515.25 [#/sec] (mean)Time per request: 86.841 [ms] (mean)Time per request: 0.087 [ms] (mean, across all concurrent requests)Transfer rate: 1799.26 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 4 4.7 3 30Processing: 3 11 5.0 10 216Waiting: 0 9 4.7 9 214Total: 6 15 7.1 14 239Percentage of the requests served within a certain time (ms) 50% 14 66% 15 75% 16 80% 17 90% 20 95% 26 98% 41 99% 42 100% 239 (longest request)
golang
Document Path: /Document Length: 12 bytesConcurrency Level: 1000Time taken for tests: 1.018 secondsComplete requests: 10000Failed requests: 0Write errors: 0Total transferred: 1130000 bytesHTML transferred: 120000 bytesRequests per second: 9823.25 [#/sec] (mean)Time per request: 101.799 [ms] (mean)Time per request: 0.102 [ms] (mean, across all concurrent requests)Transfer rate: 1084.01 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 5 6.6 3 37Processing: 0 13 9.3 12 209Waiting: 0 11 8.2 10 205Total: 0 18 13.5 15 210Percentage of the requests served within a certain time (ms) 50% 15 66% 17 75% 19 80% 21 90% 33 95% 45 98% 66 99% 77 100% 210 (longest request)
3.4 ab -n 100000 -c 10000
swoole
Server Software: swoole-http-serverServer Hostname: 127.0.0.1Server Port: 9501Document Path: /Document Length: 12 bytesConcurrency Level: 10000Time taken for tests: 9.582 secondsComplete requests: 100000Failed requests: 0Write errors: 0Total transferred: 16000000 bytesHTML transferred: 1200000 bytesRequests per second: 10436.61 [#/sec] (mean)Time per request: 958.166 [ms] (mean)Time per request: 0.096 [ms] (mean, across all concurrent requests)Transfer rate: 1630.72 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 487 535.1 297 7133Processing: 62 374 115.8 388 832Waiting: 0 286 96.7 273 704Total: 161 861 549.7 696 7350Percentage of the requests served within a certain time (ms) 50% 696 66% 826 75% 912 80% 1225 90% 1607 95% 1739 98% 2005 99% 3442 100% 7350 (longest request)
golang
Document Path: /Document Length: 12 bytesConcurrency Level: 10000Time taken for tests: 16.700 secondsComplete requests: 100000Failed requests: 0Write errors: 0Total transferred: 11300000 bytesHTML transferred: 1200000 bytesRequests per second: 5987.91 [#/sec] (mean)Time per request: 1670.033 [ms] (mean)Time per request: 0.167 [ms] (mean, across all concurrent requests)Transfer rate: 660.77 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 709 1278.7 20 7048Processing: 0 72 324.6 34 13554Waiting: 0 66 324.3 27 13553Total: 1 781 1357.7 64 16588Percentage of the requests served within a certain time (ms) 50% 64 66% 1029 75% 1047 80% 1061 90% 3041 95% 3091 98% 7041 99% 7083 100% 16588 (longest request)
3.5 ab -n 200000 -c 20000
swoole
Server Software: swoole-http-serverServer Hostname: 127.0.0.1Server Port: 9501Document Path: /Document Length: 12 bytesConcurrency Level: 20000Time taken for tests: 20.057 secondsComplete requests: 200000Failed requests: 0Write errors: 0Total transferred: 32000000 bytesHTML transferred: 2400000 bytesRequests per second: 9971.56 [#/sec] (mean)Time per request: 2005.704 [ms] (mean)Time per request: 0.100 [ms] (mean, across all concurrent requests)Transfer rate: 1558.06 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 913 689.1 696 15748Processing: 324 966 229.3 959 1970Waiting: 0 736 189.6 743 1556Total: 909 1879 716.9 1659 16114Percentage of the requests served within a certain time (ms) 50% 1659 66% 1842 75% 2129 80% 2427 90% 2605 95% 2744 98% 4279 99% 4522 100% 16114 (longest request)
golang
Server Software:Server Hostname: 127.0.0.1Server Port: 9502Document Path: /Document Length: 12 bytesConcurrency Level: 20000Time taken for tests: 34.083 secondsComplete requests: 200000Failed requests: 0Write errors: 0Total transferred: 22600000 bytesHTML transferred: 2400000 bytesRequests per second: 5868.07 [#/sec] (mean)Time per request: 3408.274 [ms] (mean)Time per request: 0.170 [ms] (mean, across all concurrent requests)Transfer rate: 647.55 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 1328 2378.8 466 15093Processing: 0 171 1106.5 44 26576Waiting: 0 163 1106.7 37 26573Total: 0 1499 2775.8 709 33626Percentage of the requests served within a certain time (ms) 50% 709 66% 1069 75% 1190 80% 3031 90% 3209 95% 7080 98% 8709 99% 15161 100% 33626 (longest request)
3.6 ab -n 300000 -c 20000
swoole
Server Software: swoole-http-serverServer Hostname: 127.0.0.1Server Port: 9501Document Path: /Document Length: 12 bytesConcurrency Level: 20000Time taken for tests: 29.131 secondsComplete requests: 300000Failed requests: 0Write errors: 0Total transferred: 48000000 bytesHTML transferred: 3600000 bytesRequests per second: 10298.19 [#/sec] (mean)Time per request: 1942.089 [ms] (mean)Time per request: 0.097 [ms] (mean, across all concurrent requests)Transfer rate: 1609.09 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 944 887.3 691 15919Processing: 294 938 220.0 923 2056Waiting: 0 743 203.4 717 1877Total: 725 1882 922.0 1665 16908Percentage of the requests served within a certain time (ms) 50% 1665 66% 1843 75% 2125 80% 2263 90% 2641 95% 2994 98% 4552 99% 4814 100% 16908 (longest request)
golang
已无法承受压力
3.7 ab -n 400000 -c 20000
swoole
Server Software: swoole-http-serverServer Hostname: 127.0.0.1Server Port: 9501Document Path: /Document Length: 12 bytesConcurrency Level: 20000Time taken for tests: 39.223 secondsComplete requests: 400000Failed requests: 0Write errors: 0Total transferred: 64000000 bytesHTML transferred: 4800000 bytesRequests per second: 10197.99 [#/sec] (mean)Time per request: 1961.170 [ms] (mean)Time per request: 0.098 [ms] (mean, across all concurrent requests)Transfer rate: 1593.44 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 930 717.2 722 15587Processing: 360 975 198.0 962 2555Waiting: 0 738 168.0 739 2344Total: 740 1905 740.7 1732 16800Percentage of the requests served within a certain time (ms) 50% 1732 66% 1894 75% 2015 80% 2263 90% 2623 95% 2836 98% 4397 99% 4623 100% 16800 (longest request)
golang
已无法承受压力