A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
-bash/zsh: wrk: command not found #Debian apt-get install wrk #Ubuntu apt-get install wrk #Alpine apk add wrk #OS X brew install wrk #Raspbian apt-get install wrk #Docker docker run cmd.cat/wrk wrk
wrk
相对于 ab 命令 来说最大的优点是它支持多线程,可以有更大的并发量。
注意:运行 wrk 的机器必须有足够数量的可用临时端口,并且应该快速回收关闭的套接字。为了处理初始连接突发,服务器的 listen(2) backlog
应该大于正在测试的并发连接数。
wrk -t12 -c400 -d30s http://127.0.0.1:8080/index.html ----------------- Output: 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.
wrk 做压力测试:
wrk -c 100 -d 30m -t 1 -s test/wrk/rand.lua --latency http://localhost/ -- /path/to/rand-str.txt
以上 wrk 命令输出结果:
wrk -c 100 -d 30m -t 1 -s ngx_waf/test/wrk/rand.lua --timeout 1m --latency http://localhost/ -- /usr/local/src/ngx_waf/txt.txt Running 30m test @ http://localhost/ 1 threads and 100 connections Thread Stats Avg Stdev Max +/- Stdev Latency 78.56ms 340.74ms 3.97s 94.52% Req/Sec 67.33k 25.42k 95.38k 86.58% Latency Distribution 50% 1.14ms 75% 1.48ms 90% 4.84ms 99% 1.97s 120532104 requests in 30.00m, 17.06GB read Requests/sec: 66959.26 Transfer/sec: 9.71MB