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.
This commit is contained in:
sandbox-agent
2026-06-14 22:06:49 +00:00
parent 926aba4344
commit 943080805c
3 changed files with 12 additions and 3 deletions
+3 -1
View File
@@ -3,11 +3,13 @@
-- contention on axum, and gen_server message-pass on cowboy without
-- making writes the bottleneck.
-- 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())
math.randomseed(os.time() + (os.getpid and os.getpid() or 0))
-- A small pool of pre-built JSON bodies. Building one fresh per request
-- in Lua would taint the bench with Lua's GC overhead.