其它
使用Chrome/Edge模拟跨域请求
How to encrypt data in linux(Debian/Ubuntu)
压力测试
ApacheBench
Mac安装OpenVPN客户端
ffmpeg拼接视频与格式转换
软路由
去广告hosts
whisper自动为视频生成字幕
99. 故障处理
Nginx无法绑定0.0.0.0:80
记一次Laravel用户跟踪插件导致的性能问题
Zoom下载链接
laravel-u-editor在新版chrome内核浏览器的问题
浏览器ServiceWorker问题
本文档使用 MrDoc 发布
-
+
首页
ApacheBench
# ApacheBench ## 安装 ```shell [root@master ~]# yum -y install httpd-tools ``` ## 使用 ### 帮助说明 ```shell [root@master ~]# ab --help ab: wrong number of arguments Usage: ab [options] [http[s]://]hostname[:port]/path Options are: -n requests Number of requests to perform -c concurrency Number of multiple requests to make at a time -t timelimit Seconds to max. to spend on benchmarking This implies -n 50000 -s timeout Seconds to max. wait for each response Default is 30 seconds -b windowsize Size of TCP send/receive buffer, in bytes -B address Address to bind to when making outgoing connections -p postfile File containing data to POST. Remember also to set -T -u putfile File containing data to PUT. Remember also to set -T -T content-type Content-type header to use for POST/PUT data, eg. 'application/x-www-form-urlencoded' Default is 'text/plain' -v verbosity How much troubleshooting info to print -w Print out results in HTML tables -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 -C attribute Add cookie, eg. 'Apache=1234'. (repeatable) -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. -q Do not show progress when doing more than 150 requests -l Accept variable document length (use this for dynamic pages) -g filename Output collected data to gnuplot format file. -e filename Output CSV file with percentages served -r Don't exit on socket receive errors. -m method Method name -h Display usage information (this message) -I Disable TLS Server Name Indication (SNI) extension -Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers) -f protocol Specify SSL/TLS protocol (TLS1, TLS1.1, TLS1.2 or ALL) -E certfile Specify optional client certificate chain and private key ``` ### GET - 修改Header中user-agent伪装浏览器请求 ```shell [root@master ~]# ab -n 100 -c 10 -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.66' 'http://127.0.0.1/' ``` ### POST - post json格式数据 - Header中增加自定义user-agent - post格式设置为application/json ```shell [root@master ~]# ab -n 100 -c 10 -p post.json -T 'application/json' -H 'user-agent: ApacheBench Zhangky'' 'http://127.0.0.1/login' # json文件示例 [root@master ~]# cat post.json {"user": "username", "pwd": "password"} ``` ## 性能指标 ### 1、吞吐率(Requests per second) ```shell 服务器并发处理能力的量化描述,单位是reqs/s,指的是在某个并发用户数下单位时间内处理的请求数。某个并发用户数下单位时间内能处理的最大请求数,称之为最大吞吐率。 吞吐率是基于并发用户数的。这句话代表了两个含义: a、吞吐率和并发用户数相关 b、不同的并发用户数下,吞吐率一般是不同的 计算公式:总请求数/处理完成这些请求数所花费的时间,即: Request per second=Complete requests/Time taken for tests 必须要说明的是,这个数值表示当前机器的整体性能,值越大越好。 ``` ### 2、并发连接数(The number of concurrent connections) ```shell 并发连接数指的是某个时刻服务器所接受的请求数目,简单的讲,就是一个会话。 ``` ### 3、并发用户数(Concurrency Level) ```shell 要注意区分这个概念和并发连接数之间的区别,一个用户可能同时会产生多个会话,也即连接数。在HTTP/1.1下: IE7支持两个并发连接 IE8支持6个并发连接 FireFox3支持4个并发连接 所以相应的,我们的并发用户数就得除以这个基数。 ``` ### 4、用户平均请求等待时间(Time per request) ```shell 计算公式:处理完成所有请求数所花费的时间/(总请求数/并发用户数),即: Time per request=Time taken for tests/(Complete requests/Concurrency Level) ``` ### 5、服务器平均请求等待时间(Time per request:across all concurrent requests) ```shell 计算公式:处理完成所有请求数所花费的时间/总请求数,即: Time taken for/testsComplete requests 可以看到,它是吞吐率的倒数。 同时,它也等于用户平均请求等待时间/并发用户数,即: Time per request/Concurrency Level ```
zhangky
2021年6月3日 15:45
分享文档
收藏文档
上一篇
下一篇
微信扫一扫
复制链接
手机扫一扫进行分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码