oliver-zehentleitner / maity

hub: a held wait costs almost nothing while idle (the bell wait ran ~380 SQL statements per 56 s wait, the event wait ~51)

Sign in to report

tsk-pekzwky49pa8 Done Maity Coder Claude 001

The prod load test of 2026-12-03 (card tsk-wshw4njbbyc4, idle scenario: 600 held waits, no writes) measured what a held wait costs:

| route | waits | SQL per wait (median) | wait length (median) | SQL/s per wait |
|---|---|---|---|---|
| GET /me/notifications (bell wait) | 445 | 378 | 55.7 s | ~6.9 |
| GET …/events (event wait) | 952 | 51 | 55.2 s | ~0.97 |

With about 200 bell waits and 400 event waits held, that is about 1800 SQL statements per second spent on waiting alone, and the pods used about 2.4 cores with no writes. The CPU rose with the number of held waits during the mixed ramp too. So held waits, not the replica count, set the capacity ceiling.

Find out:

  • Why does one held /me/notifications run about 380 statements (about 7 per second)? Is it polling in a loop instead of waking on the change signal, or re-checking on every unrelated event?
  • Why does an event wait run about one statement per second while nothing happens?
  • Check whether #2377 (tsk-xgpebf72w2bc) changed the bell path.

Then fix: a held wait should cost close to nothing while nothing relevant happens. It wakes on its signal (NOTIFY on PostgreSQL; the existing fallback on SQLite/MariaDB), plus a bounded, slow safety re-check. Give before/after numbers from a local test that holds N waits, for example statements per wait per minute, and put them in the PR body. Answer shapes and wake latency stay as they are.

Also on this path (2026-12-03): tests/test_event_wake_skip.py::test_unrelated_events_during_a_held_wait_cost_no_read_each failed on PostgreSQL in an unrelated PR run (run 47052138934, job 144066950559, tests/test_event_wake_skip.py:1158): AssertionError: (3, 54, 104), reads=3 against the bound 2 + 30 // 64. The PR touched no event or wait file, so the test is timing-sensitive on main. Make it deterministic as part of this card, or explain why 3 reads are correct and fix the bound.