性能工具之 Apache Bench 入门使用

简介: ab 全称为:apache bench,ab 为小型压力工具,对于在 Linux 中简单压测 HTTP 接口轻巧灵活。

一、背景

ab 全称为:apache bench,ab 为小型压力工具,对于在 Linux 中简单压测 HTTP 接口轻巧灵活。

在官网上的解释如下:

ab是Apache超文本传输协议(HTTP)的性能测试工具。其设计意图是描绘当前所安装的Apache的执行性能,主要是显示你安装的Apache每秒可以处理多少个请求。

apache官网:http://httpd.apache.org/

二、快速安装

这里以 CentOS 7.X 系统为例:

yum -y install httpd-tools

三、快速使用

查看版本:

[root@7dgroup2 ~]# ab -V
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/

查看帮助:

[root@7dgroup2 ~]# ab help
ab: invalid URL
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
    -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)
[root@7dgroup2 ~]#
  • -n:在测试会话中所执行的请求个数。默认时,仅执行一个请求。
  • -c:一次产生的请求个数。默认是一次一个。
  • -t:测试所进行的最大秒数。其内部隐含值是 -n 50000,它可以使对服务器的测试限制在一个固定的总时间以内。默认时,没有时间限制。

快速上手:

[root@7dgroup2 ~]# ab -n10 -c 10 http://172.17.211.142:8089/
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.17.211.142 (be patient).....done

Server Software:          #服务器软件
Server Hostname:        172.17.211.142 #域名
Server Port:            8089  #请求端口号

Document Path:          /  #文件路径
Document Length:        76443 bytes  #页面字节数

# 这段展示了压力测试的几个重要指标
Concurrency Level:      10  #请求的并发数
Time taken for tests:   0.064 seconds  #总访问时间
Complete requests:      10  #请求成功数量
Failed requests:        0   #请求失败数量
Write errors:           0
Total transferred:      766030 bytes  #请求总数据大小(包括header头信息)
HTML transferred:       764430 bytes  #html页面实际总字节数
Requests per second:    157.09 [#/sec] (mean)   #每秒多少请求,服务器的吞吐量,后面括号中的 mean 表示这是一个平均值
Time per request:       63.656 [ms] (mean)   #用户平均请求等待时间
Time per request:       6.366 [ms] (mean, across all concurrent requests) # 服务器平均处理时间,也就是服务器吞吐量的倒数
Transfer rate:          11751.86 [Kbytes/sec] received  #每秒获取的数据长度

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0   #网络链接
Processing:     8   36  17.1     41      60   #系统处理
Waiting:        3   24  18.7     18      55   #等待
Total:          9   37  17.1     42      60

# Total 并不等于前三行数据相加,因为前三行的数据并不是在同一个请求中采集到的,
#可能某个请求的网络延迟最短,但是系统处理时间又是最长的呢。
#所以 Tota l是从整个请求所需要的时间的角度来统计的。

# 这段是每个请求处理时间的分布情况,50 %的处理时间在4 2 ms内,66 %的处理时间在 45 ms内...,重要的是看 90 %的处理时间。
Percentage of the requests served within a certain time (ms)
  50%     42
  66%     45
  75%     51
  80%     52
  90%     60
  95%     60
  98%     60
  99%     60
 100%     60 (longest request)

四、关于登录的问题

有时候进行压力测试需要用户登录,怎么办?

请参考以下步骤:

  • 先用账户和密码登录后,用开发者工具找到标识这个会话的 Cookie值(Session ID)记下来
  • 如果只用到一个Cookie,那么只需键入命令:

    ab -n 100 -C key=value http://test.com/
    
  • 如果需要多个 Cookie,就直接设 Header:

ab -n 100 -H “Cookie: Key1=Value1; Key2=Value2” http://test.com/

五、总结

总的来说 ab 工具小巧简单,上手学习较快,可以提供需要的基本性能指标,但是没有图形化结果,不能监控。因此 ab 工具可以用作临时和简单测试。
同类型的压力测试工具还有:webbench、siege、http_load 等

参考资料:

目录
相关文章
|
3月前
|
存储 缓存 Cloud Native
云原生时代的架构革新,Apache Doris 存算分离如何实现弹性与性能双重提升
随着云基础设施的成熟,Apache Doris 3.0 正式支持了存算分离全新模式。基于这一架构,能够实现更低成本、极致弹性以及负载隔离。本文将介绍存算分离架构及其优势,并通过导入性能、查询性能、资源成本的测试,直观展现存算分离架构下的性能表现,为读者提供具体场景下的使用参考。
云原生时代的架构革新,Apache Doris 存算分离如何实现弹性与性能双重提升
|
7月前
|
消息中间件 监控 大数据
优化Apache Kafka性能:最佳实践与调优策略
【10月更文挑战第24天】作为一名已经对Apache Kafka有所了解并有实际使用经验的开发者,我深知在大数据处理和实时数据流传输中,Kafka的重要性不言而喻。然而,在面对日益增长的数据量和业务需求时,如何保证系统的高性能和稳定性成为了摆在我们面前的一个挑战。本文将从我的个人视角出发,分享一些关于如何通过合理的配置和调优来提高Kafka性能的经验和建议。
206 4
|
9月前
|
存储 JSON 物联网
查询性能提升 10 倍、存储空间节省 65%,Apache Doris 半结构化数据分析方案及典型场景
本文我们将聚焦企业最普遍使用的 JSON 数据,分别介绍业界传统方案以及 Apache Doris 半结构化数据存储分析的三种方案,并通过图表直观展示这些方案的优势与不足。同时,结合具体应用场景,分享不同需求场景下的使用方式,帮助用户快速选择最合适的 JSON 数据存储及分析方案。
查询性能提升 10 倍、存储空间节省 65%,Apache Doris 半结构化数据分析方案及典型场景
|
9月前
|
存储 大数据 数据挖掘
【数据新纪元】Apache Doris:重塑实时分析性能,解锁大数据处理新速度,引爆数据价值潜能!
【9月更文挑战第5天】Apache Doris以其卓越的性能、灵活的架构和高效的数据处理能力,正在重塑实时分析的性能极限,解锁大数据处理的新速度,引爆数据价值的无限潜能。在未来的发展中,我们有理由相信Apache Doris将继续引领数据处理的潮流,为企业提供更快速、更准确、更智能的数据洞察和决策支持。让我们携手并进,共同探索数据新纪元的无限可能!
320 11
|
10月前
|
Java 持续交付 项目管理
Maven是一款基于Apache许可的项目管理和构建自动化工具,在Java开发中极为流行。
Maven是一款基于Apache许可的项目管理和构建自动化工具,在Java开发中极为流行。它采用项目对象模型(POM)来描述项目,简化构建流程。Maven提供依赖管理、标准构建生命周期、插件扩展等功能,支持多模块项目及版本控制。在Java Web开发中,Maven能够自动生成项目结构、管理依赖、自动化构建流程并运行多种插件任务,如代码质量检查和单元测试。遵循Maven的最佳实践,结合持续集成工具,可以显著提升开发效率和项目质量。
109 1
|
10月前
|
消息中间件 大数据 Kafka
"Apache Flink:重塑大数据实时处理新纪元,卓越性能与灵活性的实时数据流处理王者"
【8月更文挑战第10天】Apache Flink以卓越性能和高度灵活性在大数据实时处理领域崭露头角。它打破批处理与流处理的传统界限,采用统一模型处理有界和无界数据流,提升了开发效率和系统灵活性。Flink支持毫秒级低延迟处理,通过时间窗口、状态管理和自动并行化等关键技术确保高性能与可靠性。示例代码展示了如何使用Flink从Kafka读取实时数据并进行处理,简明扼要地呈现了Flink的强大能力。随着技术进步,Flink将在更多场景中提供高效可靠的解决方案,持续引领大数据实时处理的发展趋势。
155 7
|
10月前
|
安全 搜索推荐 数据挖掘
文件解析的终极工具:Apache Tika
文件解析的终极工具:Apache Tika
1217 0
|
Java 应用服务中间件 Apache
Apache HTTP配置反向代理入门
Apache HTTP配置反向代理入门
540 0
Apache HTTP配置反向代理入门
|
测试技术 Apache Windows
如何使用apache的ab压力测试小工具传参数
该内容是关于在Windows环境下使用PHPStudy中的Apache集成的ab工具进行性能测试的简要教程。
124 9
|
6月前
|
存储 人工智能 大数据
The Past, Present and Future of Apache Flink
本文整理自阿里云开源大数据负责人王峰(莫问)在 Flink Forward Asia 2024 上海站主论坛开场的分享,今年正值 Flink 开源项目诞生的第 10 周年,借此时机,王峰回顾了 Flink 在过去 10 年的发展历程以及 Flink社区当前最新的技术成果,最后展望下一个十年 Flink 路向何方。
560 33
The Past, Present and Future of Apache Flink

推荐镜像

更多
下一篇
oss创建bucket