From 1a8022ab34eeab9f7b4e09967229f3a3977bf9dd Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Wed, 31 May 2023 20:39:06 +0200 Subject: [PATCH] chore: add benchmarking --- README.md | 19 +++++++++++++++++++ bench/get.lua | 13 +++++++++++++ bench/post.lua | 24 ++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 bench/get.lua create mode 100644 bench/post.lua diff --git a/README.md b/README.md index 9f712ca..fcdf32f 100644 --- a/README.md +++ b/README.md @@ -20,3 +20,22 @@ requesting a redirect. This makes the server very fast. I gave up giving my projects original names a long time ago, so now I just use the names of my friends ;p + +## Benchmarking + +I benchmark this tool using the [`wrk2`](https://github.com/giltene/wrk2) +utility. I've provided two Lua scripts to aid with this. To bench publishing +redirects, use the following: + +```sh +wrk2 -s bench/post.lua -t 10 -R 10k -d30s -c32 http://localhost:18080 +``` + +And to bench GET requests: + +```sh +wrk2 -s bench/get.lua -t 10 -R 25k -d30s -c32 http://localhost:18080 +``` + +Of course you're free to change the parameters, but the provided Lua files +generate URLs that can be used in the benchmark. diff --git a/bench/get.lua b/bench/get.lua new file mode 100644 index 0000000..f9a3359 --- /dev/null +++ b/bench/get.lua @@ -0,0 +1,13 @@ +chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + +request = function() + + path = "/" + + for i = 1,4 do + local rint = math.random(1, #chars) + path = path .. chars:sub(rint, rint) + end + + return wrk.format(nil, path) +end diff --git a/bench/post.lua b/bench/post.lua new file mode 100644 index 0000000..84879e7 --- /dev/null +++ b/bench/post.lua @@ -0,0 +1,24 @@ +chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + +request = function() + path = "/s/" + + -- for i = 1,16 do + -- local rint = math.random(1, #chars) + -- path = path .. chars:sub(rint, rint) + -- end + + body = "https://example.com/" + + for i = 1,32 do + local rint = math.random(1, #chars) + body = body .. chars:sub(rint, rint) + end + + wrk.path = path + wrk.method = "POST" + wrk.body = body + wrk.headers["X-Api-Key"] = "test" + + return wrk.format() +end