34.9k star,推荐一款使用工具,wrk

1 简介

wrk,一款http协议的压测工具,能够在单个多核 CPU 上运行时产生大量负载。它将多线程设计与可扩展的事件通知系统(如 epoll 和 kqueue)相结合。

​ 34.9k star,推荐一款使用工具,wrk_html
高级功能可以通过lua脚本完成,可选的 LuaJIT 脚本可以执行 HTTP 请求生成、响应处理和自定义报告。

2 安装

github可以访问的直接到如下链接去下载就可以,目前支持linux

 https://github.com/wg/wrk

github如果无法访问的话,可以后台直接私信

3 示例:

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

这将运行基准测试30秒,使用12个线程,并保持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
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.

命令参数:

-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.
                   
                   
            
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.

4 注意项

运行 wrk 的机器必须具有足够数量的临时端口,并且应快速回收关闭的套接字。为了处理初始连接突发,服务器的侦听(2)积压工作应该大于正在测试的并发连接数。

仅更改 HTTP 方法、路径、添加标头或正文的用户脚本不会影响性能。每个请求的操作,特别是构建新的 HTTP 请求,以及使用 response() 必然会减少可以生成的负载量。

注:如需转载,须保留文首公众号名片,其它行为一律视为非授权转载。