You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Durable Emitter - Backpressure and other improvements - #2570
New Config.BackpressureEnabled (default false) and Config.MaxQueueDepth (default DefaultMaxQueueDepth = 500k).
When enabled and the estimated backlog is at or above MaxQueueDepth, Emit returns ErrBacklogged without persisting the event. Rejected events are lost. That's the deliberate trade-off: shed load rather than take the shared DB down. That's also why the flag is off by default.
The backlog estimate comes from a new optional store interface, BacklogEstimator:
PgDurableEventStore reads pg_stat_user_tables.n_live_tup, a catalog lookup that stays cheap at any table size.
It covers rows written by every process sharing the table.
It is polled every BacklogPollInterval (default 5s) and seeded at start, so a restart into an existing backlog is covered.
Between polls the estimate is not adjusted, so MaxQueueDepth is a soft limit: rejects start and stop up to one BacklogPollInterval late.
Fails open: if the estimate query fails, the last value is kept. If the store doesn't implement BacklogEstimator, a warning is logged and back-pressure stays off.
New counter: durable_emitter.emit.backpressure_rejects.
2. Retransmit pauses while delivery deletes fail
After any failed delivery delete, the retransmit loop skips its ticks for DeleteFailureRetransmitBackoff (default 30s). It resumes once the window passes.
This stops the loop of re-reading and re-sending rows that can't be deleted.
3. Only the host scans the queue
Only the retransmit-owning (host) emitter runs the queue aggregate query; LOOP plugins no longer do.
While back-pressure is engaged, the host skips the scan too and reports depth from the estimate.
4. Per-process metric attribution
Every durable emitter metric now carries an emitter_instance attribute:
DurableEmitterMetricsConfig.Instance sets it explicitly.
Otherwise it defaults to host (retransmit enabled) or plugin.
LOOP servers set it to the plugin's logger name (e.g. cron, http-trigger).
Series from different processes no longer collide, so rate() and per-process dashboards are correct again.
5. LOOP configuration
New env vars, read by pkg/loop/server.go, so plugins use the same settings as the host:
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved findings show that refresh and purge races can undercount the backlog and bypass its threshold, while successful deletes can prematurely cancel the retransmit pause.
This PR adds opt-in load shedding and recovery safeguards to the durable telemetry emitter, aiming to reduce database pressure during overload and distinguish metrics from host and LOOP processes.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Queue-depth accounting misses concurrent in-flight inserts, discards local deltas after stale polls, and ignores confirmed removals, allowing limit overruns or rejection of events when the queue is empty.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Outstanding insert reservations can be dropped across polls, bypassing back-pressure, and LOOP plugin delete failures do not signal the host to pause retransmission.
Pause retransmits on delivery failures from loop plugins
pkg/durableemitter/durable_emitter.go:973
This timestamp only records failures in the host's own emitter; LOOP plugins perform delivery deletes in separate instances and disable retransmit (pkg/loop/server.go:224). If plugin deletes time out, the host continues reading and republishing those rows until a host delete fails, so plugin failures do not trigger the intended immediate pause. Share the failure signal with the retransmit owner and test a plugin/host pair using the same store.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Queue-depth rollover can misclassify an empty queue as full and reject new events, while cross-process delete-failure backoff and rejection-failure metrics also remain incomplete.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The backlog estimate changes only after successful polls, so poll failures can allow unchecked queue growth or continued event rejection after draining because local insert, delete, and purge adjustments are missing.
can we make the DE adaptable to slow queries? if we detect deletes are taking twice the p99 for typical delete latency (should make this configurable), can we backoff on attempting deletes?
Reviewing FRs in order of priority, as this informs what features we choose to create:
not bringing down the nodes DB
transmitting the messages at least once to ChIP
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
1. Emit back-pressure (opt-in)
Config.BackpressureEnabled(defaultfalse) andConfig.MaxQueueDepth(defaultDefaultMaxQueueDepth= 500k).MaxQueueDepth,EmitreturnsErrBackloggedwithout persisting the event. Rejected events are lost. That's the deliberate trade-off: shed load rather than take the shared DB down. That's also why the flag is off by default.BacklogEstimator:PgDurableEventStorereadspg_stat_user_tables.n_live_tup, a catalog lookup that stays cheap at any table size.BacklogPollInterval(default 5s) and seeded at start, so a restart into an existing backlog is covered.BacklogEstimator, a warning is logged and back-pressure stays off.durable_emitter.emit.backpressure_rejects.2. Retransmit pauses while delivery deletes fail
DeleteFailureRetransmitBackoff(default 30s). It resumes once the window passes.3. Only the host scans the queue
4. Per-process metric attribution
emitter_instanceattribute:DurableEmitterMetricsConfig.Instancesets it explicitly.host(retransmit enabled) orplugin.cron,http-trigger).rate()and per-process dashboards are correct again.5. LOOP configuration
New env vars, read by
pkg/loop/server.go, so plugins use the same settings as the host:CL_CHIP_INGRESS_DURABLE_EMITTER_BACKPRESSURE_ENABLEDCL_CHIP_INGRESS_DURABLE_EMITTER_MAX_QUEUE_DEPTHCL_CHIP_INGRESS_DURABLE_EMITTER_BACKLOG_POLL_INTERVALZero values fall back to the exported defaults:
DefaultMaxQueueDepth,DefaultBacklogPollIntervalandDefaultDeleteFailureRetransmitBackoff.