一、测试架构图

image.png

二、主机状态参数

image.png

---主机资源配置均为 2核8G
---系统参数优化:

#查看系统允许打开的最大连接数
    cat /proc/sys/net/core/somaxconn
    echo 50000 > /proc/sys/net/core/somaxconn
#打开系统快速连接回收
    cat /proc/sys/net/ipv4/tcp_tw_recycle
    echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
#打开空的tcp连接允许回收利用
    cat /proc/sys/net/ipv4/tcp_tw_reuse
    echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse
#不做洪水抵御
    cat /proc/sys/net/ipv4/tcp_syncookies
    echo 0 > /proc/sys/net/ipv4/tcp_syncookies

---编辑配置文件: vim /etc/security/limits.conf

# End of file
root soft nofile 65535
root hard nofile 65535
* soft nofile 100000  #可打开的文件句柄的最大数
* hard nofile 100000  #soft:软限制、hard:硬限制
* soft nproc 40960     #单个用户可用的最大进程数量
* hard nproc 40960
* soft memlock unlimited   #可打开的文件描述符的最大数
* hard memlock unlimited   #unlimited:无限制

三、测试工具

工具采用了 apache自带压力测试工具 --- ab
利用ab发送post请求,请求经过 haproxy ---> nginx ---> java ---> mysql 最终写入到数据库表中,模拟了客户端提交数据的场景;

因为客户端就是给java发送的post请求,提交数据,所以也以此为场景进行压力测试

四、测试过程

1、模拟1000并发,2000的请求总量

(即1000客户端同时发送请求,每个客户端发送2条请求。)

[root@skip file_xpt]# ab -n 2000 -c 1000 -p 'post.txt' -T 'application/x-www-form-urlencoded' -r http://172.19.195.225/api/testResult/save.json/
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
 
Benchmarking 172.19.195.225 (be patient)
Completed 200 requests
Completed 400 requests
Completed 600 requests
Completed 800 requests
Completed 1000 requests
Completed 1200 requests
Completed 1400 requests
Completed 1600 requests
Completed 1800 requests
Completed 2000 requests
Finished 2000 requests
 
 
Server Software:        openresty/1.15.8.3
Server Hostname:        172.19.195.225
Server Port:            80
 
Document Path:          /api/testResult/save.json/
Document Length:        1 bytes
 
Concurrency Level:      1000
Time taken for tests:   5.909 seconds
Complete requests:      2000
Failed requests:        0
Total transferred:      480000 bytes
Total body sent:        502000
HTML transferred:       2000 bytes
Requests per second:    338.44 [#/sec] (mean)
Time per request:       2954.737 [ms] (mean)
Time per request:       2.955 [ms] (mean, across all concurrent requests)
Transfer rate:          79.32 [Kbytes/sec] received
                        82.96 kb/s sent
                        162.28 kb/s total
 
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    9   9.5      9      27
Processing:    41 2536 1430.7   2316    5817
Waiting:       15 2536 1430.7   2316    5817
Total:         42 2545 1436.0   2327    5842
 
Percentage of the requests served within a certain time (ms)
  50%   2327
  66%   2745
  75%   3443
  80%   3720
  90%   4911
  95%   5284
  98%   5586
  99%   5670
 100%   5842 (longest request)

主机负载:
主机2负载:0.65,cpu使用率97%+
主机3负载:1.55,cpu使用率97%+

重要参数:
吞吐量:338.44 [#/sec] (mean)
所有并发请求的平均处理时间:2.955 [ms]

2、模拟3000并发,6000的请求总量

[root@skip file_xpt]# ab -n 6000 -c 3000 -p 'post.txt' -T 'application/x-www-form-urlencoded' -r http://172.19.195.225/api/testResult/save.json/
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
 
Benchmarking 172.19.195.225 (be patient)
Completed 600 requests
Completed 1200 requests
Completed 1800 requests
Completed 2400 requests
Completed 3000 requests
Completed 3600 requests
Completed 4200 requests
Completed 4800 requests
Completed 5400 requests
Completed 6000 requests
Finished 6000 requests
 
 
Server Software:        openresty/1.15.8.3
Server Hostname:        172.19.195.225
Server Port:            80
 
Document Path:          /api/testResult/save.json/
Document Length:        1 bytes
 
Concurrency Level:      3000
Time taken for tests:   10.660 seconds
Complete requests:      6000
Failed requests:        0
Total transferred:      1440000 bytes
Total body sent:        1506000
HTML transferred:       6000 bytes
Requests per second:    562.87 [#/sec] (mean)
Time per request:       5329.789 [ms] (mean)
Time per request:       1.777 [ms] (mean, across all concurrent requests)
Transfer rate:          131.92 [Kbytes/sec] received
                        137.97 kb/s sent
                        269.89 kb/s total
 
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   26  26.8     28      71
Processing:    90 4431 2096.2   4006   10519
Waiting:       19 4431 2096.2   4006   10519
Total:         90 4457 2103.2   4017   10578
 
Percentage of the requests served within a certain time (ms)
  50%   4017
  66%   4859
  75%   5533
  80%   6083
  90%   7817
  95%   9178
  98%   9874
  99%  10073
 100%  10578 (longest request)

主机负载:
主机2负载:3.49,cpu使用率99.00
主机3负载:12.87,cpu使用率99.00

重要参数:
吞吐量:562.87 [#/sec] (mean)
所有并发请求的平均处理时间:1.777 [ms]

3、模拟6000并发,12000的请求总量

[root@skip file_xpt]# ab -n 12000 -c 6000 -p 'post.txt' -T 'application/x-www-form-urlencoded' -r http://172.19.195.225/api/testResult/save.json/
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
 
Benchmarking 172.19.195.225 (be patient)
Completed 1200 requests
Completed 2400 requests
Completed 3600 requests
Completed 4800 requests
Completed 6000 requests
Completed 7200 requests
Completed 8400 requests
Completed 9600 requests
Completed 10800 requests
Completed 12000 requests
Finished 12000 requests
 
 
Server Software:        openresty/1.15.8.3
Server Hostname:        172.19.195.225
Server Port:            80
 
Document Path:          /api/testResult/save.json/
Document Length:        1 bytes
 
Concurrency Level:      6000
Time taken for tests:   18.985 seconds
Complete requests:      12000
Failed requests:        0
Total transferred:      2880000 bytes
Total body sent:        3012000
HTML transferred:       12000 bytes
Requests per second:    632.09 [#/sec] (mean)
Time per request:       9492.388 [ms] (mean)
Time per request:       1.582 [ms] (mean, across all concurrent requests)
Transfer rate:          148.15 [Kbytes/sec] received
                        154.94 kb/s sent
                        303.08 kb/s total
 
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   59  93.1     71    1003
Processing:   123 7661 2657.9   7260   18674
Waiting:       13 7661 2658.0   7260   18674
Total:        157 7721 2649.2   7305   18798
 
Percentage of the requests served within a certain time (ms)
  50%   7305
  66%   8449
  75%   8988
  80%   9507
  90%  11078
  95%  12607
  98%  14386
  99%  15811
 100%  18798 (longest request)

主机负载:
主机2负载:4.74,cpu使用率97.47
主机3负载:7.13,cpu使用率97.47

重要参数:
吞吐量:632.09 [#/sec] (mean)
所有并发请求的平均处理时间:1.582 [ms]

4、模拟10000并发,20000的请求总量

[root@skip file_xpt]# ab -n 20000 -c 10000 -p 'post.txt' -T 'application/x-www-form-urlencoded' -r http://172.19.195.225/api/testResult/save.json/
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
 
Benchmarking 172.19.195.225 (be patient)
Completed 2000 requests
Completed 4000 requests
Completed 6000 requests
Completed 8000 requests
Completed 10000 requests
Completed 12000 requests
Completed 14000 requests
Completed 16000 requests
Completed 18000 requests
Completed 20000 requests
Finished 20000 requests
 
 
Server Software:        openresty/1.15.8.3
Server Hostname:        172.19.195.225
Server Port:            80
 
Document Path:          /api/testResult/save.json/
Document Length:        1 bytes
 
Concurrency Level:      10000
Time taken for tests:   22.820 seconds
Complete requests:      20000
Failed requests:        6174
   (Connect: 0, Receive: 2058, Length: 2058, Exceptions: 2058)
Total transferred:      4306080 bytes
Total body sent:        5020000
HTML transferred:       17942 bytes
Requests per second:    876.42 [#/sec] (mean)
Time per request:       11410.002 [ms] (mean)
Time per request:       1.141 [ms] (mean, across all concurrent requests)
Transfer rate:          184.28 [Kbytes/sec] received
                        214.83 kb/s sent
                        399.10 kb/s total
 
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  991 2338.2    156   15048
Processing:   228 7240 2895.5   6839   21655
Waiting:        0 5999 2986.3   6055   21655
Total:        228 8231 4105.2   7099   22104
 
Percentage of the requests served within a certain time (ms)
  50%   7099
  66%   8389
  75%   9407
  80%  10342
  90%  15887
  95%  16100
  98%  20104
  99%  21346
 100%  22104 (longest request)

主机负载:
主机2负载:9.10,cpu使用率97.55
主机3负载:9.45,cpu使用率97.55
重要参数:
吞吐量:876.42 [#/sec] (mean)
所有并发请求的平均处理时间:1.141 [ms]
表中的数据量:17942,缺少2058。(应该是20000条数据)

5、模拟8000并发,16000的请求总量

[root@skip file_xpt]# ab -n 16000 -c 8000 -p 'post.txt' -T 'application/x-www-form-urlencoded' -r http://172.19.195.225/api/testResult/save.json/
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
 
Benchmarking 172.19.195.225 (be patient)
Completed 1600 requests
Completed 3200 requests
Completed 4800 requests
Completed 6400 requests
Completed 8000 requests
Completed 9600 requests
Completed 11200 requests
Completed 12800 requests
Completed 14400 requests
Completed 16000 requests
Finished 16000 requests
 
 
Server Software:        openresty/1.15.8.3
Server Hostname:        172.19.195.225
Server Port:            80
 
Document Path:          /api/testResult/save.json/
Document Length:        1 bytes
 
Concurrency Level:      8000
Time taken for tests:   17.704 seconds
Complete requests:      16000
Failed requests:        1737
   (Connect: 0, Receive: 579, Length: 579, Exceptions: 579)
Total transferred:      3701040 bytes
Total body sent:        4016000
HTML transferred:       15421 bytes
Requests per second:    903.76 [#/sec] (mean)
Time per request:       8851.905 [ms] (mean)
Time per request:       1.106 [ms] (mean, across all concurrent requests)
Transfer rate:          204.15 [Kbytes/sec] received
                        221.53 kb/s sent
                        425.68 kb/s total
 
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  572 1458.1    115    7019
Processing:   138 6299 2460.6   6188   17245
Waiting:        0 5825 2366.0   5880   17245
Total:        191 6871 3324.2   6339   17491
 
Percentage of the requests served within a certain time (ms)
  50%   6339
  66%   6910
  75%   7793
  80%   8141
  90%  10803
  95%  16092
  98%  16727
  99%  17223
 100%  17491 (longest request)

主机负载:
主机2负载:18.85
主机3负载:37.59
重要参数:
吞吐量:903.76 [#/sec] (mean)
所有并发请求的平均处理时间:1.106 [ms]
表中的数据量:15421,缺少579。(应该是16000条数据)

6、模拟7000并发,14000的请求总量

[root@skip file_xpt]# ab -n 14000 -c 7000 -p 'post.txt' -T 'application/x-www-form-urlencoded' -r http://172.19.195.225/api/testResult/save.json/
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
 
Benchmarking 172.19.195.225 (be patient)
Completed 1400 requests
Completed 2800 requests
Completed 4200 requests
Completed 5600 requests
Completed 7000 requests
Completed 8400 requests
Completed 9800 requests
Completed 11200 requests
Completed 12600 requests
Completed 14000 requests
Finished 14000 requests
 
 
Server Software:        openresty/1.15.8.3
Server Hostname:        172.19.195.225
Server Port:            80
 
Document Path:          /api/testResult/save.json/
Document Length:        1 bytes
 
Concurrency Level:      7000
Time taken for tests:   16.259 seconds
Complete requests:      14000
Failed requests:        597
   (Connect: 0, Receive: 199, Length: 199, Exceptions: 199)
Total transferred:      3312240 bytes
Total body sent:        3514000
HTML transferred:       13801 bytes
Requests per second:    861.07 [#/sec] (mean)
Time per request:       8129.380 [ms] (mean)
Time per request:       1.161 [ms] (mean, across all concurrent requests)
Transfer rate:          198.95 [Kbytes/sec] received
                        211.06 kb/s sent
                        410.01 kb/s total
 
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  376 1169.1     94    7022
Processing:    88 5806 2294.4   5640   15073
Waiting:        0 5620 2226.0   5525   15072
Total:        165 6182 2823.5   5913   16104
 
Percentage of the requests served within a certain time (ms)
  50%   5913
  66%   6520
  75%   7232
  80%   7674
  90%   9182
  95%  12640
  98%  14993
  99%  15171
 100%  16104 (longest request)

主机负载:
主机2负载:3.48
主机3负载:9.90
重要参数:
吞吐量:861.07 [#/sec] (mean)
所有并发请求的平均处理时间:1.161 [ms]
表中的数据量:13801,缺少199。(应该是14000条数据)

五、结论

测试环境为阿里云内网环境,不考虑外网因素的情况下,该架构并发可达6000+;
由于使用的单机数据库,并没有对mysql进行任何调优、集群,所以在6000+并发时,mysql成为瓶颈,出现写入数据失败的情况;

打赏
支付宝 微信
上一篇 下一篇