其實還很多工作沒完成,不過還是撐過三十天了
效能驗收
最後一天,來測試看看之前搞的架構,對於效能是否有很大影響。
如果同樣是跑出hello world,evolve的效能與最簡單的hello world範例差距不大:
簡單hello world:
Server Software:
Server Hostname: localhost
Server Port: 8443
Document Path: /hello
Document Length: 31 bytes
Concurrency Level: 100
Time taken for tests: 5.245300 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 940000 bytes
HTML transferred: 310000 bytes
Requests per second: 1906.47 [#/sec] (mean)
Time per request: 52.453 [ms] (mean)
Time per request: 0.525 [ms] (mean, across all concurrent requests)
Transfer rate: 174.82 [Kbytes/sec] received
evolve跑hello world,開八個instance:
Server Software:
Server Hostname: localhost
Server Port: 8443
Document Path: /hello
Document Length: 31 bytes
Concurrency Level: 100
Time taken for tests: 5.264301 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 1140000 bytes
HTML transferred: 310000 bytes
Requests per second: 1899.59 [#/sec] (mean)
Time per request: 52.643 [ms] (mean)
Time per request: 0.526 [ms] (mean, across all concurrent requests)
Transfer rate: 211.42 [Kbytes/sec] received
evolve跑hello world,只開一個instance:
Server Software:
Server Hostname: localhost
Server Port: 8443
Document Path: /hello
Document Length: 31 bytes
Concurrency Level: 100
Time taken for tests: 5.918338 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 1140000 bytes
HTML transferred: 310000 bytes
Requests per second: 1689.66 [#/sec] (mean)
Time per request: 59.183 [ms] (mean)
Time per request: 0.592 [ms] (mean, across all concurrent requests)
Transfer rate: 188.06 [Kbytes/sec] received
ab在我的windows上跑,極限大概是1024個concurrent,不過速度會略為降低。
所以雖然看起來架構稍微複雜,在最簡單的例子中,效能還能大致維持。另外,效能會隨著response的大小成反比,例如access一個gif檔:
使用node.js:
Server Software:
Server Hostname: localhost
Server Port: 8443
Document Path: /bg.gif
Document Length: 81563 bytes
Concurrency Level: 100
Time taken for tests: 15.24859 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 816490000 bytes
HTML transferred: 815630000 bytes
Requests per second: 665.56 [#/sec] (mean)
Time per request: 150.249 [ms] (mean)
Time per request: 1.502 [ms] (mean, across all concurrent requests)
Transfer rate: 53068.92 [Kbytes/sec] received
透過apache httpd:
Server Software: Apache/2.2.8
Server Hostname: localhost
Server Port: 80
Document Path: /bg/bg.gif
Document Length: 81563 bytes
Concurrency Level: 100
Time taken for tests: 15.310876 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 818370000 bytes
HTML transferred: 815630000 bytes
Requests per second: 653.13 [#/sec] (mean)
Time per request: 153.109 [ms] (mean)
Time per request: 1.531 [ms] (mean, across all concurrent requests)
Transfer rate: 52197.47 [Kbytes/sec] received
兩個的效能就差不多了
到了負載高的時候,兩個的表現就會有差距:
在我的機器上,apache+php只能跑到264個concurrent:
Server Software: Apache/2.2.8
Server Hostname: localhost
Server Port: 80
Document Path: /hello.php
Document Length: 31 bytes
Concurrency Level: 264
Time taken for tests: 5.739328 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 2160000 bytes
HTML transferred: 310000 bytes
Requests per second: 1742.36 [#/sec] (mean)
Time per request: 151.518 [ms] (mean)
Time per request: 0.574 [ms] (mean, across all concurrent requests)
Transfer rate: 367.46 [Kbytes/sec] received
但是node.js可以輕易到1000個concurrent:
Server Software:
Server Hostname: localhost
Server Port: 8443
Document Path: /hello
Document Length: 31 bytes
Concurrency Level: 1000
Time taken for tests: 8.254472 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 1140000 bytes
HTML transferred: 310000 bytes
Requests per second: 1211.46 [#/sec] (mean)
Time per request: 825.447 [ms] (mean)
Time per request: 0.825 [ms] (mean, across all concurrent requests)
Transfer rate: 134.84 [Kbytes/sec] received
如果開啟cluster,用八個instance來跑:
Server Software:
Server Hostname: localhost
Server Port: 8443
Document Path: /hello
Document Length: 31 bytes
Concurrency Level: 1000
Time taken for tests: 5.713326 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 1140000 bytes
HTML transferred: 310000 bytes
Requests per second: 1750.29 [#/sec] (mean)
Time per request: 571.333 [ms] (mean)
Time per request: 0.571 [ms] (mean, across all concurrent requests)
Transfer rate: 194.81 [Kbytes/sec] received
會發現速度衰退不大,但是如果是apache就完全動不了,這就是node.js的威力。
未完成的工作
不過未完成的工作其實還有一大堆,舉例:
* 很多單元測試還沒寫,都是靠整合測試在撐
* 更完整的http支援
* 比較好的擴充方式
* 缺點不勝枚舉
當然,還是有一些收穫,也激發了一些想要進一步發展的創意:
* cluster控制(本來今天試寫了一個pool,但是發現在node.js內部有點難統計出concurrent,這是Javascript的先天問題,所以先放棄。當然做一些worker的統計是沒問題的)
* 模板引擎parser
經過了三十天,多少還是有一些收穫的。
工作沒做完, 怎麼能收工??繼續PO到明年鐵人賽...
明年就不知道了,去年寫完html5,就剛好碰上node.js...
fillano提到:
去年寫完html5,就剛好碰上node.js
我的第一個想法也是如此
明年
不知道又有什麼更好用、更快速的什麼什麼技術
iT邦幫忙MVPsimon581923提到:
工作沒做完, 怎麼能收工??繼續PO到明年鐵人賽...
賽大,別忘了您的人生也還在繼續呀!!!
請教費大是用什麼方式來測試伺服器的?
新手一枚發問@@
主要是用node_unit做單元測試,用client_request做整合測試,用jscoverage做測試覆蓋率檢測,用ant驅動。
我想你要問的是已經上線的伺服器?簡單的測試可以直接用client_request來做。但是要做比較複雜的整合測試,用selenium可能比較方便。
fillano提到:
selenium
感謝QAQ