Skip to content

feat(config): make adaptive_rate_limit optional in server config#1734

Merged
gaius-qi merged 1 commit intomainfrom
feature/bbr
Mar 18, 2026
Merged

feat(config): make adaptive_rate_limit optional in server config#1734
gaius-qi merged 1 commit intomainfrom
feature/bbr

Conversation

@gaius-qi
Copy link
Member

Description

This pull request makes the adaptive BBR (Bottleneck Bandwidth and Round-trip propagation time) rate limiting feature optional in the Dragonfly client configuration and gRPC server implementations. The main goal is to allow the servers to run without BBR-based rate limiting when it is not configured, improving flexibility and configurability.

Configuration changes:

  • Changed the adaptive_rate_limit field in the Server struct to be an Option<BBRConfig>, and updated its default value to None, making adaptive rate limiting optional in the configuration (dragonfly-client-config/src/dfdaemon.rs). [1] [2]

gRPC server changes (Download/Upload):

  • Updated both DfdaemonDownloadServer and DfdaemonUploadServer structs to make the bbr field optional (Option<Arc<BBR>>), and adjusted their constructors accordingly (dragonfly-client/src/grpc/dfdaemon_download.rs, dragonfly-client/src/grpc/dfdaemon_upload.rs). [1] [2] [3] [4]
  • Modified the gRPC server builder to wrap the BBR middleware layer with option_layer, so the BBR rate limiting middleware is only applied if configured (dragonfly-client/src/grpc/dfdaemon_download.rs, dragonfly-client/src/grpc/dfdaemon_upload.rs). [1] [2]

Dependency and import updates:

  • Added imports for tower::util::option_layer where necessary to support conditional middleware application. [1] [2]

Related Issue

Motivation and Context

Screenshots (if appropriate)

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

@chlins chlins 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 01d0d11 into main Mar 18, 2026
8 of 9 checks passed
@gaius-qi gaius-qi deleted the feature/bbr branch March 18, 2026 06:59
@mingcheng
Copy link
Member

LGTM

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR makes the dfdaemon gRPC servers’ BBR-based adaptive rate limiting configurable/optional by changing the server config from a mandatory BBRConfig to Option<BBRConfig>, and conditionally applying the BBR middleware layer only when configured.

Changes:

  • Change Server.adaptive_rate_limit to Option<BBRConfig> with a default of None (disabled by default).
  • Update download/upload gRPC server structs to carry Option<Arc<BBR>> and apply BBRLayer via tower::util::option_layer.
  • Update dfdaemon startup to only initialize BBR when adaptive_rate_limit is configured.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.

File Description
dragonfly-client-config/src/dfdaemon.rs Makes adaptive rate limit config optional and disables it by default.
dragonfly-client/src/bin/dfdaemon/main.rs Conditionally initializes the BBR limiter based on optional config.
dragonfly-client/src/grpc/dfdaemon_download.rs Makes BBR middleware optional and conditionally layers it into the server.
dragonfly-client/src/grpc/dfdaemon_upload.rs Makes BBR middleware optional and conditionally layers it into the server.

Comment on lines 405 to 412
/// BBR-inspired adaptive rate limiter configuration for gRPC servers (download & upload).
///
/// When system CPU or memory usage exceeds the configured thresholds, the limiter
/// estimates capacity via `max_pass × min_rt × bucket_count / 1000` and sheds
/// incoming requests whose in-flight count exceeds this estimate. A cooldown
/// period prevents rapid oscillation between shedding and accepting.
pub adaptive_rate_limit: BBRConfig,
pub adaptive_rate_limit: Option<BBRConfig>,
}
Comment on lines 414 to 421
@@ -417,7 +417,7 @@
Server {
plugin_dir: default_dfdaemon_plugin_dir(),
cache_dir: default_dfdaemon_cache_dir(),
adaptive_rate_limit: BBRConfig::default(),
adaptive_rate_limit: None,
}
@@ -113,7 +114,7 @@ pub struct DfdaemonDownloadServer {
persistent_cache_task: Arc<persistent_cache_task::PersistentCacheTask>,

/// BBR rate limiter middleware for adaptive rate limiting based on system load.
@@ -108,7 +109,7 @@ pub struct DfdaemonUploadServer {
system_monitor: Arc<SystemMonitor>,

/// BBR rate limiter middleware for adaptive rate limiting based on system load.
@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 10.00000% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.86%. Comparing base (e9ff969) to head (738af40).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
dragonfly-client/src/bin/dfdaemon/main.rs 0.00% 5 Missing ⚠️
dragonfly-client/src/grpc/dfdaemon_download.rs 0.00% 2 Missing ⚠️
dragonfly-client/src/grpc/dfdaemon_upload.rs 0.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1734      +/-   ##
==========================================
- Coverage   46.89%   46.86%   -0.04%     
==========================================
  Files          87       87              
  Lines       24811    24815       +4     
==========================================
- Hits        11636    11629       -7     
- Misses      13175    13186      +11     
Files with missing lines Coverage Δ
dragonfly-client-config/src/dfdaemon.rs 89.31% <100.00%> (ø)
dragonfly-client/src/grpc/dfdaemon_download.rs 5.03% <0.00%> (ø)
dragonfly-client/src/grpc/dfdaemon_upload.rs 0.00% <0.00%> (ø)
dragonfly-client/src/bin/dfdaemon/main.rs 0.00% <0.00%> (ø)

... 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.

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.

6 participants