Skip to content

[ISSUE #7608]✨Drive ProduceAccumulator guards by deadline#7609

Merged
mxsm merged 1 commit into
mainfrom
mxsm/issue-7608-guard-deadline-driven
Jun 27, 2026
Merged

[ISSUE #7608]✨Drive ProduceAccumulator guards by deadline#7609
mxsm merged 1 commit into
mainfrom
mxsm/issue-7608-guard-deadline-driven

Conversation

@mxsm

@mxsm mxsm commented Jun 27, 2026

Copy link
Copy Markdown
Owner

Which Issue(s) This PR Fixes(Closes)

Brief Description

Replaces the ProduceAccumulator guard fixed-tick full-map scan with deadline-driven scheduling. Each newly created batch registers key + create_time + deadline with the sync or async guard, and each guard maintains a deadline min-heap so it only wakes for the nearest deadline, a new schedule event, or shutdown.

The sync guard now notifies waiting sync senders when a batch reaches its deadline. The async guard removes and sends only the due batch after re-checking that the batch is still open and still matches the scheduled create_time. Batches flushed early by size are handled through lazy deletion when their stale deadline entry is later observed.

This also exposes guard wakeup/flush/idle counters through the lifecycle probe and adds a 64-key low-activity benchmark for full-scan vs deadline-heap scheduling.

Latest local guard benchmark data:

Case Full scan mean Deadline heap mean Improvement
64 keys, low activity 44,827.48 ns 759.16 ns 98.31%

Lifecycle benchmark mean: 170.87 us for task-group shutdown.

How Did You Test This Change?

  • cargo fmt --all - passed
  • cargo test -p rocketmq-client-rust --lib produce_accumulator - passed, 25 tests
  • cargo clippy --workspace --no-deps --all-targets --all-features -- -D warnings - passed
  • cargo bench -p rocketmq-client-rust --bench produce_accumulator_guard_lifecycle_bench - passed, latest lifecycle mean 170.87 us
  • cargo bench -p rocketmq-client-rust --bench produce_accumulator_benchmark - passed, guard deadline scheduler improvement 98.31%
  • cargo fmt --all from rocketmq-example - passed
  • cargo clippy --all-targets -- -D warnings from rocketmq-example - failed on existing shared-client compile error: ScheduledTaskManager::new_legacy_compatibility is missing in rocketmq-client/src/factory/mq_client_instance.rs
  • cargo fmt --all from rocketmq-dashboard/rocketmq-dashboard-web/backend - passed
  • cargo clippy --all-targets --all-features -- -D warnings from rocketmq-dashboard/rocketmq-dashboard-web/backend - passed
  • cargo build --all-targets --all-features from rocketmq-dashboard/rocketmq-dashboard-web/backend - passed
  • cargo fmt --all from rocketmq-dashboard/rocketmq-dashboard-tauri/src-tauri - passed
  • cargo clippy --all-targets --all-features -- -D warnings from rocketmq-dashboard/rocketmq-dashboard-tauri/src-tauri - failed on the same existing shared-client ScheduledTaskManager::new_legacy_compatibility compile error

Summary by CodeRabbit

  • New Features
    • Added deadline-based batch scheduling for producer operations, improving how pending work is triggered and processed.
    • Introduced new guard metrics that can be inspected at runtime to understand wakeups, flushes, and idle cycles.
  • Bug Fixes
    • Improved handling of expired or removed batches so they are ignored safely during scheduling.
    • Reduced unnecessary polling by waking only when deadlines or new work arrive.

@rocketmq-rust-bot

Copy link
Copy Markdown
Collaborator

🔊@mxsm 🚀Thanks for your contribution🎉!

💡CodeRabbit(AI) will review your code first🔥!

Note

🚨The code review suggestions from CodeRabbit are to be used as a reference only, and the PR submitter can decide whether to make changes based on their own judgment. Ultimately, the project management personnel will conduct the final code review💥.

@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

Replaces periodic tick-based polling in ProduceAccumulator sync and async batch guards with deadline-driven scheduling using a BinaryHeap min-heap. Adds BatchGuardMetrics atomic counters and public snapshot types, updates batch creation to enqueue deadlines via mpsc, and adds corresponding tests and Criterion benchmarks.

Deadline-driven batch guard scheduling

Layer / File(s) Summary
Metrics types and scheduling contracts
rocketmq-client/src/producer/produce_accumulator.rs
Adds BatchGuardMetrics, BatchGuardMetricsSnapshot, ProduceAccumulatorGuardMetricsSnapshot, GuardScheduleCommand, GuardDeadline, and BatchMap type alias.
Deadline scheduling primitives and drain helpers
rocketmq-client/src/producer/produce_accumulator.rs
Introduces GuardWakeEvent, push_guard_deadline, wait_guard_deadline_or_schedule, drain_due_sync_batches, and drain_due_async_batches; replaces prior tick model and records wakeup/flush/idle metrics.
GuardForSyncSendService and GuardForAsyncSendService refactor
rocketmq-client/src/producer/produce_accumulator.rs
Adds schedule_tx and metrics fields to both guard structs; start() runs deadline loop; schedule_batch() enqueues commands; shutdown paths clear schedule_tx; metrics_snapshot() added.
ProduceAccumulator wiring and public API
rocketmq-client/src/producer/produce_accumulator.rs
Updates new() to use constructors; rewrites get_or_create_*_send_batch with dashmap entry APIs and schedule_batch calls; adds guard_metrics_snapshot(); extends lifecycle probe.
Tests and benchmarks
rocketmq-client/src/producer/produce_accumulator.rs, rocketmq-client/benches/produce_accumulator_benchmark.rs
Adds tokio tests for deadline notification and stale-batch lazy-ignore; adds BenchDeadline, full-scan and heap benchmark functions, and bench_guard_deadline_scheduler Criterion group.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

🐇 Tick-tock, no more scanning the clock,
A heap of deadlines, neatly in stock.
Each batch gets a slot, then sleeps till it's due,
Metrics count flushes, idle ones too.
The rabbit rejoices — less work, more snooze! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states the core change: driving ProduceAccumulator guards by deadline, and it matches the PR scope.
Linked Issues check ✅ Passed The changes implement the requested deadline-driven guards, metrics, benchmarks, and stale-entry handling from issue #7608.
Out of Scope Changes check ✅ Passed No unrelated code changes are evident beyond the requested guard scheduling, metrics, tests, and benchmark updates.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mxsm/issue-7608-guard-deadline-driven

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mxsm mxsm merged commit 7735b2b into main Jun 27, 2026
25 of 28 checks passed
@rocketmq-rust-bot rocketmq-rust-bot added approved PR has approved and removed ready to review waiting-review waiting review this PR labels Jun 27, 2026
@codecov

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 61.51316% with 117 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.19%. Comparing base (083d556) to head (7d5de8f).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ocketmq-client/src/producer/produce_accumulator.rs 61.51% 117 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7609      +/-   ##
==========================================
+ Coverage   69.17%   69.19%   +0.01%     
==========================================
  Files        1234     1234              
  Lines      268790   269002     +212     
==========================================
+ Hits       185944   186138     +194     
- Misses      82846    82864      +18     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement✨] Drive ProduceAccumulator batch guards by deadlines

3 participants