桃之夭夭,灼灼其华

ab / awk 并发测试工具

Word count: 607Reading time: 2 min
2020/08/28 Share

ab

  • -n 执行的请求个数,默认时执行一个请求

  • -c 一次产生的请求个数,即并发个数

  • -p:模拟post请求,文件格式为gid=2&status=1,配合-T使用

  • -T:post数据所使用的Content-Type头信息,如果-T ‘application/x-www-form-urlencoded’

  • 模拟get请求

    1
    ab -n 10 -c 10 http://www.baidu.com/
  • 模拟post请求
    在当前目录下创建一个文件post.txt,编辑文件post.txt写入cid=4&status=1相当于post传递cid,status参数.

    1
    2
    3
    ab -n 100  -c 10 -p 'post.txt' -T 'application/x-www-form-urlencoded' 'http://test.api.com/ttk/auth/info/'

    ab -n50 -c20 -p 'post.txt' -T 'application/json' 'http://192.168.250.79:9081/admin/letsapi/attendance/jwdownworkdatarelay'

    617A271D-84FE-4E85-9B12-98BF4F3B4BF9.png

awk

  • awk 命令
    1
    2
    ## 查看awk 版本
    awk -v
    02FDF235-4384-4AD4-AEDF-51378E8E685D.png
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    使用方法: wrk <选项> <被测HTTP服务的URL>
    Options:
    -c, --connections <N> 跟服务器建立并保持的TCP连接数量
    -d, --duration <T> 压测时间
    -t, --threads <N> 使用多少个线程进行压测
    -s, --script <S> 指定Lua脚本路径
    -H, --header <H> 为每一个HTTP请求添加HTTP头
    --latency 在压测结束后,打印延迟统计信息
    --timeout <T> 超时时间
    -v, --version 打印正在使用的wrk的详细版本信息

    <N>代表数字参数,支持国际单位 (1k, 1M, 1G)
    <T>代表时间参数,支持时间单位 (2s, 2m, 2h)
  • 用例
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    ➜ wrk -t12 -c400 -d30s --latency http://www.baidu.com
    Running 30s test @ http://www.baidu.com
    12 threads and 400 connections
    Thread Stats Avg Stdev Max +/- Stdev
    Latency 262.15ms 284.99ms 2.00s 87.28%
    Req/Sec 80.55 47.39 222.00 58.48%
    Latency Distribution
    50% 113.91ms
    75% 307.85ms
    90% 634.01ms
    99% 1.41s
    28122 requests in 30.09s, 418.67MB read
    Socket errors: connect 158, read 59, write 0, timeout 112
    Requests/sec: 934.65
    Transfer/sec: 13.91MB
    解释
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    Running 30s test @ http://www.baidu.com(压测时间30s)
    12 threads and 400 connections(共12个测试线程,400个连接)
    Thread Stats Avg Stdev Max +/- Stdev
    (平均值) (标准差)(最大值)(正负一个标准差所占比例)
    Latency 933.14ms 415.00ms 2.00s 77.56%
    (延迟)
    Req/Sec 24.77 15.65 121.00 70.04%
    (处理中的请求数)
    Latency Distribution (延迟分布)
    50% 711.85ms
    75% 1.24s
    90% 1.56s
    99% 1.90s (99分位的延迟)
    8181 requests in 30.10s, 121.83MB read(30.10秒内共处理完成了8181个请求,读取了121.83MB数据)
    Socket errors: connect 0, read 0, write 0, timeout 1545
    Requests/sec: 271.82 (平均每秒处理完成271.82个请求)
    Transfer/sec: 4.05MB (平均每秒读取数据4.05MB)
CATALOG
  1. 1. ab
  2. 2. awk