js出了個nodejs,我們技術老大前段時間發了個技術郵件說php支援多線程,非同步,非阻塞 還打著旗號說要滅掉nodejs,官方網站上說swoole的效能已經最少也和nodejs可以媲美了,這個需要用資料說話,周末的時候有空就順手測試了一下這兩個東東!下面是測試報告哈。
首先我用127.0.0.1:8000連接埠測試swoole, 用127.0.0.1:1337測試nodejs
有圖有真相:(稍後傳,不會用mac把截圖儲存!汗!各位看客有誰會的教教我哈!編程都變傻了)
測試環境:
處理器:2.7GHz i7
記憶體:16GB 1600hz DDR3
系統 MAC OS X
先放測試結果:
1.PHPswoole的測試結果:
~mysql? ab -n 5000 -c 100 http://127.0.0.1:8000/This is ApacheBench, Version 2.3 <$Revision: 655654 $>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 500 requestsCompleted 1000 requestsCompleted 1500 requestsCompleted 2000 requestsCompleted 2500 requestsCompleted 3000 requestsCompleted 3500 requestsCompleted 4000 requestsCompleted 4500 requestsCompleted 5000 requestsFinished 5000 requestsServer Software: Server Hostname: 127.0.0.1Server Port: 8000Document Path: /Document Length: 0 bytesConcurrency Level: 100Time taken for tests: 1.411 secondsComplete requests: 5000Failed requests: 0Write errors: 0Total transferred: 55330 bytesHTML transferred: 0 bytesRequests per second: 3543.00 [#/sec] (mean)Time per request: 28.225 [ms] (mean)Time per request: 0.282 [ms] (mean, across all concurrent requests)Transfer rate: 38.29 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 3 1.2 3 7Processing: 17 25 16.7 23 143Waiting: 1 9 12.9 7 136Total: 20 28 16.6 26 143Percentage of the requests served within a certain time (ms) 50% 26 66% 27 75% 27 80% 27 90% 28 95% 29 98% 141 99% 142 100% 143 (longest request)
2.nodejs的測試結果:
~mysql? ab -n 5000 -c 100 http://127.0.0.1:1337/This is ApacheBench, Version 2.3 <$Revision: 655654 $>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 500 requestsCompleted 1000 requestsCompleted 1500 requestsCompleted 2000 requestsCompleted 2500 requestsCompleted 3000 requestsCompleted 3500 requestsCompleted 4000 requestsCompleted 4500 requestsCompleted 5000 requestsFinished 5000 requestsServer Software: Server Hostname: 127.0.0.1Server Port: 1337Document Path: /Document Length: 12 bytesConcurrency Level: 100Time taken for tests: 1.215 secondsComplete requests: 5000Failed requests: 0Write errors: 0Total transferred: 565000 bytesHTML transferred: 60000 bytesRequests per second: 4116.49 [#/sec] (mean)Time per request: 24.293 [ms] (mean)Time per request: 0.243 [ms] (mean, across all concurrent requests)Transfer rate: 454.26 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 0 0.6 0 5Processing: 2 24 21.0 21 175Waiting: 2 24 20.8 21 174Total: 6 24 20.9 21 175Percentage of the requests served within a certain time (ms) 50% 21 66% 22 75% 23 80% 24 90% 26 95% 32 98% 159 99% 170 100% 175 (longest request)
上面的ab測試中:每秒100的並發量共向介面請求5000次。
PHP和nodejs成績都還不錯,關鍵是Swoole的環境我用了--debug導致有很多命令會輸出,暫時有不會改回去,(稍後在公司測試環境重新測試下)
Time taken for tests: 1.411 seconds共耗時
Requests per second: 3543.00 [#/sec] (mean)
nodeJS
Time taken for tests: 1.215 seconds共耗時
Requests per second: 4116.49 [#/sec] (mean)
從測試結果來看,雖然swoole的測試資料稍微遜色了一點,但是這並不影響我對swoole的看法(況且配置可能不是很好),我覺的對於一個C語言編寫的PHP,這個已經比我們目前的環境要好的多了。