最近有一个使用ab测试服务器并发量的需求,顺便鼓捣了一下ab的入门操作。发现在网上的内容有些千篇一律。在此记录下我测试的过程。

我使用的ab测试命令如下

ab -n 100 -c 10 -T 'application/x-www-form-urlencoded' -p postfile  http://172.25.24.221:8880/project

此服务使用Tornado开发,ip为172.25.24.221,端口8880, 参数有两个:用户名user_id和查询语句query。

ab的参数有以下几个:

-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 benchmarkingThis implies -n 50000
-s timeout      Seconds to max. wait for each responseDefault 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 attributesare a colon separated username and password.
-P attribute    Add Basic Proxy Authentication, the attributesare 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
-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.
-h              Display usage information (this message)
-Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers)
-f protocol     Specify SSL/TLS protocol(SSL3, TLS1, TLS1.1, TLS1.2 or ALL)

在此主要用到的是-n-c-T-p四个参数,分别表示总请求数、并发数、Content-type、请求参数文件。
请求参数文件格式为:

user_id=haonima&query=%e4%b8%9c%e6%96%b9%e7%ba%a2%e5%a4%aa%e9%98%b3%e5%8d%87

中文需要做url编码。此步可以使用python转换

from urllib import quote
print quote('东方红太阳升')

更简单一点的方法可以直接去http://tool.chinaz.com/tools/urlencode.aspx转换。

然后就可以进行测试了

[haonima@server02 ab_test]$ ab -n 1000 -c 50 -T 'application/x-www-form-urlencoded' -p postfile  http://172.25.24.221:8880/project
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 172.25.24.221 (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 requestsServer Software:        TornadoServer/4.4.1
Server Hostname:        172.25.24.221
Server Port:            8880Document Path:          /project
Document Length:        292 bytesConcurrency Level:      50
Time taken for tests:   370.201 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      512000 bytes
Total body sent:        387000
HTML transferred:       292000 bytes
Requests per second:    2.70 [#/sec] (mean)
Time per request:       18510.060 [ms] (mean)
Time per request:       370.201 [ms] (mean, across all concurrent requests)
Transfer rate:          1.35 [Kbytes/sec] received1.02 kb/s sent2.37 kb/s totalConnection Times (ms)min  mean[+/-sd] median   max
Connect:        0    0   0.2      0       1
Processing:   378 18470 1042.0  18284   20271
Waiting:      377 18470 1042.0  18284   20271
Total:        379 18470 1041.9  18284   20271Percentage of the requests served within a certain time (ms)50%  1828466%  1871275%  1899480%  1911690%  1965295%  2013598%  2025799%  20267100%  20271 (longest request)

(入门)使用ab进行压力测试相关推荐

  1. apache修改最大连接并用ab网站压力测试

    apache修改最大连接并用ab网站压力测试 apache 2.2,使用默认配置,默认最大连接数是150 1.首先在httpd.conf中加载httpd-mpm.conf配置(去掉前面的注释): # ...

  2. ab命令压力测试攻击

    ab命令压力测试攻击 注:本尘埃の客栈所有文章均为技术分享,用于研究和复现漏洞,请勿非法用于其他用途,否则后果自负! ab命令攻击 ab命令全称为:Apache bench .是Apache自带的压力 ...

  3. 从零开始的Nginx [ 8 ] --- nginx 的性能优化:ab接口压力测试工具,tomcat企业运维,WEB站点部署,项目上线

    文章目录 nginx 性能优化 1.当前系统结构瓶颈 2.了解业务模式 3.性能与安全 4.系统与nginx性能优化 1.文件句柄 2.设置方式 3.系统全局性修该和用户局部性修改 4.进程局部性修改 ...

  4. apachebench ab.exe压力测试

    今天使用ab.exe做压力测试,由于页面只接收POST数据,遂上网找了相关资料,GET的一堆,POST的了了无几,而且都是抄来抄去,下面给出正确的POST请求参数信息 ab版本:2.3 E:\> ...

  5. 使用ab进行压力测试详解

    当你使用PHP(或其他编程语言)完成一个web程序的开发,并且web程序在Apache服务器上正常运行的时候,你有没有考虑过对你的Apache服务器及部署在其上的web程序进行一些压力测试呢?毕竟,真 ...

  6. Apache Benchmark(简称ab)压力测试安装与解释

    ab(apache benchmark)安装 命令: yum -y install httpd-tools ab测试的命令参数 命令: ab 或 ab -help 显示命令参数如下 ab [可选的参数 ...

  7. ab 服务器压力测试工具 使用详解

    ab的全称是Apache Bench,是Apache自带的网络压力测试工具,相比于LR.JMeter,是我所知道的 Http 压力测试工具中最简单.最通用的. ab命令对发出负载的计算机要求很低,不会 ...

  8. Linux学习13-CentOS安装ab做压力测试

    前言 网站性能压力测试是服务器网站性能调优过程中必不可缺少的一,测试环境准备好了后,如何对网站做压力测试? 压力测试的工具很多,如:ab.http_load.webbench.siege.jmeter ...

  9. ab.exe压力测试

    转载:https://www.cnblogs.com/TingJie/articles/4974885.html 当你使用PHP(或其他编程语言)完成一个web程序的开发,并且web程序在Apache ...

  10. ab进行压力测试详解

    当你使用PHP(或其他编程语言)完成一个web程序的开发,并且web程序在Apache服务器上正常运行的时候,你有没有考虑过对你的Apache服务器及部署在其上的web程序进行一些压力测试呢?毕竟,真 ...

最新文章

  1. 我来出个题:这些事务会不会回滚?大概率你会错!
  2. 如何 添加 implementation_如何用序列分类方式进行法律要素与当事人关联性分析 | 机器之心...
  3. python消费kafka逻辑处理导致cpu升高_大数据技术之一次KAFKA消费者异常引起的思考...
  4. Android学习---通过内容提供者(ContentProvider)操作另外一个应用私有数据库的内容...
  5. 【leetcode 简单】第五题 最长公共前缀
  6. python计算无穷级数求和,无穷级数求和的积分审敛法
  7. 桌面运维转网络要做什么准备,高级网工学习路线分享
  8. JAVASEday02
  9. googleseo只做内容不做外链行不行?(e6zzseo)
  10. 四川300家旅游企业上“云端”转型信息化
  11. Centos打开3306端口
  12. 【OpenCV-图像处理】用sift特征点算法和ransac算法进行多幅图像的拼接
  13. 加密项目是否采用DAO模式 首先考量这8个因素
  14. Mac虚拟机实现ios UI自动化教程-最新版本(MacOS 12.1,ios15.1)
  15. 共享企业文化造就企业明天
  16. 计算机网络矢量算法三个更新原则,距离矢量路由算法
  17. vi linux insert切换该行第一个字符,Linux之Vi命令讲解
  18. Java实战项目详细教程+文档+PPT+源码等]javaweb点餐系统全套|餐饮就餐订餐餐厅
  19. pythonocc 坐标系平移
  20. 2020年网络搭建与应用——国赛samba答案

热门文章

  1. mt6582 pwm
  2. linux 如何延迟100ms,Linux延时函数
  3. Windows Server 远程桌面 SSL/TLS 漏洞修复
  4. 企业承担社会责任的具体内容
  5. Jackknife test 是什么
  6. java微信公众号开发及源码分享
  7. IDEA修改默认的新建项目路径
  8. VS2010能否取代VS6?微软能否再创辉煌!
  9. 基础版微信模板消息开发详解,附代码PHP
  10. [架构之路-160]-《软考-系统分析师》-10-系统分析-7-数据与数据流程分析、需求规格说明书