A simple HTTP performance test tool
Wrk.git
A simple HTTP benchmark tool that can do a lot of basic HTTP performance testing.
A good feature of wrk is that it can use a very small number of threads to press out a lot of concurrency.
The reason is that it uses some operating system-specific high-performance IO mechanisms, such as SELECT, Epoll, Kqueue, and so on.
In fact, it is a reusable Redis AE asynchronous event-driven framework. Specifically, the AE event-driven framework is not invented by Redis, it comes to the TCL interpreter Jim, a compact and efficient framework that is more well known by Redis.
To use WRK, you first need to compile wrk
You need to have Git installed on your machine and a basic C-build environment. The wrk itself is written in C and does not use many third-party libraries. So there's no problem with compiling (it won't be too difficult to run).
Install Mac Installation
brew install wrk
Note: The number of connections on the MAC itself is limited, do not test too much
Linux Installation
clone https://github.com/wg/wrk.gitcd wrkmake
After successful in the directory there is a wrk
file, copy this file to your software directory, configure the environment variables can be, here does not elaborate
Compilation Error Fatalerror:openssl/ssl.h:nosuchfileor Directory
is because the system does not have a library of OpenSSL installed
sudo apt-get install libssl-dev# or runsudo yum install openssl-devel
Use a simple performance test
wrk -t12 -c100 -d30s http://192.168.31.107# 输出为12 threadsand 100 connectionsThreadStats Avg Stdev Max +/- StdeLatency 538.64ms 368.66ms 1.99s 77.33Req/Sec 15.62 10.28 80.00 75.355073 requestsin 30.09s, 75.28MB reaSocketerrors: connect 0, read 5, write 0, timeout 6Requests/sec: 168.5Transfer/sec: 2.50M
- -T12 simulates 100 connections for simulating 12 user threads-c100
The general number of threads should not be excessive. 2 to 4 times times the number of cores is enough, wrk is not using a model that connects one thread to another, but increases concurrency through asynchronous network IO. So network traffic does not block thread execution
Results statistical analysis of thread statistics
Project |
name |
Description |
Avg |
Average |
Average of each test |
Stdev |
Standard deviation |
The higher the degree of dispersion of the result, the more unstable it is. |
Max |
Maximum Value |
The biggest single result |
+/-Stdev |
Plus or minus a standard deviation ratio |
The degree of dispersion of the result, the greater the more unstable |
Latency: Can be understood as response time
Req/sec: The number of requests completed per second for each thread
Generally speaking, we mainly focus on the average and maximum values.
The standard deviation is too large to indicate that the sample itself is relatively discrete. It is possible that system performance fluctuates greatly
Read and Write analysis
- Total number of requests completed
- Read Data volume
- Error statistics
read 5, write 0, timeout 6Requests/sec: 168.5Transfer/sec: 2.50M
WRK Post Interface Test
First you need to prepare a LUA file
"POST"wrk.headers["Content-Type"] = "application/x-www-form-urlencoded"wrk.body = "youbody&youset"
This file content suggested to fill in, Save as post.lua
file
Of course, this script content can be defined again, to see the wrk git document
Execute script
wrk -t4 -c2000 -d60s -T5s --script=post.lua --latency http://192.168.31.107/user/login
This is the simulation of 4 threads, 2000 connections, within 60s, interval 5s execution Post.lua request
- You can scale up and make shell scripts to test various interfaces in bulk
such as Test post JSON:
post.lua--example http POST script which demonstrates setting the--HTTP method, body, and adding a headerwrk.method = "P OST "wrk.body =" {\ "q\": 1} "wrk.headers[" content-type "] =" Application/json "
WRK pressure test HTTP Benchmark Post interface