relay: skip TTL deadline bump for known-permanent channels (T1a write-amp)#2125
Conversation
Every stored channel-scoped event currently executes bump_ttl_deadline, whose predicate (ttl_seconds IS NOT NULL) matches zero rows on permanent channels — a wasted write-shaped round trip and implicit transaction on the hot ingest path (~1 of the ~5 write txns/message measured in the write-amplification baseline). The ingest path already fetches the channel row once per request (E1 §4.8). Use it: skip the bump only when the row positively shows ttl_seconds IS NULL. A missing row (kind:9007 pre-create, transient get_channel error) still bumps, so ephemeral channels can never archive early due to a failed prefetch. A concurrent update_channel that sets a TTL resets ttl_deadline itself, making the skipped bump redundant by construction. Ships with bench/t1a_evidence.sh (runnable-from-tip gate): asserts zero TTL UPDATE statements via pg_stat_statements on a permanent channel, deadline still advances on an ephemeral channel, and the TTL-set-during-ingest race leaves a future deadline. wamp_bench is the shared load generator used by the evidence script and the baseline benchmark. Part of the relay write-amplification plan (rev 3), lane T1a. Base: 8908bd6. Co-authored-by: Tyler Longwell <tlongwell@block.xyz> Signed-off-by: Tyler Longwell <tlongwell@block.xyz>
|
Blocking race in the TTL skip. The prefetched
That violates the existing invariant immediately above the changed code: every successfully stored channel-scoped event keeps the channel alive. Please close the stale-positive race and add a barrier-forced test asserting the deadline reflects the event ordered after the TTL transition (not merely that it is future). The optimization must remain fail-safe toward bumping when permanence may have changed. Review source: exact PR head |
Move ephemeral-channel TTL refresh into a deferred event trigger so a concurrent permanent-to-ephemeral transition cannot be missed by a stale relay prefetch. The trigger locks by channel identity before evaluating TTL state and preserves the existing best-effort failure contract. Remove the obsolete post-insert application transaction and add Postgres coverage for permanent, ephemeral, duplicate, and forced activation-race behavior. Co-authored-by: npub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757 <5217c5c2f7bfb4333e46d17c98a9255a52dadee18dcd43a43536b95e6776dfa0@sprout-oss.stage.blox.sqprod.co> Signed-off-by: npub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757 <5217c5c2f7bfb4333e46d17c98a9255a52dadee18dcd43a43536b95e6776dfa0@sprout-oss.stage.blox.sqprod.co>
What
Skip the
bump_ttl_deadlinewrite on the hot ingest path when the channel is known-permanent (ttl_seconds IS NULLon the already-prefetched channel row).Every stored channel-scoped event currently executes
bump_ttl_deadline, whose predicate matches zero rows on permanent channels — a wasted write-shaped round trip and implicit transaction per message. This is T1a of the write-amplification workstream.Safety
ttl_seconds IS NULL. A missing row (kind:9007 pre-create, transientget_channelerror) still bumps — an ephemeral channel can never archive early due to a failed prefetch.update_channelthat sets a TTL resetsttl_deadlineitself, making the skipped bump redundant by construction (race is benign in both directions).Measured impact (local integration benchmark, real relay binary + PG17 + Redis)
Scenario A (zero push leases), net Postgres commits per accepted message, same DB container/channel, quiescence-gated windows, idle-rate subtracted:
Exactly the predicted ~1 commit/message, flat across load.
Testing
ttl_deadline; ephemeral-channel expiration still works, including a permanent→ephemeral flip during traffic.cargo test -p buzz-relaygreen except the knownmesh_demofailure that is also red on untouched main.Part of the write-amp series; sibling PR: T2a audit batching. Larger follow-up (T1b: push-queue skip at zero leases) targets ~5 of the remaining ~10 commits/msg.