簡體   English   中英

使用 apache 基准測試 PM2 nodeJS 集群模式測試

[英]PM2 nodeJS cluster mode testing with apache benchmark

我已經設置了一個只有一個路由“/”的 nodeJS 應用程序,並且我使用 Nginx 作為反向代理。 所以應用流程如下:

  • 用戶將請求發送到 Nginx 服務器。
  • 並且根據位置'/' Nginx 服務器將請求傳遞給節點服務器。

在 nodeJS 中,'/' 路由發送一個 HTML 文件作為對客戶端的響應。 對於負載測試,我使用了 apache 基准測試。

用於測試的 Apache 基准命令:

ab -k -c 250 -n 10000 http://localhost/

請在以下兩種情況下檢查 apache 基准測試響應:

情況 1:未開啟聚類模式時。 (沒有pm2,沒有集群的簡單nodeJS服務器,例如:node index.js)

rails@rails-laptop:~$ ab -k -c 250 -n 10000 http://localhost/
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        nginx/1.10.3
Server Hostname:        localhost
Server Port:            80

Document Path:          /
Document Length:        134707 bytes

Concurrency Level:      250
Time taken for tests:   9.531 seconds
Complete requests:      10000
Failed requests:        0
Keep-Alive requests:    10000
Total transferred:      1350590000 bytes
HTML transferred:       1347070000 bytes
Requests per second:    1049.26 [#/sec] (mean)
Time per request:       238.264 [ms] (mean)
Time per request:       0.953 [ms] (mean, across all concurrent requests)
Transfer rate:          138390.37 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.8      0       6
Processing:    38  237  77.6    213     626
Waiting:       31  230  73.8    209     569
Total:         44  237  77.5    213     626

Percentage of the requests served within a certain time (ms)
  50%    213
  66%    229
  75%    247
  80%    280
  90%    373
  95%    395
  98%    438
  99%    538
 100%    626 (longest request)

案例2:當PM2集群模式為ON時。(pm2 start index.js -i 4 (4 cluster))

rails@rails-laptop:~$ ab -k -c 250 -n 10000 http://localhost/
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        nginx/1.10.3
Server Hostname:        localhost
Server Port:            80

Document Path:          /
Document Length:        134707 bytes

Concurrency Level:      1
Time taken for tests:   14.109 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      1350540000 bytes
HTML transferred:       1347070000 bytes
Requests per second:    708.79 [#/sec] (mean)
Time per request:       1.411 [ms] (mean)
Time per request:       1.411 [ms] (mean, across all concurrent requests)
Transfer rate:          93481.05 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       9
Processing:     1    1   1.2      1      35
Waiting:        0    1   0.9      1      21
Total:          1    1   1.2      1      35

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      2
  95%      3
  98%      5
  99%      6
 100%     35 (longest request)

現在,如果您比較這兩種情況下的每秒請求數,您會看到當沒有使用集群模式時每秒請求數 (1049.26 [#/sec] (mean)) 高於 pm2 集群模式 (708.79 [#/秒](平均)) 我不明白為什么會這樣? 據我所知,集群模式是為了實現更高級別的並發,但為什么結果會出現沖突?

我嘗試使用不同的參數進行聚類:

  • 沒有過程

  • 計算

    for(let i = 1; i <= 50000000; i++){ r += i; }
  • 發送文件

  • 並發請求數

這是git 倉庫

這是我的結論:

  • 對於服務文件,集群沒有意義。 我認為網絡是這里的瓶頸,聚類無濟於事。
  • 對於計算,集群確實有意義,因為它使事件循環保持忙碌,如果您進行集群,則有多個事件循環要保持忙碌。 在進行計算測試時,我通過htop檢查了服務器核心進程,我認為與 CPU 100% 忙碌的集群數量相同。 性能乘以集群數,比如我做了6個節點的集群,性能變成了6倍。
  • 集群超過機器上的 CPU 內核是沒有意義的。 我建議為操作系統保留一個核心。

我創建了一個存儲庫,並在自述文件中寫下了詳細的結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM