架构师_程序员_码农网

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 7003|回复: 3

windows Apache ab web网站压力测试

[复制链接]
发表于 2018-6-14 11:14:30 | 显示全部楼层 |阅读模式
ab 是apachebench的缩写。

ab命令会创建多个并发访问线程,模拟多个访问者同时对某一URL地址进行访问。它的测试目标是基于URL的,因此,它既可以用来测试apache的负载压力,也可以测试nginx、lighthttp、tomcat、IIS等其它Web服务器的压力。

ab命令对发出负载的计算机要求很低,它既不会占用很高CPU,也不会占用很多内存。但却会给目标服务器造成巨大的负载,其原理类似CC攻击。自己测试使用也需要注意,否则一次上太多的负载。可能造成目标服务器资源耗完,严重时甚至导致死机。

一、Apache Bench简介

ApacheBench 是 Apache 服务器自带的一个web压力测试工具,简称ab。ab又是一个命令行工具,对发起负载的本机要求很低,根据ab命令可以创建很多的并发访问线程,模拟多个访问者同时对某一URL地址进行访问,因此可以用来测试目标服务器的负载压力。总的来说ab工具小巧简单,上手学习较快,可以提供需要的基本性能指标,但是没有图形化结果,不能监控。



二、Apache Bench安装

首先需要安装Apache服务器,下载地址:https://www.apachelounge.com/download/

我电脑是win10 64位的系统,所以,我下载的是“httpd-2.4.33-win64-VC15.zip”,链接:https://www.apachelounge.com/dow ... 4.33-win64-VC15.zip

建议下载最新版本的,因为旧版本的ab不支持-r参数。

三、Apache Bench使用

了解参数

参数说明:
格式:ab [options] [http://]hostname[:port]/path

-n requests Number of requests to perform     //本次测试发起的总请求数
-c concurrency Number of multiple requests to make   //一次产生的请求数(或并发数)
-t timelimit Seconds to max. wait for responses    //测试所进行的最大秒数,默认没有时间限制。
-r Don't exit on socket receive errors.     // 抛出异常继续执行测试任务
-p postfile File containing data to POST  //包含了需要POST的数据的文件,文件格式如“p1=1&p2=2”.使用方法是 -p 111.txt

-T content-type Content-type header for POSTing
//POST数据所使用的Content-type头信息,如 -T “application/x-www-form-urlencoded” 。 (配合-p)
-v verbosity How much troubleshooting info to print
//设置显示信息的详细程度 – 4或更大值会显示头信息, 3或更大值可以显示响应代码(404, 200等), 2或更大值可以显示警告和其他信息。 -V 显示版本号并退出。
-C attribute Add cookie, eg. -C “c1=1234,c2=2,c3=3” (repeatable)
//-C cookie-name=value 对请求附加一个Cookie:行。 其典型形式是name=value的一个参数对。此参数可以重复,用逗号分割。
提示:可以借助session实现原理传递 JSESSIONID参数, 实现保持会话的功能,如-C ” c1=1234,c2=2,c3=3, JSESSIONID=FF056CD16DA9D71CB131C1D56F0319F8″ 。
-w Print out results in HTML tables  //以HTML表的格式输出结果。默认时,它是白色背景的两列宽度的一张表。
-i Use HEAD instead of GET
-x attributes String to insert as table attributes
-y attributes String to insert as tr attributes
-z attributes String to insert as td or th attributes
-H attribute Add Arbitrary header line, eg. ‘Accept-Encoding: gzip’ Inserted after all normal header lines. (repeatable)
-A attribute Add Basic WWW Authentication, the attributes
are a colon separated username and password.
-P attribute Add Basic Proxy Authentication, the attributes are a colon separated username and password.
-X proxy:port Proxyserver and port number to use
-V Print version number and exit
-k Use HTTP KeepAlive feature
-d Do not show percentiles served table.
-S Do not show confidence estimators and warnings.
-g filename Output collected data to gnuplot format file.
-e filename Output CSV file with percentages served
-h Display usage information (this message)

参数很多,一般我们用 -c 和 -n 参数就可以了。例如:


解压“httpd-2.4.33-win64-VC15.zip”,进入\Apache24\bin下面,用cmd命令行的方式去启动,如下图:

QQ截图20180614111058.jpg QQ截图20180614111113.jpg

SSL not compiled in; no https support:SSL未编译进去; 没有https支持,说明不支持https的网站。

测试结果:

C:\Users\itsvse_pc\Downloads\httpd-2.4.33-win64-VC15\Apache24\bin>ab -c 10 -n 1000 https://www.itsvse.com
SSL not compiled in; no https support

C:\Users\itsvse_pc\Downloads\httpd-2.4.33-win64-VC15\Apache24\bin>ab -c 10 -n 1000 http://www.itsvse.com/
This is ApacheBench, Version 2.3 <$Revision: 1826891 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.itsvse.com (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:
Server Hostname:        www.itsvse.com
Server Port:            80

Document Path:          /
Document Length:        178 bytes

Concurrency Level:      10
Time taken for tests:   44.916 seconds
Complete requests:      1000
Failed requests:        0
Non-2xx responses:      1000
Total transferred:      349000 bytes
HTML transferred:       178000 bytes
Requests per second:    22.26 [#/sec] (mean)
Time per request:       449.164 [ms] (mean)
Time per request:       44.916 [ms] (mean, across all concurrent requests)
Transfer rate:          7.59 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       32   45  60.1     37    1439
Processing:    35  401 185.6    356    1795
Waiting:       34  245 199.6    228    1791
Total:         69  446 195.4    397    1830

Percentage of the requests served within a certain time (ms)
  50%    397
  66%    415
  75%    439
  80%    461
  90%    535
  95%    623
  98%   1563
  99%   1784
100%   1830 (longest request)

结果参数分析:

Document Path:测试页面
Document Length: 页面大小
Concurrency Level: 测试的并发数
Time taken for tests:整个测试持续的时间
Complete requests:完成的请求数量
Failed requests: 失败的请求数量
Write errors: 0
Total transferred: 整个过程中的网络传输量
HTML transferred: 整个过程中的HTML内容传输量
Requests per second: 最重要的指标之一,相当于LR中的每秒事务数,后面括号中的mean表示这是一个平均值
Time per request: 最重要的指标之二,相当于LR中的平均事务响应时间,后面括号中的mean表示这是一个平均值
Time per request: 每个连接请求实际运行时间的平均值
Transfer rate: 平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题





上一篇:在Linq to Entity 中使用lambda表达式来实现Left Join和Join
下一篇:asp.net mvc Route路由映射.html后缀
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
 楼主| 发表于 2018-6-14 11:16:33 | 显示全部楼层
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
 楼主| 发表于 2019-5-27 09:17:09 | 显示全部楼层
ab -n 800 -c 800  http://192.168.0.10/
-n发出800个请求,-c模拟800并发,相当800人同时访问,后面是测试url)
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
 楼主| 发表于 2019-5-27 09:20:46 | 显示全部楼层
还可以通过Fiddler进行压力并发测试,打开Fiddler工具,拦截所有请求,如下图:
QQ截图20190527091444.jpg

选中要重复请求的会话,然后按shift+r,会弹出Repeat this request how many times?(重复这个请求多少次?)

输入要重复请求的次数,这里我填写的5,fiddle就会帮你重复请求该链接5次,如下图:

QQ截图20190527091504.jpg

更多fiddle操作技巧,请参见手册:

Fiddler中文手册.zip下载
https://down.itsvse.com/item/12839.html


码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

免责声明:
码农网所发布的一切软件、编程资料或者文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:help@itsvse.com

QQ|手机版|小黑屋|架构师 ( 鲁ICP备14021824号-2 )|网站地图

GMT+8, 2024-4-20 10:53

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表