1
0
mirror of https://github.com/wg/wrk synced 2025-03-09 23:17:19 +08:00

add a few example scripts

This commit is contained in:
Will 2013-12-07 14:09:44 +09:00
parent 7763ce3c9b
commit 44aa1b4aab
7 changed files with 51 additions and 2 deletions

View File

@ -43,7 +43,7 @@ $(OBJ): config.h Makefile $(LDIR)/libluajit.a | $(ODIR)
$(ODIR): $(ODIR):
@mkdir -p $@ @mkdir -p $@
$(ODIR)/bytecode.o: scripts/wrk.lua $(ODIR)/bytecode.o: src/wrk.lua
@echo LUAJIT $< @echo LUAJIT $<
@$(SHELL) -c 'cd $(LDIR) && ./luajit -b $(CURDIR)/$< $(CURDIR)/$@' @$(SHELL) -c 'cd $(LDIR) && ./luajit -b $(CURDIR)/$< $(CURDIR)/$@'

3
README
View File

@ -5,7 +5,8 @@ wrk - a HTTP benchmarking tool
design with scalable event notification systems such as epoll and kqueue. design with scalable event notification systems such as epoll and kqueue.
An optional LuaJIT script can perform HTTP request generation, response An optional LuaJIT script can perform HTTP request generation, response
processing, and custom reporting. processing, and custom reporting. Several example scripts are located in
scripts/
Basic Usage Basic Usage

18
scripts/auth.lua Normal file
View File

@ -0,0 +1,18 @@
-- example script that demonstrates response handling and
-- retrieving an authentication token to set on all future
-- requests
token = nil
path = "/authenticate"
request = function()
return wrk.format("GET", path)
end
response = function(status, headers, body)
if not token and status == 200 then
token = headers["X-Token"]
path = "/resource"
wrk.headers["X-Token"] = token
end
end

14
scripts/counter.lua Normal file
View File

@ -0,0 +1,14 @@
-- example dynamic request script which demonstrates changing
-- the request path and a header for each request
-------------------------------------------------------------
-- NOTE: each wrk thread has an independent Lua scripting
-- context and thus there will be one counter per thread
counter = 0
request = function()
path = "/" .. counter
wrk.headers["X-Counter"] = counter
counter = counter + 1
return wrk.format(nil, path)
end

6
scripts/post.lua Normal file
View File

@ -0,0 +1,6 @@
-- example HTTP POST script which demonstrates setting the
-- HTTP method, body, and adding a header
wrk.method = "POST"
wrk.body = "foo=bar&baz=quux"
wrk.headers["Content-Type"] = "application/x-www-form-urlencoded"

10
scripts/report.lua Normal file
View File

@ -0,0 +1,10 @@
-- example reporting script which demonstrates a custom
-- done() function that prints latency percentiles as CSV
done = function(summary, latency, requests)
io.write("------------------------------\n")
for _, p in pairs({ 50, 90, 99, 99.999 }) do
n = latency:percentile(p)
io.write(string.format("%g%%,%d\n", p, n))
end
end