[improvement](be) Add CPU-aware S3 rate limiter#65420
Open
0AyanamiRei wants to merge 11 commits into
Open
Conversation
Add three new CPU-aware S3 limiter configs: - s3_get_token_per_second_per_core: GET QPS per CPU core (0 to disable) - s3_put_token_per_second_per_core: PUT QPS per CPU core (0 to disable) - token_per_second_max: Hard cap on derived QPS (0 means no cap) When per-core values are > 0, effective QPS = per_core_value * CpuInfo::num_cores() When per-core values are = 0, existing absolute configs are used (preserving backward compatibility). All new configs default to 0, maintaining existing behavior. Affected files: - be/src/common/config.h: Added DECLARE statements - be/src/common/config.cpp: Added DEFINE statements with validators Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Fix naming inconsistency: all other S3 rate-limiter config options carry the s3_ prefix. This public API change must be fixed now before downstream code starts using these configs. - DECLARE_mInt64(s3_token_per_second_max) in config.h - DEFINE_mInt64(s3_token_per_second_max) in config.cpp - DEFINE_Validator(s3_token_per_second_max) in config.cpp Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add S3RateLimiterConfig struct and get_effective_s3_rate_limiter_config() to centralize the logic for computing effective rate limiter parameters from both legacy configs and new per-core configs. Changes: - Add S3RateLimiterConfig struct in s3_util.h - Add get_effective_s3_rate_limiter_config() declaration and implementation - Add helper functions checked_positive_product() and apply_s3_token_per_second_max() - Add required includes: <limits> and util/cpu_info.h This is Task 2 of the S3 rate limiter refactoring. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…n and dynamic reset
Replace raw config::s3_{get,put}_* accesses with get_effective_s3_rate_limiter_config()
in both S3ClientFactory constructor (initialization) and check_s3_rate_limiter_config_changed()
(dynamic reset). This ensures per-core QPS scaling and the s3_token_per_second_max cap are
applied consistently at startup and on every dynamic config check.
Also add an INFO log on successful limiter reset to make config changes observable in logs.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Cover four scenarios: absolute GET config, per-core GET without cap, per-core GET with cap, and per-core PUT with cap. Add S3RateLimiterConfigGuard RAII helper to save/restore all nine related configs after each test. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Replace manual save/restore of 3 config values with S3RateLimiterConfigGuard that handles all 9 relevant S3 rate limiter configs. This prevents state contamination between tests. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
…r-core and cap config
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
### What problem does this PR solve?
Issue Number: None
Related PR: None
Problem Summary: CPU-aware S3 rate limiter calculation multiplied per-core QPS by BE CPU cores before applying s3_token_per_second_max. Extremely large mutable per-core settings could overflow int64 and trigger a CHECK even when a valid max cap was configured. This change computes the CPU-derived QPS with a wider intermediate value and applies the configured cap safely. It also adds unit coverage for the overflow-with-cap case and PUT limiter rebuild when the max cap changes.
### Release note
None
### Check List (For Author)
- Test: Unit Test
- ./run-be-ut.sh --run --filter=S3UTILTest.effective_s3_rate_limiter_config_caps_overflowing_per_core_get_config
- ./run-be-ut.sh --run --filter='S3UTILTest.*'
- Behavior changed: No
- Does this need documentation: No
5287ce9 to
a4effbe
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
Issue Number: None
Related PR: None
Problem Summary:
The existing S3 GET/PUT token bucket rate limiter uses fixed per-BE QPS settings. This is not suitable for heterogeneous deployments because a BE with many CPU cores and a BE with few CPU cores receive the same S3 request budget.
This PR adds CPU-aware S3 rate limiter settings for GET and PUT requests. When the new per-core settings are left as 0, Doris keeps the existing absolute limiter behavior. When a per-core setting is positive, Doris derives the effective per-BE S3 QPS from BE CPU cores and caps it with s3_token_per_second_max when configured.
The PR also centralizes effective limiter config calculation, reuses it for initialization and dynamic rebuild, and guards CPU-derived QPS calculation from overflow before applying the max cap.
Release note
Add BE configs to support CPU-aware S3 GET/PUT request rate limiting.
Check List (For Author)
Test
Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)