使用ab 进行并发压力测试

ab全称为:apache bench。

是apache自带的压力测试工具。ab非常实用,它不仅可以对apache服务器进行网站访问压力测试,也可以对或其它类型的服务器进行压力测试。比如nginx、tomcat、IIS等。

 

安装ab命令:

ubuntu:

sudo apt-get install apache2-utils

centos:

yum install apr-util

# 安装依赖 yum-utils中的yumdownload 工具
# 如果没有找到 yumdownload 命令可以
yum install yum-utils

 

使用:

简单使用说明
1. 最基本的关心两个选项 -c -n
例: ab -n 1000 -c 100 http://www.baidu.com/

-n 1000 即: 共发送1000个请求
-c 100 即:每次并发100个

 

测试结果:

命令:ab -n 1000 -c 1000 http://www.test.net/switch/get

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

Benchmarking www.test.net(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.2
Server Hostname:        www.test.net
Server Port:            80

Document Path:          /switch/get
Document Length:        85 bytes

Concurrency Level:      1000
Time taken for tests:   2.296 seconds
Complete requests:      1000
Failed requests:        170
   (Connect: 0, Receive: 0, Length: 170, Exceptions: 0)
Non-2xx responses:      170
Total transferred:      496990 bytes
HTML transferred:       103360 bytes
Requests per second:    435.62 [#/sec] (mean)
Time per request:       2295.555 [ms] (mean)
Time per request:       2.296 [ms] (mean, across all concurrent requests)
Transfer rate:          211.43 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       15  132  47.7    145     201
Processing:    89  428 225.7    382    2121
Waiting:       85  358 223.0    293    2121
Total:        198  559 233.0    512    2286

Percentage of the requests served within a certain time (ms)
  50%    512
  66%    603
  75%    697
  80%    751
  90%    850
  95%    910
  98%    935
  99%   1243
 100%   2286 (longest request)

 

结果分析:

服务器信息:

  采用nginx服务器,域名是www.test.net,端口号80端口。

Server Software:        nginx/1.10.2
Server Hostname:        www.test.net
Server Port:            80

文档信息:

  文档路径/switch/get,文档长度85字节(http响应的正文长度)

Document Path:          /switch/get
Document Length:        85 bytes

重要指标:

  Concurrency Level: 1000  // 1000个并发请求

  Time taken for tests: 2.296 seconds  // 整个测试持续时间

  Complete requests: 1000  // 完成了1000个请求

  Failed requests: 170 (Connect: 0, Receive: 0, Length: 170, Exceptions: 0)  // 失败的请求数170

  Non-2xx responses: 170  // 170个不是2开头的响应码,比如缓存的304

  Total transferred: 496990 bytes  // 整个场景中的网络传输量

  HTML transferred: 103360 bytes  // 整个场景中的HTML内容传输量

  Requests per second: 435.62 [#/sec] (mean)

  // 吞吐率(大家最关心的指标之一)

  服务器并发处理能力的量化描述,单位是reqs/s,指的是在某个并发用户数下单位时间内处理的请求数。某个并发用户数下单位时间内能处理的最大请求数,称之为最大吞吐率。

  记住:吞吐率是基于并发用户数的。这句话代表了两个含义:

  a、吞吐率和并发用户数相关

  b、不同的并发用户数下,吞吐率一般是不同的

  计算公式:总请求数/处理完成这些请求数所花费的时间,即

  Request per second=Complete requests/Time taken for tests

  必须要说明的是,这个数值表示当前机器的整体性能,值越大越好。

  Time per request: 2295.555 [ms] (mean)

   // 用户平均请求等待时间,大家最关心的指标之二

  计算公式:处理完成所有请求数所花费的时间/(总请求数/并发用户数)

  Time per request: 2.296 [ms] (mean, across all concurrent requests)

  // 服务器平均请求处理时间,大家最关心的指标之三

  计算公式:处理完成所有请求数所花费的时间/总请求数

  Transfer rate: 211.43 [Kbytes/sec] received  // 平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题

Concurrency Level:      1000
Time taken for tests:   2.296 seconds
Complete requests:      1000
Failed requests:        170
   (Connect: 0, Receive: 0, Length: 170, Exceptions: 0)
Non-2xx responses:      170
Total transferred:      496990 bytes
HTML transferred:       103360 bytes
Requests per second:    435.62 [#/sec] (mean)
Time per request:       2295.555 [ms] (mean)
Time per request:       2.296 [ms] (mean, across all concurrent requests)
Transfer rate:          211.43 [Kbytes/sec] received

 网络上消耗的时间的分解:

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       15  132  47.7    145     201
Processing:    89  428 225.7    382    2121
Waiting:       85  358 223.0    293    2121
Total:        198  559 233.0    512    2286

每个请求处理时间的分布情况,50%的处理时间在512ms内,66%的处理时间在603ms内...,重要的是看90%的处理时间:

Percentage of the requests served within a certain time (ms)
  50%    512
  66%    603
  75%    697
  80%    751
  90%    850
  95%    910
  98%    935
  99%   1243
 100%   2286 (longest request)

 

posted @ 2018-01-26 19:23  参与商  阅读(14229)  评论(0编辑  收藏  举报