Files
urus-benches/loadgen/_diag_status.lua
T
sandbox-agent 943080805c loadgen: fix two latent lua bugs that voided every wrk run
Root cause of the ~100% non-2xx benchmark: the load scripts never actually
ran. Two stacked failures, each of which makes wrk silently fall back to its
built-in default request (GET / with no auth -> 401 -> 100% non-2xx):

1. require('common') failed: wrk runs with cwd at the repo root, where
   common.lua (in loadgen/) is not on package.path. Now each script prepends
   its own directory (via debug.getinfo source) before requiring.
2. os.getpid() is not in luajit's os library (wrk doesn't add it), so the
   randomseed line aborted the chunk once the require was fixed. Guarded with
   (os.getpid and os.getpid() or 0). It was per-process anyway (same PID across
   wrk threads), so it never varied the per-thread seed regardless.

Verified under luajit 2.1 (same interpreter wrk uses), loading each script as
wrk does from the repo-root cwd and via absolute path: all now load, define
request(), and set the Authorization header. The require always failed first,
so neither bug was ever caught -- the wrk path was never exercised end-to-end
(only manual curl, which worked). Not caused by the gen_server port or the
core/loadgen retune; those stand. Re-run _diag_status.lua to confirm real
status codes, then the A/B is finally measuring store work.
2026-06-14 22:06:49 +00:00

70 lines
2.8 KiB
Lua

-- _diag_status.lua — diagnostic: tally response status codes and print them.
--
-- The normal bench scripts report only an aggregate "Non-2xx" count, which
-- can't tell a 401 (auth not reaching the server) from a 404 (store not
-- populated) from a 503 (store-call erroring). This script counts every
-- status code and prints the breakdown in done().
--
-- IMPORTANT: run with a SINGLE wrk thread (-t1) so response() and done()
-- share one Lua VM and the counter aggregates. Low load is fine; this is a
-- correctness probe, not a throughput test.
--
-- Usage (against an already-running, pre-populated server):
-- HOST=127.0.0.1:8080 BEARER=test-token-aaaaaaaaaaaaaaaaaaaa \
-- wrk -t1 -c10 -d3s -s loadgen/_diag_status.lua http://127.0.0.1:8080
--
-- It sends the S3 mix (GET-one / list / POST) so it exercises auth + store
-- on every route. If you see mostly 401 -> the auth header isn't reaching the
-- server (lua/header issue). Mostly 404 -> the store wasn't pre-populated.
-- Mostly 503 -> store-call is erroring (store actor down). Mostly 2xx at low
-- load but the full bench shows non-2xx -> it's load/scale dependent.
-- Locate common.lua next to this script regardless of cwd (see s2 for why).
package.path = (debug.getinfo(1, "S").source:match("^@(.*[/\\])") or "./") .. "?.lua;" .. package.path
local common = require("common")
wrk.headers = common.headers
wrk.headers["Content-Type"] = "application/json"
math.randomseed(os.time() + (os.getpid and os.getpid() or 0))
local body = [[{"name":"diag","email":"diag@example.test"}]]
request = function()
local r = math.random()
if r < 0.80 then
return wrk.format("GET", "/api/v1/users/" .. math.random(1, 10000))
elseif r < 0.95 then
return wrk.format("GET", "/api/v1/users")
else
return wrk.format("POST", "/api/v1/users", nil, body)
end
end
local codes = {}
local total = 0
response = function(status, headers, body)
codes[status] = (codes[status] or 0) + 1
total = total + 1
end
done = function(summary, latency, requests)
io.write("\n=== status code distribution (single-thread tally) ===\n")
-- sort keys for stable output
local keys = {}
for k in pairs(codes) do keys[#keys + 1] = k end
table.sort(keys)
for _, k in ipairs(keys) do
local n = codes[k]
io.write(string.format(" %d : %d (%.1f%%)\n", k, n, 100.0 * n / total))
end
io.write(string.format(" total tallied: %d\n", total))
if codes[401] and codes[401] > total * 0.5 then
io.write(" -> mostly 401: the auth header is NOT reaching the server.\n")
elseif codes[404] and codes[404] > total * 0.5 then
io.write(" -> mostly 404: the store was NOT pre-populated (or id range mismatch).\n")
elseif codes[503] and codes[503] > total * 0.5 then
io.write(" -> mostly 503: store-call is erroring (store actor down).\n")
end
end