iT邦幫忙

DAY 31
10

node.js伺服器實戰系列 第 31

node.js伺服器實戰(31) - 結語

  • 分享至 

  • xImage
  •  

其實還很多工作沒完成,不過還是撐過三十天了XD
效能驗收

最後一天,來測試看看之前搞的架構,對於效能是否有很大影響。

如果同樣是跑出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

兩個的效能就差不多了XD

到了負載高的時候,兩個的表現就會有差距:

在我的機器上,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

經過了三十天,多少還是有一些收穫的哈哈

相關文章


上一篇
node.js伺服器實戰(30) - scaling node.js
下一篇
node.js伺服器實戰(-1) - 賽後亂搞dnode
系列文
node.js伺服器實戰33
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
0
賽門
iT邦超人 1 級 ‧ 2011-11-10 23:31:04

工作沒做完, 怎麼能收工??繼續PO到明年鐵人賽...

fillano iT邦超人 1 級 ‧ 2011-11-10 23:42:52 檢舉

明年就不知道了XD,去年寫完html5,就剛好碰上node.js...

fillano提到:
去年寫完html5,就剛好碰上node.js

我的第一個想法也是如此
明年
不知道又有什麼更好用、更快速的什麼什麼技術
落寞

總裁 iT邦好手 1 級 ‧ 2011-11-11 09:55:25 檢舉

iT邦幫忙MVPsimon581923提到:
工作沒做完, 怎麼能收工??繼續PO到明年鐵人賽...

賽大,別忘了您的人生也還在繼續呀!!!

0
wordsmith
iT邦高手 1 級 ‧ 2011-11-11 01:29:10

費大公超強,收獲很多~

總裁 iT邦好手 1 級 ‧ 2011-11-11 09:57:08 檢舉

沒錯,沒錯,看來外盤買費公的人都沒買錯哈哈

0
diaplo432
iT邦新手 5 級 ‧ 2012-04-22 03:08:40

請教費大是用什麼方式來測試伺服器的?
新手一枚發問@@

fillano iT邦超人 1 級 ‧ 2012-04-22 15:18:45 檢舉

主要是用node_unit做單元測試,用client_request做整合測試,用jscoverage做測試覆蓋率檢測,用ant驅動。

我想你要問的是已經上線的伺服器?簡單的測試可以直接用client_request來做。但是要做比較複雜的整合測試,用selenium可能比較方便。

diaplo432 iT邦新手 5 級 ‧ 2012-04-24 12:33:47 檢舉

fillano提到:
selenium

感謝QAQ

我要留言

立即登入留言