Mercurial
comparison third_party/wrk/SCRIPTING @ 178:94705b5986b3
[ThirdParty] Added WRK and luajit for load testing.
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Thu, 22 Jan 2026 20:10:30 -0800 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 177:24fe8ff94056 | 178:94705b5986b3 |
|---|---|
| 1 Overview | |
| 2 | |
| 3 wrk supports executing a LuaJIT script during three distinct phases: setup, | |
| 4 running, and done. Each wrk thread has an independent scripting environment | |
| 5 and the setup & done phases execute in a separate environment which does | |
| 6 not participate in the running phase. | |
| 7 | |
| 8 The public Lua API consists of a global table and a number of global | |
| 9 functions: | |
| 10 | |
| 11 wrk = { | |
| 12 scheme = "http", | |
| 13 host = "localhost", | |
| 14 port = nil, | |
| 15 method = "GET", | |
| 16 path = "/", | |
| 17 headers = {}, | |
| 18 body = nil, | |
| 19 thread = <userdata>, | |
| 20 } | |
| 21 | |
| 22 function wrk.format(method, path, headers, body) | |
| 23 | |
| 24 wrk.format returns a HTTP request string containing the passed parameters | |
| 25 merged with values from the wrk table. | |
| 26 | |
| 27 function wrk.lookup(host, service) | |
| 28 | |
| 29 wrk.lookup returns a table containing all known addresses for the host | |
| 30 and service pair. This corresponds to the POSIX getaddrinfo() function. | |
| 31 | |
| 32 function wrk.connect(addr) | |
| 33 | |
| 34 wrk.connect returns true if the address can be connected to, otherwise | |
| 35 it returns false. The address must be one returned from wrk.lookup(). | |
| 36 | |
| 37 The following globals are optional, and if defined must be functions: | |
| 38 | |
| 39 global setup -- called during thread setup | |
| 40 global init -- called when the thread is starting | |
| 41 global delay -- called to get the request delay | |
| 42 global request -- called to generate the HTTP request | |
| 43 global response -- called with HTTP response data | |
| 44 global done -- called with results of run | |
| 45 | |
| 46 Setup | |
| 47 | |
| 48 function setup(thread) | |
| 49 | |
| 50 The setup phase begins after the target IP address has been resolved and all | |
| 51 threads have been initialized but not yet started. | |
| 52 | |
| 53 setup() is called once for each thread and receives a userdata object | |
| 54 representing the thread. | |
| 55 | |
| 56 thread.addr - get or set the thread's server address | |
| 57 thread:get(name) - get the value of a global in the thread's env | |
| 58 thread:set(name, value) - set the value of a global in the thread's env | |
| 59 thread:stop() - stop the thread | |
| 60 | |
| 61 Only boolean, nil, number, and string values or tables of the same may be | |
| 62 transfered via get()/set() and thread:stop() can only be called while the | |
| 63 thread is running. | |
| 64 | |
| 65 Running | |
| 66 | |
| 67 function init(args) | |
| 68 function delay() | |
| 69 function request() | |
| 70 function response(status, headers, body) | |
| 71 | |
| 72 The running phase begins with a single call to init(), followed by | |
| 73 a call to request() and response() for each request cycle. | |
| 74 | |
| 75 The init() function receives any extra command line arguments for the | |
| 76 script which must be separated from wrk arguments with "--". | |
| 77 | |
| 78 delay() returns the number of milliseconds to delay sending the next | |
| 79 request. | |
| 80 | |
| 81 request() returns a string containing the HTTP request. Building a new | |
| 82 request each time is expensive, when testing a high performance server | |
| 83 one solution is to pre-generate all requests in init() and do a quick | |
| 84 lookup in request(). | |
| 85 | |
| 86 response() is called with the HTTP response status, headers, and body. | |
| 87 Parsing the headers and body is expensive, so if the response global is | |
| 88 nil after the call to init() wrk will ignore the headers and body. | |
| 89 | |
| 90 Done | |
| 91 | |
| 92 function done(summary, latency, requests) | |
| 93 | |
| 94 The done() function receives a table containing result data, and two | |
| 95 statistics objects representing the per-request latency and per-thread | |
| 96 request rate. Duration and latency are microsecond values and rate is | |
| 97 measured in requests per second. | |
| 98 | |
| 99 latency.min -- minimum value seen | |
| 100 latency.max -- maximum value seen | |
| 101 latency.mean -- average value seen | |
| 102 latency.stdev -- standard deviation | |
| 103 latency:percentile(99.0) -- 99th percentile value | |
| 104 latency(i) -- raw value and count | |
| 105 | |
| 106 summary = { | |
| 107 duration = N, -- run duration in microseconds | |
| 108 requests = N, -- total completed requests | |
| 109 bytes = N, -- total bytes received | |
| 110 errors = { | |
| 111 connect = N, -- total socket connection errors | |
| 112 read = N, -- total socket read errors | |
| 113 write = N, -- total socket write errors | |
| 114 status = N, -- total HTTP status codes > 399 | |
| 115 timeout = N -- total request timeouts | |
| 116 } | |
| 117 } |