I’ve been working on server-side performance optimization lately, and the rigor of QPS (query rate per second) has impressed upon me, a former Node.js blogger, that everything I’ve done is a toy. So I have been trying to understand some knowledge of pressure measurement recently. Jmeter, LoadRunner, TCPCopy, Apache Bench, WRK (2) and so on are commonly used in the industry. As a pressure test white, combined with the actual situation of the project (no hardware monitoring, simple test request), I chose to use WRK2. This article has recorded some experience in using the process.
Introduction of WRK
Wrk2 evolved from WRK, so let’s look at the use of WRK first. WRK is similar in type to Apache Bench (ab) in that it is an on-terminal tool designed to generate requests using multiple threads. Compared to AB, WRK is most notable for its custom scripting capabilities: WRK supports HTTP request generation, response processing, and custom pressure reporting using Lua scripts. WRK is also very simple in terms of basic configuration items:
$ wrkWRK 4.1.0 [kqueue] Copyright (C) 2012 Will Glozer Usage: WRK <options> <url> options: C, --connections <N> connections to keep open --duration <T> duration of test Number of threads -t, --threads <N> Number of threads to use -s, --script < s > Load lua script file # WRK "-h, --header <H> Add header to request # latency Print latency statistics - Timeout <T> Socket/request timeoutCopy the code
To open the url http://127.0.0.1:8080/index.html 12 threads, open 400 HTTP connection, lasts 30 s pressure measurement, can be expressed as follows:
WRK - t12 - c400 - d30s http://127.0.0.1:8080/index.htmlCopy the code
The content of the report produced after the pressure test is also more detailed, which is concerned about some data of the pressure tester, such as delay distribution, QPS, etc., which will not be repeated here.
Custom script function
If WRK’s usual functionality is not sufficient, then you need to write your own scripts to handle it. WRK provides some sample scripts for your reference. Of course, first we need to master the basic Lua syntax, and then we need to refer to the Lua interface exposed by WRK. WRK exposes many methods in the setup, RUNNING, and Done declaration cycles for thread configuration, request and response processing, and custom display of the resulting test report. Combined with scripting, WRK can accomplish a considerable degree of complex pressure measurement requirements. Many WRK tutorials don’t elaborate on this, but I think it’s the best part of WRK. You should be familiar with the use of custom scripts if you want to get comfortable with them.
For example, if you want to add a delay per request, you can set it in the delay function exposed by WRK:
function delay(a)
return math.random(10.50)
end
Copy the code
If you want to pressure post requests, you can set the table WRK:
wrk.method = "POST"
wrk.body = "foo=bar&baz=quux"
wrk.headers["Content-Type"] = "application/x-www-form-urlencoded"
Copy the code
wrk2
Wrk2 is an evolution of WRK, which claims to provide stable throughput and more accurate latency statistics. This is reflected in the addition of the –rate parameter for setting throughput and –u_latency parameter for displaying incorrect (statistically significant) latency statistics. Other uses of WRK2 are not very different from WRK, is a more complete tool. Of course wrK2’s author is very modest and shows great respect for WRK.
To the end.
This article was first published on my blog (click here to view it).