大型门户网站核心技术,成都it公司排名,WordPress文章添加版权信息,整站seo排名外包转载#xff1a;ApacheBench#xff08;ab#xff09;使用详解 一、Apache Bench简介 ApacheBench 是 Apache 服务器自带的一个web压力测试工具#xff0c;简称ab。ab又是一个命令行工具#xff0c;对发起负载的本机要求很低#xff0c;根据ab命令可以创建很多的并发访问…转载ApacheBenchab使用详解 一、Apache Bench简介 ApacheBench 是 Apache 服务器自带的一个web压力测试工具简称ab。ab又是一个命令行工具对发起负载的本机要求很低根据ab命令可以创建很多的并发访问线程模拟多个访问者同时对某一URL地址进行访问因此可以用来测试目标服务器的负载压力。它的测试目标是基于URL的因此既可以用来测试Apache的负载压力也可以测试nginx、lighthttp、tomcat、IIS等其它Web服务器的压力。总的来说ab工具小巧简单上手学习较快可以提供需要的基本性能指标但是没有图形化结果不能监控。 ab命令对发出负载的计算机要求很低既不会占用很高CPU也不会占用很多内存但却会给目标服务器造成巨大的负载其原理类似CC攻击。自己测试使用也须注意否则一次上太多的负载可能造成目标服务器因资源耗完严重时甚至导致死机。 二、Apache Bench安装 首先需要安装Apache服务器下载地址https://www.apachelounge.com/download/ 建议下载最新版本的因为旧版本的ab不支持-r参数。 三、Apache Bench使用 1.使用例子 步骤1找到安装Apache Bench文件的bin目录下输入ab.exe 可以看到提示信息如下 步骤2 输入 ab -n 100 -c 20 http://localhost:8080/jsrWeb/index.html-n发出100个请求-c模拟20并发相当100人同时访问后面是测试url 输入 ab -n 100 -c 20 http://localhost:8080/jsrAdminWeb/test?strAA 传入一个参数 输入 ab -n 100 -c 20 -T text/plain -p test.txt http://localhost:8080/jsrAdminWeb/test 传入多个参数test.txt文件与ab.exe在同目录下test.txt文件里写str1AAstr2BB 输入 ab -n 100 -c 20 -T text/plain -p E:\DOWNLOAD\httpd-2.4.33-Win64-VC15\Apache24\test.txt http://localhost:8080/jsrAdminWeb/test 传入多个参数test.txt文件与ab.exe不在同目录下写入test.txt文件的全路径 输入 ab -t 60 -c 20 http://localhost:8080/jsrWeb/index.html 在60秒内发请求一次20个请求 结果参数解释(转载) Server Software: Microsoft-HTTPAPI/2.0 Server Hostname: 192.168.0.10 Server Port: 80 Document Path: / Document Length: 315 bytes HTTP响应数据的正文长度 Concurrency Level: 800 Time taken for tests: 0.914 seconds 所有这些请求处理完成所花费的时间 Complete requests: 800 完成请求数 Failed requests: 0 失败请求数 Write errors: 0 Non-2xx responses: 800 Total transferred: 393600 bytes 网络总传输量 HTML transferred: 252000 bytes HTML内容传输量 Requests per second: 875.22 [#/sec] (mean) 吞吐量-每秒请求数 Time per request: 914.052 [ms] (mean) 服务器收到请求响应页面要花费的时间 Time per request: 1.143 [ms] (mean, across all concurrent requests) 并发的每个请求平均消耗时间 Transfer rate: 420.52 [Kbytes/sec] received 平均每秒网络上的流量可以帮助排除是否存在网络流量过大导致响应时间延长的问题 网络上消耗的时间的分解 Connection Times (ms) min mean[/-sd] median max Connect: 0 1 0.5 1 3 Processing: 245 534 125.2 570 682 Waiting: 11 386 189.1 409 669 Total: 246 535 125.0 571 684 整个场景中所有请求的响应情况。在场景中每个请求都有一个响应时间 其中 50 的用户响应时间小于 571 毫秒 80 的用户响应时间小于 652 毫秒 最大的响应时间小于 684 毫秒 Percentage of the requests served within a certain time (ms) 50% 571 66% 627 75% 646 80% 652 90% 666 95% 677 98% 681 99% 682 100% 684 (longest request) 2.ApacheBench的参数说明 1 格式ab [options] [http://]hostname[:port]/path2 参数说明3 -n requests Number of requests to perform4 //在测试会话中所执行的请求个数本次测试总共要访问页面的次数。默认时仅执行一个请求。5 -c concurrency Number of multiple requests to make6 //一次产生的请求个数并发数。默认是一次一个。7 -t timelimit Seconds to max. wait for responses8 //测试所进行的最大秒数。其内部隐含值是-n 50000。它可以使对服务器的测试限制在一个固定的总时间以内。默认时没有时间限制。9 -p postfile File containing data to POST
10 //包含了需要POST的数据的文件文件格式如“p11p22”.使用方法是 -p 111.txt 。 配合-T
11 -T content-type Content-type header for POSTing
12 //POST数据所使用的Content-type头信息如 -T “application/x-www-form-urlencoded” 。 配合-p
13 -v verbosity How much troubleshooting info to print
14 //设置显示信息的详细程度 – 4或更大值会显示头信息 3或更大值可以显示响应代码(404, 200等), 2或更大值可以显示警告和其他信息。 -V 显示版本号并退出。
15 -w Print out results in HTML tables
16 //以HTML表的格式输出结果。默认时它是白色背景的两列宽度的一张表。
17 -i Use HEAD instead of GET
18 // 执行HEAD请求而不是GET。
19 -x attributes String to insert as table attributes
20 -y attributes String to insert as tr attributes
21 -z attributes String to insert as td or th attributes
22 -C attribute Add cookie, eg. -C “c11234,c22,c33″ (repeatable)
23 //-C cookie-namevalue 对请求附加一个Cookie:行。 其典型形式是namevalue的一个参数对。此参数可以重复用逗号分割。
24 提示可以借助session实现原理传递 JSESSIONID参数 实现保持会话的功能如
25 -C ” c11234,c22,c33, JSESSIONIDFF056CD16DA9D71CB131C1D56F0319F8″ 。
26 -H attribute Add Arbitrary header line, eg. ‘Accept-Encoding: gzip’ Inserted after all normal header lines. (repeatable)
27 -A attribute Add Basic WWW Authentication, the attributes
28 are a colon separated username and password.
29 -P attribute Add Basic Proxy Authentication, the attributes
30 are a colon separated username and password.
31 //-P proxy-auth-username:password 对一个中转代理提供BASIC认证信任。用户名和密码由一个:隔开并以base64编码形式发送。无论服务器是否需要(即, 是否发送了401认证需求代码)此字符串都会被发送。
32 -X proxy:port Proxyserver and port number to use
33 -V Print version number and exit
34 -k Use HTTP KeepAlive feature
35 -d Do not show percentiles served table.
36 -S Do not show confidence estimators and warnings.
37 -g filename Output collected data to gnuplot format file.
38 -e filename Output CSV file with percentages served
39 -h Display usage information (this message)
40 //-attributes 设置属性的字符串. 缺陷程序中有各种静态声明的固定长度的缓冲区。另外对命令行参数、服务器的响应头和其他外部输入的解析也很简单这可能会有不良后果。它没有完整地实现 HTTP/1.x; 仅接受某些’预想’的响应格式。 strstr(3)的频繁使用可能会带来性能问题即你可能是在测试ab而不是服务器的性能。 转载于:https://www.cnblogs.com/nananana/p/8748941.html