http benchmark - downgoon/hello-world GitHub Wiki

单独安装 apache ab

开发人员临时简单做性能测试,过去通常用Apache ab,但是它不方便单独安装。有个替代品就是 webbench,它安装简单。不过功能不如 apache ab

勘误

早前单独安装apache ab确实不方便,但后来有人做贡献了,一条命令就安装好。

$ yum install httpd-tools

因为Apache的后台进程叫httpd,压力测试ab是它的附属工具,所以人家命名叫httpd-tools。安装完后,/usr/bin/ab可执行文件。

测试: 4个并发,100个请求,http://10.213.42.230/yunpan/

$ ab -c 4 -n 100 http://10.213.42.230/yunpan/

结果:

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

Benchmarking 10.213.42.230 (be patient).....done


Server Software:        nginx/1.8.0
Server Hostname:        10.213.42.230
Server Port:            80

Document Path:          /yunpan/
Document Length:        1916 bytes

Concurrency Level:      4
Time taken for tests:   0.014 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      203700 bytes
HTML transferred:       191600 bytes
Requests per second:    7003.78 [#/sec] (mean)
Time per request:       0.571 [ms] (mean)
Time per request:       0.143 [ms] (mean, across all concurrent requests)
Transfer rate:          13932.33 [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.1      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)
  • 压力状态

4个并发,总共完成 100个请求,相当于每个并发分担25个请求。

Concurrency Level: 4 Time taken for tests: 0.014 seconds Complete requests: 100

  • 性能指标

Requests per second: 7003.78 [#/sec] (mean) Time per request: 0.571 [ms] (mean) Time per request: 0.143 [ms] (mean, across all concurrent requests) Transfer rate: 13932.33 [Kbytes/sec] received

QPS吞吐量: 平均每秒处理7千个请求。 时延:0.571 ms / 0.143 ms 数据量: 每秒 13932.33 KB


webbench 安装

安装

在 Linux 和 Mac 下都可以安装:

wget https://github.com/downgoon/hello-world/files/829959/webbench-1.5.tar.gz
tar zxvf webbench-1.5.tar.gz && cd webbench-1.5
make && make install

说明

  1. 无需 ./configure,直接 make && make install 安装。
  2. 如果提示 "`/usr/local/man/man1': No such file or directory" ,只需手动创建 mkdir -p /usr/local/man/man1即可。

使用

webbench -c 10 http://10.213.42.230/yunpan/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://10.213.42.230/yunpan/
10 clients, running 30 sec.

Speed=4212 pages/min, 142997 bytes/sec.
Requests: 2106 susceed, 0 failed.

看帮助:

$ ./webbench
webbench [option]... URL
  -f|--force               Don't wait for reply from server.
  -r|--reload              Send reload request - Pragma: no-cache.
  -t|--time <sec>          Run benchmark for <sec> seconds. Default 30.
  -p|--proxy <server:port> Use proxy server for request.
  -c|--clients <n>         Run <n> HTTP clients at once. Default one.
  -9|--http09              Use HTTP/0.9 style requests.
  -1|--http10              Use HTTP/1.0 protocol.
  -2|--http11              Use HTTP/1.1 protocol.
  --get                    Use GET request method.
  --head                   Use HEAD request method.
  --options                Use OPTIONS request method.
  --trace                  Use TRACE request method.
  -?|-h|--help             This information.
  -V|--version             Display program version.

资料

⚠️ **GitHub.com Fallback** ⚠️