Skip to content

[improvement](be) Add CPU-aware S3 rate limiter#65420

Open
0AyanamiRei wants to merge 11 commits into
apache:masterfrom
0AyanamiRei:feature/cpu-aware-s3-limiter
Open

[improvement](be) Add CPU-aware S3 rate limiter#65420
0AyanamiRei wants to merge 11 commits into
apache:masterfrom
0AyanamiRei:feature/cpu-aware-s3-limiter

Conversation

@0AyanamiRei

@0AyanamiRei 0AyanamiRei commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

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

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

0AyanamiRei and others added 9 commits July 9, 2026 15:14
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>
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@0AyanamiRei 0AyanamiRei changed the title [feature](be) Add CPU-aware S3 rate limiter [improvement](be) Add CPU-aware S3 rate limiter Jul 9, 2026
### 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
@0AyanamiRei 0AyanamiRei force-pushed the feature/cpu-aware-s3-limiter branch from 5287ce9 to a4effbe Compare July 9, 2026 11:24
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