ab-Apache HTTP服务器基准测试工具

http://httpd.apache.org/docs/2.0/programs/ab.html 

ab是用于对Apache超文本传输​​协议(HTTP)服务器进行基准测试的工具。它旨在使您对当前的Apache安装如何执行有一个印象。这尤其向您显示Apache安装每秒能够处理多少个请求。

概要

ab [ -A auth-username:password ] [ -c concurrency ] [ -C cookie-name=value ] [ -d ] [ -e csv-file ] [ -g gnuplot-file ] [ -h ] [ -H custom-header ] [ -i ] [ -k ] [ -n requests ] [ -p POST-file ] [ -P proxy-auth-username:password ] [ -q ] [ -s ] [ -S ] [ -t timelimit ] [ -T content-type ] [ -v verbosity] [ -V ] [ -w ] [ -x <table>-attributes ] [ -X proxy[:port] ] [ -y <tr>-attributes ] [ -z <td>-attributes ] [http://]hostname[:port]/path

选项

-A auth-username:password

向服务器提供BASIC身份验证凭据。用户名和密码用单个分隔,:并通过编码为base64的网络发送。无论服务器是否需要该字符串,都将发送该字符串(,已发送所需的401身份验证)。

-c concurrency

一次执行的多个请求的数量。默认值为一次一个请求。

-C cookie-name=value

Cookie:在请求中添加一行。参数通常为一 对形式。该字段是可重复的。name=value

-d

不要显示“ XX [ms]表中的投放百分比”。(旧版支持)。

-e csv-file

编写一个逗号分隔值(CSV)文件,其中包含每个百分比(从1%到100%)的服务该百分比请求所花费的时间(以毫秒为单位)。通常,它比“ gnuplot”文件有用。因为结果已经“装箱”了。

-g gnuplot-file

将所有测量值写为“ gnuplot”或TSV(制表符单独值)文件。此文件可以轻松导入到Gnuplot,IDL,Mathematica,Igor甚至Excel等软件包中。标签位于文件的第一行。

-h

显示使用情况信息。

-H custom-header

将额外的标头添加到请求。该参数是典型地在一个有效报头线的形式,含有一个冒号分隔的字段值对("Accept-Encoding: zip/zop;8bit")。

-i

HEAD请求,而不是GET

-k

启用HTTP KeepAlive功能,在一个HTTP会话中执行多个请求。默认为no KeepAlive。

-n requests

为基准测试会话执行的请求数。默认设置是仅执行一个请求,这通常会导致非代表性的基准测试结果。

-p POST-file

包含要发布的数据的文件。

-P proxy-auth-username:password

在代理途中提供BASIC身份验证凭据。用户名和密码用单个分隔,:并通过编码为base64的网络发送。不管代理是否需要它都将发送该字符串(,已发送了所需的407代理身份验证)。

-q

当处理150个以上的请求时,每10%或100个左右的请求ab输出进度计数stderr。该 -q标志将禁止显示这些消息。

-s

编译为(ab -h将向您显示)时,请使用SSL保护https而不是http协议。此功能是实验性的,非常基础。您可能不想使用它。

-S

当平均值和中位数相距标准偏差的一倍或两倍以上时,请勿显示中位数和标准偏差值,也不会显示警告/错误消息。并默认为最小值/平均值/最大值。(旧版支持)。

-t timelimit

用于基准测试的最大秒数。这意味着 -n 50000内部。使用它在固定的总时间内对服务器进行基准测试。默认情况下没有时间限制。

-T content-type

用于POST数据的内容类型标头。

-v verbosity

设置详细级别-4上方将在标题上显示信息,3上方将显示响应代码(404、200等), 2上方将显示警告和信息。

-V

显示版本号并退出。

-w

在HTML表格中打印出结果。默认表是两列宽,带有白色背景。

-x <table>-attributes

用作的属性的字符串<table>。插入属性。<table here >

-X proxy[:port]

使用代理服务器处理请求。

-y <tr>-attributes

用作的属性的字符串<tr>

-z <td>-attributes

用作的属性的字符串<td>

 

BUG

有各种固定长度的静态声明的缓冲区。与命令行参数的延迟解析,服务器的响应标头以及其他外部输入相结合,这可能会给您带来麻烦。它没有完全实现HTTP / 1.x。仅接受某些“预期”形式的回复。strstr(3)概要文件顶部的大量使用显示可能表明性能存在问题;,您将衡量ab性能而不是服务器的性能。

并发压测示例

发送1000个http get请求到[http://192.168.10.232:8000/blog,并发为10]:

$ ab -n1000 -c10 http://localhost/
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (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:        nginx/1.10.3
Server Hostname:        localhost
Server Port:            80

Document Path:          /
Document Length:        11321 bytes

Concurrency Level:      10
Time taken for tests:   0.066 seconds
Complete requests:      1000
Failed requests:        0
Total transferred:      11566000 bytes
HTML transferred:       11321000 bytes
Requests per second:    15207.74 [#/sec] (mean)
Time per request:       0.658 [ms] (mean)
Time per request:       0.066 [ms] (mean, across all concurrent requests)
Transfer rate:          171770.21 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       0
Processing:     0    0   0.1      0       1
Waiting:        0    0   0.2      0       1
Total:          0    1   0.1      1       1

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      1
  99%      1
 100%      1 (longest request)

注意Time per request: 0.658 [ms] (mean)是平均每批请求的完成时间,这里时10个请求完成的时间。Time per request: 0.066 [ms] (mean, across all concurrent requests)是平均每个请求的完成时间。

ApacheBench将只使用一个操作系统线程。很多情况下ApacheBench本身是瓶颈。当在硬件具有多个处理器核心使用ApacheBench,建议一个cpu核执行一个ab线程,但是现在cpu核数很多的情况下,比如48核,手工执行48个命令也是个体力活。

整体来说ab因为不能利用到多核、不能进行参数化、不支持http和https以外的协议等原因,只适合单个组件的粗略测试,比如Apache http。不合适业务级别的测试,如一旦后台有数据库等,ab的测试是几乎没有意义的。

猜你喜欢

转载自blog.csdn.net/boonya/article/details/109684160
今日推荐