perf(database-watt): cut the database worker's cost per request #1
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 356 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.352
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1"
general
weight: 0.35
ShogunPanda
This builds on supabase/storage#1230 and goes after the database worker's thread, which was the bottleneck: it saturated with about two storage workers.
database.batch: BEGIN, the settings and the scope ride on the first query), and runs single-query operations as one message that also commits. The database worker returns raw rows, which the storage worker parses with the same pg type parsers a direct pool uses, so the database thread no longer builds row objects, dates or JSON. WithDATABASE_ENABLE_PIPELINING=truea batch is a single socket write.sanitize: false, from platformatic/platformatic#5354), so neither side walks every request and result before posting it. CPU profiles of both builds under the same load show that the walk cost the database thread 0.8 to 1 µs per GET or info request (1.2 to 1.6% of its time) and 6.3 µs per list of 100 objects (3.4%), plus about 1 µs per request on each storage worker. Now it costs nothing, and no message fell back to being sanitized. The change in req/s is smaller than the noise between runs.Storage workers and the database application have to be deployed together, because query responses now carry raw rows.
Measured on Linux (Docker on an M4 Max, 16 vCPUs) with 4 storage workers, wrk with 128 connections, and Postgres and the S3 store in Docker. Both builds ran back to back with
DATABASE_ENABLE_PIPELINING=true, which makes no difference on #1230 alone. Absolute numbers move by about 10% between runs.| Route | req/s, #1230 → this PR | DB thread µs per request | DB thread busy | p99 |
|---|---|---|---|---|
| GET 1 KB | 3,871 → 9,241 | 251 → 68 | 97% → 63% | 216 → 20 ms |
| object info | 3,999 → 13,228 | 242 → 73 | 97% → 97% | 212 → 16 ms |
| list 100 | 2,005 → 4,436 | 487 → 179 | 98% → 80% | 100 → 50 ms |
| sign URL | 7,262 → 13,751 | 135 → 58 | 98% → 79% | 80 → 20 ms |
| upload 1 KB | 835 → 908 | 1,007 → 833 | 84% → 76% | 349 → 185 ms |
With 4 workers the database thread now has headroom on GET, list, sign and upload. Object info still saturates it, because info does very little work on the storage side. brianc/node-postgres#3871 (draft) removes two more per-query costs on that thread.