High-Concurrency Performance, Throughput (TPS/RPS) & Scalability Benchmark Report
Platform: YourPlayground.games (https://www.yourplayground.games, local runtime :9033)
Audit Date: 2026-11-23 | Runtime: Node.js v24.22.2 (win32 isolated single-process benchmark server)
Scope: Pre-launch high-concurrency throughput (RPS/TPS), tail latency (p50/p95/p99), wire bandwidth (gzip), Zero-SQL storage contention, GCS object write-quota protection, and GCP Global External HTTPS Load Balancer keep-alive hardening for public GCP Cloud Run + 121.games launch.
1. Executive Summary
An isolated, apples-to-apples load benchmark (C = 30–100 concurrent workers over HTTP keep-alive against a dedicated single-process server instance backed by an isolated temporary copy of storage/) exposed six primary scalability bottlenecks in the pre-launch codebase:
- Read-Path Mutex Convoy (
src/storage/atomicJson.mjs):readJsonFile()previously acquiredwithFileLock(filePath), serializing every concurrentGETrequest behind a single FIFO lock AND stalling all catalog reads behind every diskfsync()+ NTFSrenamewrite. OnGET /games/:slug(which performs two catalog lookups per view), concurrency collapsed to32.3 RPSwithp95 = 3,055.16 ms. - Per-Request Recursive Docs Tree Walk (
src/seo/growthCatalog.mjs&src/views/docsView.mjs): EveryGET /docs,GET /docs/:section, andGET /sitemap.xmlrequest walkeddocs/sequentially and read/parsed all 16 Markdown files (247 KB), generating8,800filesystem syscalls and147.4 MBheap spikes across just200requests. - Unbatched Per-Play & Per-Score Full-File
fsync()Storms (src/storage/gameRepository.mjs): EveryGET /runtime/:slug/index.htmltriggered an unbatchedincrementPlays()full-catalogfsync()+ rename;150rapid game launches queued a 1-second background disk-write tail that starved subsequentGET /api/auth/me, static bundles, andPOST /api/games/:slug/scores(102.4 TPS,p95 = 946.41 ms). - Uncoalesced GCS Object Upload Queue (
src/storage/cloudStorageSync.mjs):100rapid play updates queued100sequential HTTPPOSTuploads togs://yourplaygroundgames-state/catalog.json, directly violating Google Cloud Storage's1 write/sec per single objectsustained rate limit (429 Too Many Requests). - Uncompressed Wire Payloads (
src/app.mjs&src/routes/runtimeRouter.mjs):three.min.js(670,062 B),phaser.min.js(1,196,122 B), sandboxed game HTML (173,761 B), and SSR HTML (83,980 B) shipped raw (identity), inflating Cloud CDN/egress bandwidth by3.5x–10x. - GCP Load Balancer Keep-Alive Race (
server.mjs): Default Node.jskeepAliveTimeout(5,000 ms) was far below the Google Cloud Global External HTTPS Load Balancer600,000 ms(600 s) backend idle timeout, creating an intermittent502 Bad GatewayTCPFINrace under pooled traffic.
Headline Before -> After Results (Single Node.js Process, Isolated Storage)
- SSR Game Permalink (
GET /games/neon-odyssey,C=50):32.3 RPS->1,293.9 RPS(40.1x),p953,055.16 ms->45.00 ms(-98.5%). - SSR Home (
GET /,C=50):124.4 RPS->925.1 RPS(7.4x),p95687.87 ms->65.45 ms(-90.5%), wire size83.98 KB->17.86 KB(-78.7%). - REST Catalog (
GET /api/games,C=50):954.4 RPS->3,795.9 RPS(4.0x),p9557.33 ms->15.43 ms(-73.1%). - 121.games Syndication (
GET /api/syndication/121games,C=50):661.5 RPS->1,964.0 RPS(3.0x), wire size23.62 KB->4.06 KB(-82.8%). - Dynamic Sitemap (
GET /sitemap.xml,C=50):279.3 RPS->1,571.6 RPS(5.6x),3,400disk reads +2,200directory walks ->0reads /0walks, heap147.41 MB->37.82 MB(-74.3%). - Authenticated Session Check (
GET /api/auth/mewithypg_sid,C=50):1,425.7 RPS->6,061.1 RPS(4.3x),p9539.96 ms->10.76 ms(-73.1%). - Vendor Bundles (
three.min.js/phaser.min.js,C=30):902.2->3,948.9 RPS(4.4x,-75.0%bytes) and522.9->2,433.2 RPS(4.7x,-73.4%bytes). - Concurrent Score Submissions (
POST /api/games/neon-odyssey/scores,100concurrent):102.4 TPS->1,865.6 TPS(18.2x),p95946.41 ms->51.01 ms(-94.6%), disk commits161->2(-98.8%). - Mixed Read+Write Contention (
200 GET /api/games+50 POST /scores): Read throughput419.1->2,963.0 RPS(7.1x), Readp95324.93 ms->21.33 ms(-93.4%); Write throughput154.2->1,133.1 TPS(7.3x). - Direct Play Counter Burst (
200concurrentincrementPlays):206.6 TPS->27,632.3 TPS(133.7x),p95920.99 ms->6.89 ms(-99.3%),200/200plays durably persisted (0lost). - GCS State Sync Burst (
100rapid plays +flushPendingSyncs()):100GCS PUTs (1,317.26 ms) ->1coalesced GCS PUT (34.24 ms,-99%PUTs,38.5xfaster) with exact finalplaysDelta = 100. - GCP LB Socket Timeouts (
server.mjs):keepAliveTimeout5,000 ms->620,000 ms,headersTimeout60,000 ms->625,000 ms.
2. Concurrency & Caching Architecture
flowchart LR
LB["GCP Global External HTTPS LB (600s idle)"] -->|"keepAliveTimeout 620s / headersTimeout 625s"| Srv["server.mjs + Express 5"]
Srv --> Comp["Native node:zlib Gzip Middleware (>= 1024 B, Vary: Accept-Encoding)"]
Comp --> StaticLRU["Static Gzip LRU Cache (<= 16 MB, stat-validated: three.min.js, phaser.min.js)"]
Comp --> RuntimeLRU["Runtime Asset LRU Cache (<= 16 MB, post-realpath symlink check)"]
Comp --> Routes["SSR / REST / Discovery / Auth Routers"]
Routes -->|"Lock-Free Single-Flight stat(bigint)"| JsonCache["Write-Through JSON LRU Cache (atomicJson.mjs, WeakMap O(1) indexes)"]
Routes -->|"Single-Flight Tree Stat"| DocsCache["Docs Tree & Rendered HTML Cache (growthCatalog.mjs + docsView.mjs)"]
Routes -->|"Group-Commit Batching"| Lock["withFileLock + Atomic Write + fsync + NTFS Rename"]
Lock -->|"Write-Through Update"| JsonCache
Lock -->|"Coalesced Debounce Queue (1000 ms default)"| GCS["gs://yourplaygroundgames-state (<= 1 PUT/sec/object)"]
3. Detailed Before vs. After Benchmark Tables
3.1 HTTP Read Hot Paths (Accept-Encoding: gzip, Isolated Server Process)
| Endpoint | Concurrency / Requests | Before RPS | After RPS | Speedup | Before p50 / p95 / p99 (ms) | After p50 / p95 / p99 (ms) | Wire Size (Before -> After) | Disk readFile (Before -> After) |
|---|---|---|---|---|---|---|---|---|
GET / | 50 / 300 | 124.4 | 925.1 | 7.4x | 240.7 / 687.9 / 973.8 | 53.4 / 65.5 / 66.3 | 83,980 B -> 17,860 B (-78.7%) | 300 -> 0 |
GET /games/neon-odyssey | 50 / 300 | 32.3 | 1,293.9 | 40.1x | 1175.6 / 3055.2 / 3844.8 | 38.7 / 45.0 / 46.6 | 47,029 B -> 11,141 B (-76.3%) | 600 -> 0 |
GET /showcase | 50 / 300 | 200.2 | 1,425.4 | 7.1x | 158.1 / 578.7 / 636.0 | 33.2 / 42.2 / 48.6 | 52,920 B -> 10,909 B (-79.4%) | 300 -> 0 |
GET /api/games | 50 / 400 | 954.4 | 3,795.9 | 4.0x | 52.7 / 57.3 / 60.2 | 12.7 / 15.4 / 15.7 | 20,322 B -> 5,222 B (-74.3%) | 400 -> 0 |
GET /api/syndication/121games | 50 / 400 | 661.5 | 1,964.0 | 3.0x | 75.2 / 88.7 / 90.4 | 23.6 / 30.3 / 34.1 | 23,624 B -> 4,058 B (-82.8%) | 400 -> 0 |
GET /sitemap.xml | 50 / 200 | 279.3 | 1,571.6 | 5.6x | 183.9 / 221.9 / 259.8 | 31.0 / 32.7 / 33.0 | 18,457 B -> 1,837 B (-90.0%) | 3,400 -> 0 (readdir: 2,200 -> 0) |
GET /docs | 50 / 200 | 323.2 | 1,915.5 | 5.9x | 147.8 / 169.7 / 173.4 | 21.9 / 29.1 / 32.2 | 51,201 B -> 14,580 B (-71.5%) | 3,200 -> 0 (readdir: 2,200 -> 0) |
GET /runtime/neon-odyssey/index.html | 50 / 150 | 2,002.8 | 4,737.2 | 2.4x | 23.0 / 27.2 / 28.2 | 8.9 / 12.5 / 13.0 | 173,761 B -> 41,595 B (-76.1%) | 153 -> 0 |
GET /api/auth/me (ypg_sid) | 50 / 400 | 1,425.7 | 6,061.1 | 4.3x | 35.1 / 40.0 / 41.7 | 7.6 / 10.8 / 12.7 | 413 B -> 413 B (<1 KB identity) | 846 -> 0 |
GET /vendor/three.min.js | 30 / 120 | 902.2 | 3,948.9 | 4.4x | 28.1 / 43.1 / 47.2 | 6.3 / 9.7 / 9.8 | 670,062 B -> 167,770 B (-75.0%) | 16 -> 0 |
GET /vendor/phaser.min.js | 30 / 100 | 522.9 | 2,433.2 | 4.7x | 51.9 / 67.8 / 70.3 | 9.7 / 17.0 / 17.2 | 1,196,122 B -> 318,115 B (-73.4%) | 26 -> 0 |
3.2 Concurrent Write, Mixed Contention & GCS State Sync Benchmarks
| Workload | Before TPS / RPS | After TPS / RPS | Speedup | Before p50 / p95 / p99 (ms) | After p50 / p95 / p99 (ms) | Integrity & I/O Proof |
|---|---|---|---|---|---|---|
POST /api/games/neon-odyssey/scores (100 concurrent) | 102.4 TPS | 1,865.6 TPS | 18.2x | 673.5 / 946.4 / 965.9 | 48.9 / 51.0 / 51.1 | 100/100 HTTP 201; open/rename 161/162 -> 2/2 (-98.8%) |
Mixed Contention — 200 GET /api/games | 419.1 RPS | 2,963.0 RPS | 7.1x | 52.9 / 324.9 / 332.3 | 15.4 / 21.3 / 22.0 | 200/200 HTTP 200; readFile 250 -> 0 |
Mixed Contention — 50 POST /scores (parallel) | 154.2 TPS | 1,133.1 TPS | 7.3x | 190.8 / 312.5 / 323.3 | 43.0 / 43.4 / 43.4 | 50/50 HTTP 201; open/rename 50/50 -> 1/1 (-98.0%) |
Direct incrementPlays (200 concurrent) | 206.6 TPS | 27,632.3 TPS | 133.7x | 496.9 / 921.0 / 958.0 | 6.2 / 6.9 / 7.0 | Exact playsDelta = 200 (0 lost updates, 0 .tmp leftovers) |
GCS State Sync Burst (100 rapid plays + flush) | 100 PUTs (1,317.3 ms) | 1 PUT (34.2 ms) | 38.5x | — | — | -99.0% GCS writes; exact remote playsDelta = 100; zero 429 risk |
3.3 Server Socket & Heap Efficiency
| Metric | Before | After | Operational Impact |
|---|---|---|---|
server.keepAliveTimeout | 5,000 ms | 620,000 ms (620 s) | Exceeds GCP Global External HTTPS LB 600 s idle keep-alive pool |
server.headersTimeout | 60,000 ms | 625,000 ms (625 s) | Strictly >= keepAliveTimeout + 5,000 ms per Node.js HTTP contract |
SIGTERM Graceful Drain | Waited on idle sockets | server.closeIdleConnections() | Immediate idle socket teardown + flushPendingSyncs({ timeoutMs: 3000 }) |
Peak Heap on GET /sitemap.xml | 147.41 MB | 37.82 MB (-74.3%) | Eliminates 49 MB transient markdown string churn per 200 requests |
| Peak RSS across full suite | 412.02 MB | 182.50 MB (-55.7%) | Comfortably fits within 512 MiB–1 GiB Cloud Run memory budgets |
4. Engineering Upgrades Implemented (File Traceability)
- Lock-Free Single-Flight Stat-Validated Write-Through JSON Cache (
src/storage/atomicJson.mjs):
readJsonFile()no longer enterswithFileLock(), eliminating read-read serialization and read-behind-write lock convoys.- Uses single-flight coalesced
fs.stat(path, { bigint: true })(mtimeNs,ctimeNs,size,ino) against a bounded128-entry LRU cache with monotonicwriteGenerationsguards, ensuring 0 ms staleness on both in-process mutations and external disk writes (includingwriteBinaryAtomic()invalidation during GCS boot hydration). - Supports
{ clone: false }for internal read-only repository indexing and{ skipWrite: true }inupdateJsonAtomic()to avoid no-op diskfsync()writes.
- Pre-Indexed Catalog & Group-Commit Batching (
src/storage/gameRepository.mjs):
- Attaches a
WeakMapcatalog index (sortedGames,bySlugMap, pre-lowercased search strings) to each committed catalog snapshot and replaces V8structuredClone()on catalog reads with a fast deep record cloner (cloneGameRecord). - Implements strict linearizable Group-Commit Lock-Coalesced Batching for
incrementPlays()andrecordScore(): concurrent mutations arriving while a file lock is held coalesce into a single atomicfsync()+ rename while preserving exact per-caller linearizable return values,GAME_NOT_FOUNDisolation, and immediate read-after-write durability.
- O(1) Indexed Auth & Session Cache (
src/storage/authRepository.mjs):
- Adds
WeakMapindexes (usersById,usersByEmail,sessionsByIdwith pre-parsedexpiresMs) over write-through cachedusers.jsonandsessions.json, eliminating2xlocked disk reads per authenticated HTTP request and skipping redundant disk writes on idempotentdeleteSession().
- Single-Flight Parallel Docs Tree & Markdown HTML Cache (
src/seo/growthCatalog.mjs,src/views/docsView.mjs):
- Replaces sequential directory walking and per-request reading of all
16.mdfiles (247 KB) with single-flightmtimeNs/ctimeNs/sizetree validation and incremental per-file re-parsing on disk edits. - Adds a bounded
64-entry LRU cache forrenderMarkdownToSafeHtml()keyed by section content and cross-link topology.
- Coalesced / Debounced GCS Object Upload Queue (
src/storage/cloudStorageSync.mjs):
- Coalesces rapid background
scheduleMirrorFile()/scheduleMirrorGame()writes per(bucket, objectName)key using a configurableGCS_SYNC_COALESCE_MSwindow (DEFAULT_GCS_COALESCE_MS = 1000 ms, enforcing<= 1 PUT/sec/objectper GCS limits). flushPendingSyncs()cancels active debounce timers, immediately dispatches all dirty slots, awaits active game directory walks, and drains tail mutations arriving mid-flight beforeSIGTERMexit or test completion.
- Native
node:zlibGzip Compression, Static Asset LRU & Runtime Asset Cache (src/middleware/compressionMiddleware.mjs,src/app.mjs,src/routes/runtimeRouter.mjs):
- Zero external dependencies: compresses compressible responses (
text/*,application/json,application/javascript,application/xml,application/rss+xml,application/atom+xml,application/feed+json,application/manifest+json,image/svg+xml)>= 1,024 BwhenAccept-Encodingallowsgzip(q > 0), emittingVary: Accept-Encodingand weakETag(W/"...") while preserving every security header (SSR_CSP_HEADER,RUNTIME_CSP_HEADER,X-Robots-Tag,Cache-Control,Service-Worker-Allowed). - Pre-compresses static compressible
public/assets (three.min.js,phaser.min.js, CSS/JS/SVG) into a stat-validated<= 16 MBLRU cache withIf-None-Match304 Not Modifiedsupport. - Caches runtime game payloads in a stat-validated
<= 16 MBLRU cache strictly afterfs.stat+fs.realpathsymlink containment validation.
- GCP Global Load Balancer Keep-Alive Tuning (
server.mjs):
- Exports
GCP_LB_KEEP_ALIVE_TIMEOUT_MS = 620_000andGCP_LB_HEADERS_TIMEOUT_MS = 625_000, applies them tohttp.Server, and callsserver.closeIdleConnections?.()during cleanSIGINT/SIGTERMshutdown.
5. Production Capacity Sizing (GCP Cloud Run + 121.games)
| Traffic Tier | Expected Peak RPS | Recommended Cloud Run Config (yourplayground-games) | Effective Capacity Notes |
|---|---|---|---|
| Launch Baseline | 50–250 RPS | min-instances=1, max-instances=10, concurrency=80, 1 vCPU / 512 MiB | Single instance handles 925+ RPS SSR, 1,964+ RPS 121.games JSON, 3,795+ RPS /api/games, 1,865+ TPS scores; Cloud CDN absorbs static /vendor/*, /creatives/*, and /api/syndication/121games (max-age=60). |
Viral Spike (121.games Feature) | 1,000–5,000 RPS | min-instances=2, max-instances=25, concurrency=100, 2 vCPU / 1 GiB | With Cloud CDN hit ratio >= 80% on static assets + syndication feeds and gzip bandwidth cuts of 73–90%, origin load stays under 1,000 RPS (< 2 active instances). |
| Zero-SQL GCS Ceiling Notice | > 10 concurrent writers across multiple instances | Single-writer affinity or Firestore/Memorystore migration if multi-instance write fan-out exceeds 1 PUT/sec/object | Because GCS_STATE_BUCKET stores consolidated JSON blobs (catalog.json, users.json, sessions.json), a single instance coalesces all writes cleanly to <= 1 PUT/sec/object. For multi-instance horizontal write scaling (max-instances > 1 with heavy concurrent scores/signups), shard per-game score/play deltas or migrate hot counters to Firestore/Redis before removing single-writer coordination. |
6. Deterministic Verification Suite (tests/unit/perf-concurrency.test.mjs)
All upgrades are permanently gated in npm run test:unit and node .agents/scripts/agent-ctl.cjs verify --full-gate via tests/unit/perf-concurrency.test.mjs:
- GCP LB Timeout Contract: Verifies
keepAliveTimeout === 620_000,headersTimeout === 625_000, and sub-2s clean drain with active keep-alive agents. - Native Gzip & Header Preservation: Verifies raw wire gzip compression (
>60%reduction on SSR HTML,<250 KBonthree.min.jswith byte-exact SHA-256 gunzip parity +304If-None-Match), exactSSR_CSP_HEADER/RUNTIME_CSP_HEADER/Cache-Control/Service-Worker-Allowedpreservation,<1024 Bidentity passthrough,gzip;q=0compliance,HEADsafety, and zero compression on binary PNGs. - Zero-Staleness Cache Coherence: Proves immediate visibility of write-through mutations, raw external
fs.writeFileedits,writeBinaryAtomichydration overwrites, and livedocs/additions/edits acrossgameRepository,authRepository, andloadDocumentationSections(). - High-Concurrency Stress: Proves
200concurrent plays +100concurrent scores +10invalid sibling rejections +100concurrent reads complete with0lost updates, exact top-25 leaderboard ordering, and0.tmpleftovers. - GCS Coalescing & Flush Drain: Proves
120rapid catalog mutations coalesce into<= 3GCS HTTPPUTcalls with exact remote final state and zero dropped mid-flight tail writes.