From 943080805ccc08b4b817163b5f45d95bc6807b27 Mon Sep 17 00:00:00 2001 From: sandbox-agent Date: Sun, 14 Jun 2026 22:06:49 +0000 Subject: [PATCH] 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. --- loadgen/_diag_status.lua | 4 +++- loadgen/s2_user_get.lua | 7 ++++++- loadgen/s3_mixed.lua | 4 +++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/loadgen/_diag_status.lua b/loadgen/_diag_status.lua index a3c7cf9..6deaec0 100644 --- a/loadgen/_diag_status.lua +++ b/loadgen/_diag_status.lua @@ -19,11 +19,13 @@ -- 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()) +math.randomseed(os.time() + (os.getpid and os.getpid() or 0)) local body = [[{"name":"diag","email":"diag@example.test"}]] diff --git a/loadgen/s2_user_get.lua b/loadgen/s2_user_get.lua index d877f90..25438a2 100644 --- a/loadgen/s2_user_get.lua +++ b/loadgen/s2_user_get.lua @@ -1,11 +1,16 @@ -- S2: single-route GET with full middleware (logger + request_id + auth). -- :id is spread across 10_000 values to defeat per-id caching. +-- Locate common.lua next to this script regardless of cwd. wrk runs with cwd +-- at the repo root, where 'common' is not on package.path; without this the +-- require fails and wrk silently falls back to its default request (GET / with +-- no auth -> 100% non-2xx). +package.path = (debug.getinfo(1, "S").source:match("^@(.*[/\\])") or "./") .. "?.lua;" .. package.path local common = require("common") wrk.method = "GET" wrk.headers = common.headers -math.randomseed(os.time() + os.getpid()) +math.randomseed(os.time() + (os.getpid and os.getpid() or 0)) request = function() local id = math.random(1, 10000) diff --git a/loadgen/s3_mixed.lua b/loadgen/s3_mixed.lua index 19546ec..6ace24a 100644 --- a/loadgen/s3_mixed.lua +++ b/loadgen/s3_mixed.lua @@ -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.