Skip to content

perf(telemetry): reserve flush lock before spawning tasks - #478

Merged
aakash-saravanan-db merged 1 commit into
mainfrom
aakash-saravanan_data/aakash-saravanan/telemetry-flush-coalescing
Nov 18, 2026
Merged

aakash-saravanan-db merged 1 commit into
mainfrom
aakash-saravanan_data/aakash-saravanan/telemetry-flush-coalescing

Conversation

@aakash-saravanan-db

Copy link
Copy Markdown
Collaborator

Telemetry enqueue schedules a flush task for every event while the pending queue is above the batch threshold. Those tasks only compete for the flush lock after they start running.

Before: A burst of 2,000 events with a batch size of 100 can schedule 1,901 tasks before the runtime runs any of them, although only one export needs to drain that queue.

After: Enqueue attempts to reserve the existing flush mutex before spawning and transfers its owned guard into the task. Each client has at most one flush task triggered by the threshold scheduled or running. Events arriving during an export remain queued for the next threshold enqueue, timer flush, or bounded close flush.

The deterministic burst test verifies one scheduled task and all 2,000 events exported. This removes redundant task creation and scheduling work during bursts; it does not establish an isolated query-throughput improvement or resolve telemetry endpoint throttling.

Validation

  • Added two focused tests: deterministic burst/task count with exact event preservation, and events queued during export subsequently flushed by timer or close.
  • Full cargo test --locked: 1,322 passed, 64 ignored, including doc tests.
  • Formatting and cargo clippy --locked --all-targets -- -D warnings passed.

Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Terra), checked by a judge model (Claude Sonnet 5.5).

✅ No issues identified.

🔀 1 finding considered and dismissed by the judge
  • 🔵 Low src/telemetry/client.rs:370 — Closing before checking the captured events lets the close flush mask a threshold task that ran but failed to export the burst. Drive the scheduled task to comp
    Judge's evidence: assert_eq!(runtime.metrics().num_alive_tasks(), 1);

@aakash-saravanan-db
aakash-saravanan-db added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit 96572a2 Nov 18, 2026
28 of 29 checks passed

This branch was previously deployed

1 inactive deployment
azure-prod — 114dc00d Deployed Nov 17, 2026 by aakash-saravanan-db via review #1348
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants