Skip to content

feat: refactor ratelimit to ratelimiter and improve BBR adaptive rate limiter#1672

Merged
gaius-qi merged 1 commit intomainfrom
feature/bbr
Feb 9, 2026
Merged

feat: refactor ratelimit to ratelimiter and improve BBR adaptive rate limiter#1672
gaius-qi merged 1 commit intomainfrom
feature/bbr

Conversation

@gaius-qi
Copy link
Member

@gaius-qi gaius-qi commented Feb 9, 2026

  • Rename ratelimit module to ratelimiter for clearer naming convention.
  • Refactor BBR rolling window to remove per-sample timestamps and rely on ring buffer eviction for expiration, simplifying Sample struct and get_stats logic.
  • Add bucket_count field and accessor to RollingWindow for use in estimated limit calculation.
  • Integrate OverloadCollector with container-aware CPU/memory sampling and background collection loop with graceful shutdown support.
  • Add RequestGuard RAII pattern for automatic metric recording and in-flight counter management.
  • Move container detection logic from cpu.rs/memory.rs cgroup methods up to OverloadCollector, removing redundant is_running_in_container checks in get_cgroup_stats.
  • Reduce CPU cgroup refresh interval from 1s to 500ms for more responsive overload detection.
  • Use Self constructor shorthand in GC::new.

Description

This pull request introduces several improvements and code cleanups across the dragonfly-client-util and dragonfly-client crates. The most significant changes involve renaming a module for clarity, optimizing CPU refresh intervals, and simplifying cgroup resource checks for CPU and memory statistics.

Module renaming and code cleanup:

  • Renamed the ratelimit module to ratelimiter in dragonfly-client-util/src/lib.rs for consistency and clarity.

Resource statistics logic simplification:

  • Removed unnecessary container environment checks (is_running_in_container) from cgroup CPU and memory statistics retrieval, allowing stats to be fetched regardless of container status in dragonfly-client-util/src/sysinfo/cpu.rs and dragonfly-client-util/src/sysinfo/memory.rs. [1] [2]

Performance improvements:

  • Reduced the default CPU refresh interval from 1 second to 500 milliseconds in dragonfly-client-util/src/sysinfo/cpu.rs for more frequent updates.

Minor code style improvements:

  • Changed struct initialization in dragonfly-client/src/gc/mod.rs to use Self instead of explicit struct name for idiomatic Rust style.

Related Issue

Motivation and Context

Screenshots (if appropriate)

… limiter

- Rename `ratelimit` module to `ratelimiter` for clearer naming convention.
- Refactor BBR rolling window to remove per-sample timestamps and rely on
  ring buffer eviction for expiration, simplifying `Sample` struct and
  `get_stats` logic.
- Add `bucket_count` field and accessor to `RollingWindow` for use in
  estimated limit calculation.
- Integrate `OverloadCollector` with container-aware CPU/memory sampling
  and background collection loop with graceful shutdown support.
- Add `RequestGuard` RAII pattern for automatic metric recording and
  in-flight counter management.
- Move container detection logic from `cpu.rs`/`memory.rs` cgroup methods
  up to `OverloadCollector`, removing redundant `is_running_in_container`
  checks in `get_cgroup_stats`.
- Reduce CPU cgroup refresh interval from 1s to 500ms for more responsive
  overload detection.
- Use `Self` constructor shorthand in `GC::new`.

Signed-off-by: Gaius <gaius.qi@gmail.com>
@gaius-qi gaius-qi added this to the v2.5.0 milestone Feb 9, 2026
@gaius-qi gaius-qi self-assigned this Feb 9, 2026
@gaius-qi gaius-qi added the enhancement New feature or request label Feb 9, 2026
@codecov
Copy link

codecov bot commented Feb 9, 2026

Codecov Report

❌ Patch coverage is 64.26799% with 144 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.44%. Comparing base (035ae91) to head (822ea35).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
dragonfly-client-util/src/ratelimiter/bbr.rs 64.42% 143 Missing ⚠️
dragonfly-client/src/gc/mod.rs 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1672      +/-   ##
==========================================
- Coverage   50.83%   50.44%   -0.39%     
==========================================
  Files          83       83              
  Lines       20029    20157     +128     
==========================================
- Hits        10182    10169      -13     
- Misses       9847     9988     +141     
Files with missing lines Coverage Δ
dragonfly-client-util/src/sysinfo/cpu.rs 0.00% <ø> (ø)
dragonfly-client-util/src/sysinfo/memory.rs 0.00% <ø> (ø)
dragonfly-client/src/gc/mod.rs 0.00% <0.00%> (ø)
dragonfly-client-util/src/ratelimiter/bbr.rs 64.42% <64.42%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gaius-qi gaius-qi enabled auto-merge (squash) February 9, 2026 13:37
Copy link
Member

@EvanCley EvanCley left a comment

Choose a reason for hiding this comment

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

lgtm

@gaius-qi gaius-qi merged commit 52c81ae into main Feb 9, 2026
9 checks passed
@gaius-qi gaius-qi deleted the feature/bbr branch February 9, 2026 15:35
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.

3 participants