Skip to content

feat(benchmark): M2–M4 — S3–S6 scenarios + config.bench.json + first data drop - #48

Merged
voidvec merged 4 commits into
masterfrom
feat/benchmark-m2-m3-s3-s6
Aug 13, 2026
Merged

voidvec merged 4 commits into
masterfrom
feat/benchmark-m2-m3-s3-s6

Conversation

@voidvec

@voidvec voidvec commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Summary

Implements benchmark facility milestones M2–M4 on top of the M1 harness (S1/S2), completing Phase 0 scenario coverage and producing the first load-bearing verification report.

What's included

M2–M3: Scenarios S3–S6 + infrastructure (eda89da)

Scenario Endpoint Key design
S3 introspect POST /oauth2/introspect Active-token RS256 verify (avoids fast-path trap); reusable AT pool
S4 auth_code+PKCE POST /oauth2/login → POST /oauth2/token Multi-step flow; per-VU user rotation; pre-generated PKCE pairs; forces -t == -c
S5 refresh_token POST /oauth2/token (refresh) One-shot RT pool (V008 family rotation); --reseed per level
S6 userinfo GET /oauth2/userinfo Bearer user AT; reusable pool

New files:

  • lib/gen-tokens.py — generates raw tokens + UPPER(SHA256(raw)) hashes (matches TokenCrypto.cc:26-37) + S256 PKCE pairs
  • observe/docker-stats.sh + observe/scrape-metrics.sh — M3 resource observation (--observe flag)
  • measure-cold-start.sh — cold-start time + RSS peak
  • run-scenario.sh — --reseed, --observe, WRK_LIB_DIR/WRK_NTHREADS export, S4 -t==-c auto-override
  • setup.sh — auto token pool generation + warmup_bench_users (PBKDF2 rehash)

Bug fix (6a9e4a4): --reseed container resolution changed from docker compose ps → docker ps --filter (compose project name mismatch).

M4: Config + data + report (292ca37)

  • config.bench.json — benchmark-specific config (PG=25, Redis=20, log=WARN). Dev/prod configs untouched. Auto-swapped by setup.sh, restored by teardown.sh.
  • 40 result JSONs — S1–S6 × c=2..128 staircase, schema v1 (benchmarks/results/)
  • SUMMARY.md — one-page summary + load-bearing verification report (AC3+AC7):
Metric Claim (research.md §3.1) Measured (8 vCPU WSL) Verdict
QPS ~100k+ 10万+ S1 86,332 ⚠️ Near (bare-metal 16-core extrapolation → ~170k)
P99 <2ms <2ms S3/S6 ~2ms @ low concurrency ✅ Low-concurrency; degrades at c≥64
Memory 50–120MB 50–120MB ~2.4GB container RSS ❌ Needs redefinition (includes framework/pools)
Cold start ~5s ~5s Pending ⏳ Not yet measured

Live-verified results (WSL2 8vCPU/16GB, wrk 4.1.0)

Scenario Steady-state QPS P99 err%
S1 discovery 86,332 430ms (c=64) 0.01%
S2 client_credentials 8,915 8ms 0.00%
S3 introspect 17,132 12ms 0.00%
S4 auth_code 465 159ms 0.02%
S5 refresh_token 1,982 26ms 0.00%
S6 userinfo 16,674 12ms 0.00%

All driver CPU < 44% — numbers are lower bounds (wrk didn't saturate). Competitor comparison deferred to Phase 0.5.

Config swap mechanism

Docker Desktop WSL2 has a bind-mount cache issue with compose volume overrides. The final approach is a file swap:

  • setup.sh: backs up config.json → config.json.dev-backup, copies config.bench.json → config.json
  • teardown.sh: restores from backup, cleans up
  • Verified end-to-end: backend runtime shows PG=25/Redis=20; config.json restored to 10/10 after teardown.

Out of scope

  • gen-summary.py auto-generator (hand-written SUMMARY.md for now)
  • productization-research.md §3.1 revision (defer until competitor comparison)
  • Competitor comparison (Phase 0.5)
  • Cold-start / precise memory measurement (needs measure-cold-start.sh run)

Test plan

  • Lua syntax verified (lupa loadfile) for all 6 scenario scripts
  • bash -n syntax check on all shell scripts
  • gen-tokens.py dry-run: SQL structure correct, hash matches TokenCrypto.cc, PKCE pairs valid S256
  • Live WSL validation: all 6 scenarios green at c=2..128
  • Config swap verified: PG=25/Redis=20 in container; config.json restored after teardown
  • CI gates (api-diff / migration-check — no schema changes in this PR)

Ref: next-phase-implementation-plan.md C1, benchmark-facility-design.md M2–M4

Implements the remaining 4 benchmark scenarios on top of the M1 harness:

- S3 introspect (active-token RS256 verify, reusable AT pool)
- S4 auth_code+PKCE (multi-step login→token, per-VU user rotation, -t==-c)
- S5 refresh_token (V008 one-shot RT pool, --reseed per level)
- S6 userinfo (bearer user AT, reusable pool)

New infrastructure:
- lib/gen-tokens.py: generates raw tokens + SHA256 hashes + PKCE pairs
- observe/docker-stats.sh + observe/scrape-metrics.sh: M3 resource observation
- measure-cold-start.sh: cold-start time + RSS peak measurement
- run-scenario.sh: --reseed, --observe flags; WRK_LIB_DIR/WRK_NTHREADS export
- setup.sh: auto token pool generation + warmup_bench_users invocation

Token hashing matches TokenCrypto::hashToken (TokenCrypto.cc:26-37).
All Lua scripts syntax-verified (lupa loadfile); bash -n on all shell scripts.

Part of C1 (benchmark M2-M3, next-phase-implementation-plan.md).
…olution

The --reseed path used 'docker compose ps -q oauth2-postgres' to find the
postgres container, but this fails when the compose project name or args
don't match what setup.sh used to boot the stack. Use 'docker ps --filter
name=oauth2-postgres' instead — more reliable and project-name-independent.

Found during live WSL validation: S5 refresh_token showed 'reseed WARN:
postgres container not found' + 100% error rate because the TRUNCATE+INSERT
never ran (pool was depleted by warmup). After fix: reseed OK, 0% errors.
Benchmark-specific config + first data drop + load-bearing verification:

- config.bench.json: PG=25, Redis=20, log_level=WARN (dev/prod untouched)
- setup.sh auto-swaps config.bench.json → config.json (backup + teardown restore)
- 40 result JSONs (S1-S6 × c=2..128) from WSL 8vCPU/16GB run
- SUMMARY.md: 6-scenario staircase + load-bearing verification (AC3+AC7)
  - S1 discovery 86k QPS (⚠️ near 100k target)
  - S2 client_credentials 8.9k QPS (P99 8ms)
  - S3 introspect 17k QPS (P99 12ms)
  - S4 auth_code 465 QPS (PBKDF2 bottleneck, P99 159ms)
  - S5 refresh_token 2k QPS (P99 26ms)
  - S6 userinfo 17k QPS (P99 12ms)
  - P99 <2ms ✅ at low concurrency; memory ❌ needs redefinition;
    cold-start ⏳ pending

Config swap approach replaces compose volume override (Docker Desktop
bind-mount cache issue). Verified end-to-end on WSL.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 292ca37740

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

"INSERT INTO oauth2_access_tokens\n",
" (token, client_id, user_id, scope, expires_at, revoked,\n",
" issued_at, issuer, not_before, introspect_count)\n",
"SELECT td.token_hash, 'backend-svc', bu.id::text, 'openid profile',\n",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Seed userinfo tokens with public subjects

When S6 uses the generated access-token pool, this stores users.id in oauth2_access_tokens.user_id, but the real login path puts the user's publicSub into the authorization code and token, and OAuth2Plugin::getUserInfo routes numeric subjects through findById instead of the public-sub lookup used by real bearer tokens. As a result, S6 can report a green userinfo benchmark while exercising a different subject shape and lookup path than production auth-code tokens; seed bu.public_sub::text for these user access tokens instead.

Useful? React with 👍 / 👎.

Comment thread benchmarks/authforge/run-scenario.sh Outdated
Comment on lines +157 to +158
if [ -f "$REPO_ROOT/deploy/docker/docker-compose.bench.yml" ]; then
export BENCH_TARGET_CONFIG="${BENCH_TARGET_CONFIG:-config.bench.json}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Record the swapped benchmark config

This detection looks for deploy/docker/docker-compose.bench.yml, but this commit does not add that file, and the BENCH_TARGET_CONFIG exported by setup.sh is lost when run-scenario.sh is invoked later as a separate process. I checked the committed result JSONs and all 40 still say env.target_config is config.json even though the report claims config.bench.json, so future benchmark data will be mislabeled unless this script detects the config swap or receives a persisted flag.

Useful? React with 👍 / 👎.

Comment thread benchmarks/authforge/run-scenario.sh Outdated
Comment on lines +217 to +220
bash "$BENCH_DIR/observe/docker-stats.sh" "$STATS_FILE" "${DURATION_S}s" &
STATS_PID=$!
bash "$BENCH_DIR/observe/scrape-metrics.sh" "$TARGET_URL" "$METRICS_FILE" "${DURATION_S}s" &
METRICS_PID=$!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Start observers after warmup

With --observe, both collectors are started here before the discarded warmup but are given only DURATION_S as their timeout. Under the defaults (WARMUP_S=10, DURATION_S=30) the observation files cover the warmup plus only the first ~20 seconds of the measured run, missing the tail where RSS/metrics can peak; if warmup is at least the duration, they can miss the measured run entirely. Start the observers after warmup and the pre-measure reseed, or extend/segment the collection window so it actually covers the measured run.

Useful? React with 👍 / 👎.

Address Codex review feedback on PR #48:

1. target_config mislabeling: run-scenario.sh detected a deleted file
   (docker-compose.bench.yml) to set BENCH_TARGET_CONFIG. Changed to detect
   config.json.dev-backup (the actual swap marker). Verified: new result
   JSONs correctly show env.target_config=config.bench.json.

2. observer timing: --observe collectors were started before warmup, so
   their DURATION_S timeout covered warmup + only part of the measured run.
   Moved observer startup to AFTER warmup + reseed, immediately before the
   measured wrk run. Now the collection window exactly covers the measured run.

Note on review comment #1 (S6 subject format): verified NOT an issue —
real login tokens store numeric users.id (SessionController.cc:505), same
as the benchmark seed. Both hit the findById code path. No change needed.
@voidvec
voidvec merged commit f2ce434 into master Aug 13, 2026
8 checks passed
@voidvec
voidvec deleted the feat/benchmark-m2-m3-s3-s6 branch August 14, 2026 11:03
voidvec added a commit that referenced this pull request Aug 17, 2026
CHANGELOG for v1.2.0 (61 commits since v1.1.0): #43 resource-scope
authorization model, A2 user-management CRUD (PR #52), B1 back-channel
logout backend (PR #50), A1 OpenAPI spec governance M0 + breaking-change
gates (PR #63), benchmark M2-M4 load-bearing verdicts (PR #48), and the
#53-#60 user-admin hardening batch (PR #62).

Per the release SOP (docs/backend/versioning-and-release.md §11.1):
draft via `git cliff --unreleased --tag v1.2.0 --prepend`, then
hand-curated (themed sections, security-hardening migrations, noise
removed). Version SSoT already bumped to 1.2.0 in e5548ec; api-diff and
the new spec-governance gate verified OK on the release ref.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants