linux-压力测试工具

1. wrk 

官网:https://github.com/wg/wrk

wrk是一种现代HTTP基准测试工具,能够在单个多核CPU上运行时产生大量负载。它结合了多线程设计和可扩展的事件通知系统,如epoll和kqueue。

可选的LuaJIT脚本可以执行HTTP请求生成,响应处理和自定义报告。SCRIPTING中提供了详细信息,并且脚本/中有几个示例。

macOS安装方法:

$ brew install wrk

使用方法:

wrk -t12 -c400 -d30s http://127.0.0.1:8080/index.html

这将使用12个线程运行30秒的基准测试,并保持打开400个HTTP连接。

输出:

Running 30s test @ http://127.0.0.1:8080/index.html
  12 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   635.91us    0.89ms  12.92ms   93.69%
    Req/Sec    56.20k     8.07k   62.00k    86.54%
  22464657 requests in 30.00s, 17.76GB read
Requests/sec: 748868.53
Transfer/sec:    606.33MB

命令行选项

-c, --connections: total number of HTTP connections to keep open with
                   each thread handling N = connections/threads

-d, --duration:    duration of the test, e.g. 2s, 2m, 2h

-t, --threads:     total number of threads to use

-s, --script:      LuaJIT script, see SCRIPTING

-H, --header:      HTTP header to add to request, e.g. "User-Agent: wrk"

    --latency:     print detailed latency statistics

    --timeout:     record a timeout if a response is not received within
                   this amount of time.

2. fortio

官网:https://github.com/fortio/fortio

安装:

 brew install fortio

1. 通过两个并发连接(-c 2)调用服务,并发送20个请求(-n 20):

fortio load -c 2 -qps 0 -n 20 http://h1.test.com/
Fortio 1.3.1 running at 0 queries per second, 8->8 procs, for 20 calls: http://h1.test.com/
15:59:47 I httprunner.go:82> Starting http test for http://h1.test.com/ with 2 threads at -1.0 qps
Starting at max qps with 2 thread(s) [gomax 8] for exactly 20 calls (10 per thread + 0)
15:59:48 I periodic.go:533> T000 ended after 19.844964ms : 10 calls. qps=503.90617992554684
15:59:48 I periodic.go:533> T001 ended after 28.971601ms : 10 calls. qps=345.1655985459692
Ended after 29.021413ms : 20 calls. qps=689.15
Aggregated Function Time : count 20 avg 0.002392177 +/- 0.001016 min 0.001405494 max 0.005253498 sum 0.047843539
# range, mid point, percentile, count
>= 0.00140549 <= 0.002 , 0.00170275 , 45.00, 9
> 0.002 <= 0.003 , 0.0025 , 80.00, 7
> 0.003 <= 0.004 , 0.0035 , 90.00, 2
> 0.004 <= 0.005 , 0.0045 , 95.00, 1
> 0.005 <= 0.0052535 , 0.00512675 , 100.00, 1
# target 50% 0.00214286
# target 75% 0.00285714
# target 90% 0.004
# target 99% 0.0052028
# target 99.9% 0.00524843
Sockets used: 2 (for perfect keepalive, would be 2)
Code 200 : 20 (100.0 %)
Response Header Sizes : count 20 avg 241 +/- 0 min 241 max 241 sum 4820
Response Body/Total Sizes : count 20 avg 853 +/- 0 min 853 max 853 sum 17060
All done 20 calls (plus 0 warmup) 2.392 ms avg, 689.1 qps

3. h2load

支持http2性能测试。在nghttp2 工具中包括测试工具称为h2load

安装方法:

brew install nghttp2

测试:

$ h2load --client=10 --requests=100 https://h1.test.com/
starting benchmark...
spawning thread #0: 10 total client(s). 100 total requests
TLS Protocol: TLSv1.2
Cipher: ECDHE-RSA-AES128-GCM-SHA256
Server Temp Key: ECDH P-256 256 bits
Application protocol: h2
progress: 10% done
progress: 20% done
progress: 30% done
progress: 40% done
progress: 50% done
progress: 60% done
progress: 70% done
progress: 80% done
progress: 90% done
progress: 100% done

finished in 116.24ms, 860.28 req/s, 203.56KB/s
requests: 100 total, 100 started, 100 done, 21 succeeded, 79 failed, 0 errored, 0 timeout
status codes: 21 2xx, 0 3xx, 0 4xx, 79 5xx
traffic: 23.66KB (24230) total, 2.38KB (2440) headers (space savings 81.52%), 18.80KB (19251) data
                     min         max         mean         sd        +/- sd
time for request:      487us      7.51ms      2.35ms      1.25ms    73.00%
time for connect:    14.36ms     90.20ms     81.17ms     23.51ms    90.00%
time to 1st byte:    15.76ms     94.47ms     85.93ms     24.66ms    90.00%
req/s           :      86.34      454.23      124.38      115.90    90.00%

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值