ab测试工具
安装
[root@iZzm446eh1ux98Z apache-tomcat-8.5.57]# yum install -y ab CentOS-8 - AppStream 75 kB/s | 4.3 kB 00:00 CentOS-8 - Base 59 kB/s | 3.9 kB 00:00 CentOS-8 - Extras 23 kB/s | 1.5 kB 00:00 Extra Packages for Enterprise Linux 8 - x86_64 105 kB/s | 4.7 kB 00:00 No match for argument: ab Error: Unable to find a match: ab [root@iZzm446eh1ux98Z apache-tomcat-8.5.57]# yum install -y httpd-tools Last metadata expiration check: 0:01:03 ago on Sun 30 Aug 2020 11:45:07 AM CST. Dependencies resolved. ========================================================================================================================== Package Architecture Version Repository Size ========================================================================================================================== Installing: httpd-tools x86_64 2.4.37-21.module_el8.2.0+382+15b0afa8 AppStream 103 k Installing dependencies: apr x86_64 1.6.3-9.el8 AppStream 125 k apr-util x86_64 1.6.1-6.el8 AppStream 105 k Installing weak dependencies: apr-util-bdb x86_64 1.6.1-6.el8 AppStream 25 k apr-util-openssl x86_64 1.6.1-6.el8 AppStream 27 k Enabling module streams: httpd 2.4 Transaction Summary ========================================================================================================================== Install 5 Packages Total download size: 384 k Installed size: 750 k Downloading Packages: (1/5): apr-util-1.6.1-6.el8.x86_64.rpm 876 kB/s | 105 kB 00:00 (2/5): apr-1.6.3-9.el8.x86_64.rpm 952 kB/s | 125 kB 00:00 (3/5): apr-util-openssl-1.6.1-6.el8.x86_64.rpm 802 kB/s | 27 kB 00:00 (4/5): httpd-tools-2.4.37-21.module_el8.2.0+382+15b0afa8.x86_64.rpm 2.5 MB/s | 103 kB 00:00 (5/5): apr-util-bdb-1.6.1-6.el8.x86_64.rpm 137 kB/s | 25 kB 00:00 -------------------------------------------------------------------------------------------------------------------------- Total 2.1 MB/s | 384 kB 00:00 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : apr-1.6.3-9.el8.x86_64 1/5 Running scriptlet: apr-1.6.3-9.el8.x86_64 1/5 Installing : apr-util-bdb-1.6.1-6.el8.x86_64 2/5 Installing : apr-util-openssl-1.6.1-6.el8.x86_64 3/5 Installing : apr-util-1.6.1-6.el8.x86_64 4/5 Running scriptlet: apr-util-1.6.1-6.el8.x86_64 4/5 Installing : httpd-tools-2.4.37-21.module_el8.2.0+382+15b0afa8.x86_64 5/5 Running scriptlet: httpd-tools-2.4.37-21.module_el8.2.0+382+15b0afa8.x86_64 5/5 Verifying : apr-1.6.3-9.el8.x86_64 1/5 Verifying : apr-util-1.6.1-6.el8.x86_64 2/5 Verifying : apr-util-bdb-1.6.1-6.el8.x86_64 3/5 Verifying : apr-util-openssl-1.6.1-6.el8.x86_64 4/5 Verifying : httpd-tools-2.4.37-21.module_el8.2.0+382+15b0afa8.x86_64 5/5 Installed: httpd-tools-2.4.37-21.module_el8.2.0+382+15b0afa8.x86_64 apr-util-bdb-1.6.1-6.el8.x86_64 apr-util-openssl-1.6.1-6.el8.x86_64 apr-1.6.3-9.el8.x86_64 apr-util-1.6.1-6.el8.x86_64 Complete!
测试
[root@iZzm446eh1ux98Z ~]# ab -c 5 -n 4000 http://182.92.58.141:8080/myapp This is ApacheBench, Version 2.3 <$Revision: 1843412 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 182.92.58.141 (be patient) Completed 400 requests Completed 800 requests Completed 1200 requests Completed 1600 requests Completed 2000 requests Completed 2400 requests Completed 2800 requests Completed 3200 requests Completed 3600 requests Completed 4000 requests Finished 4000 requests Server Software: Server Hostname: 182.92.58.141 Server Port: 8080 Document Path: /myapp Document Length: 0 bytes Concurrency Level: 5 Time taken for tests: 23.013 seconds Complete requests: 4000 Failed requests: 0 Non-2xx responses: 4000 Total transferred: 468000 bytes HTML transferred: 0 bytes Requests per second: 173.81 [#/sec] (mean) Time per request: 28.766 [ms] (mean) Time per request: 5.753 [ms] (mean, across all concurrent requests) Transfer rate: 19.86 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 2 18 119.0 4 1067 Processing: 2 11 50.0 4 2242 Waiting: 2 10 48.4 4 2242 Total: 5 28 133.6 8 3252 Percentage of the requests served within a certain time (ms) 50% 8 66% 8 75% 9 80% 9 90% 10 95% 24 98% 226 99% 1027 100% 3252 (longest request)
处理报错 apr_socket_recv: Connection reset by peer
[root@iZzm446eh1ux98Z ~]# ab -c 50 -n 40000 http://182.92.58.141:8080/myapp This is ApacheBench, Version 2.3 <$Revision: 1843412 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 182.92.58.141 (be patient) Completed 4000 requests apr_socket_recv: Connection reset by peer (104) Total of 7660 requests completed
apr_socket_recv这个是操作系统内核的一个参数,在高并发的情况下,内核会认为系统受到了SYN flood攻击,会发送cookies(possible SYN flooding on port 80. Sending cookies),这样会减慢影响请求的速度,所以在应用服务武器上设置下这个参数为0禁用系统保护就可以进行大并发测试了
如果量太大了,改了也不好使
[root@iZzm446eh1ux98Z ~]# vim /etc/sysctl.conf vm.swappiness = 0 kernel.sysrq = 1 net.ipv4.neigh.default.gc_stale_time = 120 # see details in https://help.aliyun.com/knowledge_detail/39428.html net.ipv4.conf.all.rp_filter = 0 net.ipv4.conf.default.rp_filter = 0 net.ipv4.conf.default.arp_announce = 2 net.ipv4.conf.lo.arp_announce = 2 net.ipv4.conf.all.arp_announce = 2 # see details in https://help.aliyun.com/knowledge_detail/41334.html net.ipv4.tcp_max_tw_buckets = 5000 net.ipv4.tcp_syncookies = 0 net.ipv4.tcp_max_syn_backlog = 1024 net.ipv4.tcp_synack_retries = 2
[root@iZzm446eh1ux98Z ~]# sysctl -p
ab命令选项
命令选项 | 描述 |
-A | 用于向服务器提供BASIC认证信息,格式"用户名:密码",以base64编码发送 |
-B | 创建连接时绑定的本地地址 |
-b | TCP发送接收缓冲大小,单位字节 |
-c | 同一时刻执行的请求数目,即请求并发数 |
-C | 为请求添加Cookie信息,格式为name=value,此选项可以多次设置 |
-d | 使输出结果不包含 Percentage of the requests served 这部分 |
-e | 结果输出到CSV文件,文件包含两列,第一列是处理请求数的百分比,第二列是处理该百分比的耗时(ms) |
-f | 指定SSL/TLS协议,可以是SSL2/SSL3/TLS1/TLS1.1/TLS2/ALL |
-g | 将所有的测试值输出为gnuplot或TSV文件 |
-h | 帮助信息 |
-H | 为请求添加头信息,按请求头的格式指定参数(以冒号分割的 属性-值 ) |
-i | 执行HEAD请求,以替代GET请求 |
-k | 启用HTTP KeepAlive |
-l | 当响应长度不恒定时,不提示异常。如果请求的是动态页面,可以使用该选项(>2.4.7版本) |
-m | 以指定的HTTP Method(>2.4.10版本) |
-n | 请求的SESSION数量 |
-p小写 | 包含Post请求数据的文件,配合-T使用 |
-P | 对代理中转提供BASIC认证,格式同-A |
-q | 当请求数目超过150时,ab每隔10%或100个请求输出一次进度,该选项用于禁止输出进度 |
-r | Socket接收错误时不退出 |
-s | Socket超时之前的最大等待时间(s),默认30s,(>2.4.4版本) |
-S | 不显示中位数和标准时差,当平均值和中位数超过标准差的一到两倍,不显示错误和警告信息 |
-t | 基准测试最大耗时,单位s,可以控制服务器基准测试的总时长 |
-T | POST/PUT请求使用的Content-type,默认text/plain |
-u | 用于PUT请求的数据文件,同样与-T配合使用 |
-v | 设置冗长级别。4以上打印头信息,3以上打印响应码,2及以上打印警告和信息提示 |
-V | 显示版本信息 |
-w | HTML表格输出结果 |
-x | 如果以HTML表格输出结果,该选项用于指定<table>标签属性 |
-X | 请求启用代理服务器,格式为proxy:port |
-y | 如果以HTML表格输出结果,该选项用于指定<tr>标签属性 |
-z | 如果以HTML表格输出结果,该选项用于指定<td>标签属性 |
-Z |
指定SSL/TLS加密套件 |
输出结果说明
输出 | 描述 |
Server Software |
输出第一个成功请求的"server" HTTP响应头信息,用于记录服务器软件名 |
Server Hostname | 服务器的主机名或IP地址 |
Server Port | ab测试时,服务器的端口,默认HTTP/80,HTTPS/443 |
SSL/TLS Protocol | 客户端与服务器之间的协议参数协商,只有使用SSL时才会输出 |
Document Path | 命令行输出的请求URI |
Document Length | 第一个成功返回的文档大小(Byte),测试期间,如果请求的文档大小发生变化,响应被视为错误 |
Concurrency Level | 测试期间,客户端并发的数目 |
Time taken for tests | 自第一个请求创建到最后一个响应返回的总耗时 |
Complete requests | 接收到成功响应的请求数 |
Failed requests | 失败的请求数。如果该值大于0,还会输出链接失败、读失败、错误的内容长度以及异常的请求数目 |
Write errors | 写错误条目 |
Non-2xx responses | 响应码不是2xx的数量,如果都是2xx,则不显示该信息 |
Keep-Alive requests | 导致Keep-Alive请求的连接数量 |
Total body sent |
测试中,如果客户端发送数据,该部分用于显示测试期间发送的数据字节数; 如果测试不发送请求体,该部分输出将省略 |
Total transferred | 从服务器接收的总字节数,该数值基本等于通过网络接收的数据量 |
HTML transferred | 从服务器接收的总文档字节数,该数值排出了接收的HTTP头字节数 |
Requests per second | 每秒请求数(吞吐率),计算方式:总请求数/总耗时 |
Time per request | 请求平均耗时,有两个取值:第一个是"并发数*总耗时*1000/请求数",第二个是"总耗时*1000/请求数" |
Transfer rate | 传输速率,计算方式为"总读取字节数/1024/总耗时" |
posted on 2020-08-30 13:12 hopeless-dream 阅读(503) 评论(0) 编辑 收藏 举报