Skip to content

feat(engine): drain-parallel consumer instrumentation (force_insert + drain histograms) (#1545) - #4298

Merged
oferchen merged 1 commit into
masterfrom
feat/drain-parallel-instrumentation-1545
May 17, 2026
Merged

oferchen merged 1 commit into
masterfrom
feat/drain-parallel-instrumentation-1545

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Land the metric prerequisites from docs/design/drain-parallel-consumer-thread.md (section 7 / sequencing step 1) ahead of any topology change to the delta-drain + delta-reorder pair.
  • Adds a force_insert cumulative counter on ReorderBuffer plus two HistogramStats (powers-of-two batch sizes, microsecond-decade pauses) recorded by the consumer drain loop.
  • Exposes a live Metrics snapshot through DeltaConsumer::metrics so operators can poll the new counters without waiting for transfer completion.

Why

The design doc flags these counters as a removal-prerequisite for force_insert and a diagnostic for head-of-line pressure. Landing them as a focused refactor lets follow-up topology work (single-thread consumer, SPSC ring) ship with before/after numbers from the same surface area.

Implementation notes

  • HistogramStats is a single Copy struct with two scale variants. Sampling is allocation-free (one bucket bump per observation) and snapshots are returned by value through Metrics.
  • The consumer thread maintains a last_drain_at anchor; only non-empty drain iterations record a batch sample and the elapsed pause, so the histograms reflect actual delivered work rather than idle polling.
  • The metrics snapshot lives behind Arc<Mutex<Metrics>>. Lock contention is bounded - one publish per drain iteration / force_insert, one read per metrics() call - and the lock is never held across I/O.

Test plan

  • cargo fmt --all
  • CI: fmt + clippy
  • CI: nextest (stable) - new tests force_insert_count_*, drain_batch_histogram_records_powers_of_two, drain_pause_histogram_records_microsecond_decades, metrics_force_insert_counter_increments_under_backpressure, metrics_drain_batch_histogram_accumulates
  • CI: Windows / macOS / Linux musl

…1545)

Wires the metric prerequisites called out in
docs/design/drain-parallel-consumer-thread.md section 7 (and the
sequencing in section 10) into the production drain pipeline.

- HistogramStats: pow-2 count buckets and microsecond-decade duration
  buckets, shared between the new metrics fields.
- ReorderBuffer::force_insert now bumps a cumulative counter, exposed
  on the Metrics snapshot. Tracks the capacity-bound fallback that
  the design doc flags as a removal prerequisite.
- ReorderBuffer::record_drain_batch / record_drain_pause publish into
  two histograms on every non-empty consumer drain.
- DeltaConsumer publishes a live Metrics snapshot through an Arc<Mutex>
  and exposes it via DeltaConsumer::metrics for in-flight polling.
- Unit tests cover the force_insert counter (including the bypass and
  out-of-window paths), the powers-of-two batch buckets, and the
  microsecond decade pause buckets. End-to-end tests on DeltaConsumer
  verify the synthetic backpressure path drives force_insert_count
  above zero and that the batch histogram accumulates samples covering
  every delivered item.
@oferchen
oferchen merged commit 3e711af into master May 17, 2026
3 of 13 checks passed
@github-actions github-actions Bot added the enhancement New feature or request label May 17, 2026
oferchen added a commit that referenced this pull request May 18, 2026
…1545) (#4298)

Wires the metric prerequisites called out in
docs/design/drain-parallel-consumer-thread.md section 7 (and the
sequencing in section 10) into the production drain pipeline.

- HistogramStats: pow-2 count buckets and microsecond-decade duration
  buckets, shared between the new metrics fields.
- ReorderBuffer::force_insert now bumps a cumulative counter, exposed
  on the Metrics snapshot. Tracks the capacity-bound fallback that
  the design doc flags as a removal prerequisite.
- ReorderBuffer::record_drain_batch / record_drain_pause publish into
  two histograms on every non-empty consumer drain.
- DeltaConsumer publishes a live Metrics snapshot through an Arc<Mutex>
  and exposes it via DeltaConsumer::metrics for in-flight polling.
- Unit tests cover the force_insert counter (including the bypass and
  out-of-window paths), the powers-of-two batch buckets, and the
  microsecond decade pause buckets. End-to-end tests on DeltaConsumer
  verify the synthetic backpressure path drives force_insert_count
  above zero and that the batch histogram accumulates samples covering
  every delivered item.
oferchen added a commit that referenced this pull request May 18, 2026
…1545) (#4298)

Wires the metric prerequisites called out in
docs/design/drain-parallel-consumer-thread.md section 7 (and the
sequencing in section 10) into the production drain pipeline.

- HistogramStats: pow-2 count buckets and microsecond-decade duration
  buckets, shared between the new metrics fields.
- ReorderBuffer::force_insert now bumps a cumulative counter, exposed
  on the Metrics snapshot. Tracks the capacity-bound fallback that
  the design doc flags as a removal prerequisite.
- ReorderBuffer::record_drain_batch / record_drain_pause publish into
  two histograms on every non-empty consumer drain.
- DeltaConsumer publishes a live Metrics snapshot through an Arc<Mutex>
  and exposes it via DeltaConsumer::metrics for in-flight polling.
- Unit tests cover the force_insert counter (including the bypass and
  out-of-window paths), the powers-of-two batch buckets, and the
  microsecond decade pause buckets. End-to-end tests on DeltaConsumer
  verify the synthetic backpressure path drives force_insert_count
  above zero and that the batch histogram accumulates samples covering
  every delivered item.
@oferchen
oferchen deleted the feat/drain-parallel-instrumentation-1545 branch May 19, 2026 19:29
oferchen added a commit that referenced this pull request Aug 24, 2026
…1545) (#4298)

Wires the metric prerequisites called out in
docs/design/drain-parallel-consumer-thread.md section 7 (and the
sequencing in section 10) into the production drain pipeline.

- HistogramStats: pow-2 count buckets and microsecond-decade duration
  buckets, shared between the new metrics fields.
- ReorderBuffer::force_insert now bumps a cumulative counter, exposed
  on the Metrics snapshot. Tracks the capacity-bound fallback that
  the design doc flags as a removal prerequisite.
- ReorderBuffer::record_drain_batch / record_drain_pause publish into
  two histograms on every non-empty consumer drain.
- DeltaConsumer publishes a live Metrics snapshot through an Arc<Mutex>
  and exposes it via DeltaConsumer::metrics for in-flight polling.
- Unit tests cover the force_insert counter (including the bypass and
  out-of-window paths), the powers-of-two batch buckets, and the
  microsecond decade pause buckets. End-to-end tests on DeltaConsumer
  verify the synthetic backpressure path drives force_insert_count
  above zero and that the batch histogram accumulates samples covering
  every delivered item.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant