压力测试

服务器信息

[root@localhost webbench]# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                4
On-line CPU(s) list:   0-3
Thread(s) per core:    1
Core(s) per socket:    1
Socket(s):             4
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 63
Model name:            Intel(R) Xeon(R) CPU E5-2690 v3 @ 2.60GHz
Stepping:              0
CPU MHz:               2599.998
BogoMIPS:              5199.99
Hypervisor vendor:     VMware
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              30720K
NUMA node0 CPU(s):     0-3
[root@localhost webbench]# free -h
              total        used        free      shared  buff/cache   available
Mem:           3.7G        3.3G        237M        3.4M        176M        206M
Swap:          6.0G        1.3G        4.7G

## ```ab压力测试静态网页:

```bash
[root@localhost sbin]# ab -c 10000 -n 10000 http://210.73.219.46/index1.html
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 210.73.219.46 (be patient)
socket: Too many open files (24)
[root@localhost sbin]# ab -c 1000 -n 10000 http://210.73.219.46/index1.html
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 210.73.219.46 (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.12.2
Server Hostname:        210.73.219.46
Server Port:            80

Document Path:          /index1.html
Document Length:        169 bytes

Concurrency Level:      1000
Time taken for tests:   0.657 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Non-2xx responses:      10000
Total transferred:      3190000 bytes
HTML transferred:       1690000 bytes
Requests per second:    15224.66 [#/sec] (mean)
Time per request:       65.683 [ms] (mean)
Time per request:       0.066 [ms] (mean, across all concurrent requests)
Transfer rate:          4742.84 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   12   8.0      9      53
Processing:     3   15   7.7     13     214
Waiting:        0   12   6.8     11     210
Total:         13   27  12.3     22     222

Percentage of the requests served within a certain time (ms)
  50%     22
  66%     25
  75%     27
  80%     28
  90%     58
  95%     60
  98%     62
  99%     64
 100%    222 (longest request)

说明:

Server Software: nginx/1.10.2 (服务器软件名称及版本信息)
Server Hostname: 192.168.1.106(服务器主机名)
Server Port: 80 (服务器端口)
Document Path: /index1.html. (供测试的URL路径)
Document Length: 3721 bytes (供测试的URL返回的文档大小)
Concurrency Level: 1000 (并发数)
Time taken for tests: 2.327 seconds (压力测试消耗的总时间)
Complete requests: 5000 (的总次数)
Failed requests: 688 (失败的请求数)
Write errors: 0 (网络连接写入错误数)
Total transferred: 17402975 bytes (传输的总数据量)
HTML transferred: 16275725 bytes (HTML文档的总数据量)
Requests per second: 2148.98 [#/sec] (mean) (平均每秒的请求数) 这个是非常重要的参数数值,服务器的吞吐量
Time per request: 465.338 [ms] (mean) (所有并发用户(这里是1000)都请求一次的平均时间)
Time request: 0.247 [ms] (mean, across all concurrent requests) (单个用户请求一次的平均时间)
Transfer rate: 7304.41 [Kbytes/sec] received 每秒获取的数据长度 (传输速率,单位:KB/s)

Percentage of the requests served within a certain time (ms)
50% 347 ## 50%的请求在347ms内返回
66% 401 ## 60%的请求在401ms内返回
75% 431
80% 516
90% 600
95% 846
98% 1571
99% 1593
100% 1619 (longest request)

ab压力测试java项目

[root@localhost ~]# ab -c 1000 -n 10000 http://210.73.219.46:8080/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 210.73.219.46 (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:        Jetty(9.4.z-SNAPSHOT)
Server Hostname:        210.73.219.46
Server Port:            8080

Document Path:          /
Document Length:        793 bytes

Concurrency Level:      1000
Time taken for tests:   2.307 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Non-2xx responses:      10000
Total transferred:      15268320 bytes
HTML transferred:       7930000 bytes
Requests per second:    4335.50 [#/sec] (mean)
Time per request:       230.654 [ms] (mean)
Time per request:       0.231 [ms] (mean, across all concurrent requests)
Transfer rate:          6464.43 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   52 217.6      1    1015
Processing:     0   19  54.7     11     822
Waiting:        0   17  54.5     10     821
Total:          1   70 246.2     12    1825

Percentage of the requests served within a certain time (ms)
  50%     12
  66%     15
  75%     18
  80%     21
  90%     37
  95%    249
  98%   1051
  99%   1057
 100%   1825 (longest request)

综上:95%以上的处理存在瓶颈了,静态资源会好很多,但是动态资源就受限制了

webbench压力测试:

安装
[root@localhost ~]# tar -zvxf webbench-1.5.tar.gz 
webbench-1.5/
webbench-1.5/webbench.1
webbench-1.5/socket.c
webbench-1.5/webbench.c
webbench-1.5/Makefile
webbench-1.5/debian/
webbench-1.5/debian/rules
webbench-1.5/debian/dirs
webbench-1.5/debian/copyright
webbench-1.5/debian/control
webbench-1.5/debian/changelog
webbench-1.5/COPYRIGHT
webbench-1.5/ChangeLog
[root@localhost ~]# ls
jenkins.war  nginx  nginx-1.12.2.tar.gz  pyenv  webbench-1.5  webbench-1.5.tar.gz
[root@localhost ~]# mv webbench-1.5 webbench
[root@localhost ~]# ls
jenkins.war  nginx  nginx-1.12.2.tar.gz  pyenv  webbench  webbench-1.5.tar.gz
[root@localhost ~]# cd webbench
报错
[root@localhost webbench]# make && make install 
cc -Wall -ggdb -W -O   -c -o webbench.o webbench.c
webbench.c: In function ‘alarm_handler’:
webbench.c:77:31: warning: unused parameter ‘signal’ [-Wunused-parameter]
 static void alarm_handler(int signal)
                               ^
cc -Wall -ggdb -W -O  -o webbench webbench.o  
ctags *.c
/bin/sh: ctags: command not found
make: [tags] Error 127 (ignored)
install -s webbench /usr/local/bin	
install -m 644 webbench.1 /usr/local/man/man1	
install: cannot create regular file ‘/usr/local/man/man1’: No such file or directory
make: *** [install] Error 1

解决错误:

[root@localhost webbench]# mkdir /usr/local/man/man1 -p

帮助信息:

[root@localhost webbench]# webbench --help
webbench [option]... URL
  -f|--force               Don't wait for reply from server.
  -r|--reload              Send reload request - Pragma: no-cache.
  -t|--time <sec>          Run benchmark for <sec> seconds. Default 30.
  -p|--proxy <server:port> Use proxy server for request.
  -c|--clients <n>         Run <n> HTTP clients at once. Default one.
  -9|--http09              Use HTTP/0.9 style requests.
  -1|--http10              Use HTTP/1.0 protocol.
  -2|--http11              Use HTTP/1.1 protocol.
  --get                    Use GET request method.
  --head                   Use HEAD request method.
  --options                Use OPTIONS request method.
  --trace                  Use TRACE request method.
  -?|-h|--help             This information.
  -V|--version             Display program version.

说明:

usage函数:webbench用法介绍
-f|–force 不需要等待服务器响应
-r|–reload 发送重新加载请求
-t|–time 运行多长时间,单位是秒
-p|–proxy server:port 使用代理服务器发送请求
-c|–clients 创建多少个客户端
-9|–http09 使用HTTP/0.9
-1|–http10 使用HTTP/1.0协议
-2|–http11 使用HTTP/1.1协议
–get 使用GET方法请求
–head 使用HEAD方法请求
–options 使用OPTIONS方法请求
–trace 使用TRACE方法请求
-?|-h|–help 打印帮助信息
-V|–version 显示版本号

静态网页压力测试结果:

[root@localhost webbench]# webbench -c 2000 -t 20 http://210.73.219.46/index.html
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://210.73.219.46/index.html
2000 clients, running 20 sec.

Speed=985533 pages/min, 13879421 bytes/sec.
Requests: 328511 susceed, 0 failed.

增大压力:

[root@localhost webbench]# webbench -c 10000  -t 20 http://210.73.219.46/index.html
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://210.73.219.46/index.html
10000 clients, running 20 sec.
problems forking worker no. 8878
fork failed.: Resource temporarily unavailable

说明:增大压力时,资源不够用了,压测的同时,我用top看了一下资源占用情况
在这里插入图片描述
nginx、kswapd0(交换空间swap)cpu使用率过高

压力测试war项目:

[root@localhost webbench]# webbench -c 1000  -t 20 http://210.73.219.46:8080/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://210.73.219.46:8080/
1000 clients, running 20 sec.

Speed=64641 pages/min, 1647206 bytes/sec.
Requests: 21547 susceed, 0 failed.

增大压力测试:

[root@localhost webbench]# webbench -c 3000  -t 20 http://210.73.219.46:8080/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://210.73.219.46:8080/
3000 clients, running 20 sec.

Speed=33276 pages/min, 817275 bytes/sec.
Requests: 10807 susceed, 285 failed.

增大压力后有失败的,正常的并发1000没问题,增加到3000时会有failed,增加到10000时,资源不允许了就

  • Apache ab做压力测试

优点:Apache的ab使用非常简单, 而且只要是安装了Apache了,就会自带其ab工具;
缺点:就是不能模拟高并发状态下的测试, 好像最多可以模拟100-200次/秒的并发. 如果需要模拟更高负载的压力测试, 就需要使用Webbench。

  • webbench做压力测试

优点 :① 能测试相同硬件上不同服务的性能及不同硬件上同一个服务的运行状况;
② 它的标准测试可以向我们展示服务器的两项内容:每秒钟相应请求数和每秒钟传输数据量;
③ 支持静态页面、动态页面(如:ASP、PHP、JAVA、CGI)、SSL协议的测试能力;
④ webbench最多可以模拟3万个并发连接去测试网站的负载能力; 缺点: 测试的结果太简单

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值