简体   繁体   English

使用 apache 基准测试 PM2 nodeJS 集群模式测试

[英]PM2 nodeJS cluster mode testing with apache benchmark

I've set up one nodeJS application which only has one route '/' and I'm using Nginx as a reverse proxy.我已经设置了一个只有一个路由“/”的 nodeJS 应用程序,并且我使用 Nginx 作为反向代理。 So app flow is like below:所以应用流程如下:

  • The user sends the request to the Nginx server.用户将请求发送到 Nginx 服务器。
  • And as per the location '/' Nginx server passes the request to the node server.并且根据位置'/' Nginx 服务器将请求传递给节点服务器。

From the nodeJS, '/' route sends one HTML file as a response to the client.在 nodeJS 中,'/' 路由发送一个 HTML 文件作为对客户端的响应。 For load testing, I've used the apache benchmark.对于负载测试,我使用了 apache 基准测试。

Apache benchmark command used for testing:用于测试的 Apache 基准命令:

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

Please check the apache benchmark response in the following two cases:请在以下两种情况下检查 apache 基准测试响应:

Case 1: When clustering mode is not on.情况 1:未开启聚类模式时。 (Without pm2, simple nodeJS server without clustering ex: node index.js) (没有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)

Case 2: When PM2 clustering mode in ON.(pm2 start index.js -i 4 (4 cluster))案例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)

Now, if you compare the request per second time in both the scenarios, you will see that Requests per second (1049.26 [#/sec] (mean)) when no cluster mode is used higher than the pm2 cluster mode (708.79 [#/sec] (mean)) .现在,如果您比较这两种情况下的每秒请求数,您会看到当没有使用集群模式时每秒请求数 (1049.26 [#/sec] (mean)) 高于 pm2 集群模式 (708.79 [#/秒](平均)) I don't understand why it so?我不明白为什么会这样? As far as I know, clustering mode is used to achieve a higher level of concurrency but why there is conflict in the result?据我所知,集群模式是为了实现更高级别的并发,但为什么结果会出现冲突?

I tried clustering with different parameters:我尝试使用不同的参数进行聚类:

  • no process没有过程

  • calculation计算

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

  • concurrent request count并发请求数

Here is the git repo这是git 仓库

Here is my conclusion:这是我的结论:

  • for serving files, it does not make sense to cluster.对于服务文件,集群没有意义。 I think the network is the bottle neck here, and clustering does not help.我认为网络是这里的瓶颈,聚类无济于事。
  • for calculation it does make sense to cluster, cause it keeps the event loop busy, and if you cluster, you have multiple event loops to be kept busy.对于计算,集群确实有意义,因为它使事件循环保持忙碌,如果您进行集群,则有多个事件循环要保持忙碌。 While testing with calculation, I checked the server cores processes by htop and I considered that the same amount of the clusters I had CPU's 100 percent busy.在进行计算测试时,我通过htop检查了服务器核心进程,我认为与 CPU 100% 忙碌的集群数量相同。 The performance multiplied by the cluster count, for example if I made 6 node cluster, the performance became 6 times more.性能乘以集群数,比如我做了6个节点的集群,性能变成了6倍。
  • it does not make sense to cluster more than CPU cores you have on the machine.集群超过机器上的 CPU 内核是没有意义的。 I recommend to reserve one core for the OS.我建议为操作系统保留一个核心。

I made a repository and in the readme file I wrote the detailed results.我创建了一个存储库,并在自述文件中写下了详细的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM