Skip to content

branch-4.1: [improvement](cloud) Add dry-run mode for BE-to-MS RPC rate limiting #66977 - #67240

Merged
yiguolei merged 1 commit into
branch-4.1from
auto-pick-66977-branch-4.1
Sep 6, 2026
Merged

branch-4.1: [improvement](cloud) Add dry-run mode for BE-to-MS RPC rate limiting #66977#67240
yiguolei merged 1 commit into
branch-4.1from
auto-pick-66977-branch-4.1

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Cherry-picked from #66977

@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?

@hello-stephen

Copy link
Copy Markdown
Contributor

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

Cloud UT Coverage Report

Increment line coverage 🎉

Increment coverage report
Complete coverage report

CategoryCoverage
Function Coverage78.25% (1939/2478)
Line Coverage64.92% (34517/53165)
Region Coverage52.32% (33015/63106)
Branch Coverage55.00% (10149/18454)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 76.19% (176/231) 🎉

Increment coverage report
Complete coverage report

CategoryCoverage
Function Coverage59.45% (25676/43192)
Line Coverage43.93% (262490/597455)
Region Coverage39.86% (207975/521775)
Branch Coverage41.34% (95893/231947)

@bobhan1

Copy link
Copy Markdown
Contributor

run external

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 88.31% (204/231) 🎉

Increment coverage report
Complete coverage report

CategoryCoverage
Function Coverage74.22% (31237/42085)
Line Coverage58.37% (346108/592963)
Region Coverage55.09% (288173/523054)
Branch Coverage56.00% (129748/231681)

@morrySnow
morrySnowforce-pushed the auto-pick-66977-branch-4.1 branch from 5775718 to a10f932CompareAugust 31, 2026 07:14
@bobhan1

Copy link
Copy Markdown
Contributor

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

Cloud UT Coverage Report

Increment line coverage 🎉

Increment coverage report
Complete coverage report

CategoryCoverage
Function Coverage78.32% (1944/2482)
Line Coverage64.90% (34555/53244)
Region Coverage52.39% (33122/63220)
Branch Coverage55.01% (10172/18492)

…66977)
### What problem does this PR solve?
Issue Number: N/A
Related PR: #66969, #66940
Problem Summary: BE-to-MetaService host-level and table-level rate
limiting needs production-safe observability before thresholds are
enforced. This PR adds dry-run switches for both paths. Dry-run keeps
limit evaluation, would-wait metrics, per-table QPS collection, and
table-level MS_BUSY state transitions active, but does not delay
requests.
| Scope | New config | Default | Existing enforcement config | Purpose |
| --- | --- | --- | --- | --- |
| Host-level | `enable_ms_rpc_host_level_rate_limit_dry_run` | `true` |
`enable_ms_rpc_host_level_rate_limit` (default `false`) | Evaluate each
configured per-RPC token bucket, record would-wait observations, and log
would-throttle decisions without sleeping. |
| Table-level | `enable_ms_backpressure_handling_dry_run` | `true` |
`enable_ms_backpressure_handling` (default `false`) | Keep per-table QPS
collection and the MS_BUSY adaptive-throttling state machine active, but
do not sleep on a throttle decision. |
For each scope, the dry-run and enforcement configs interact as follows:
- When both configs are `false`, rate-limit evaluation for that scope is
disabled.
- When only the enforcement config is `true`, the limiter is enforced
and the request sleeps for the calculated wait time.
- When the dry-run config is `true`, dry-run takes precedence regardless
of the enforcement config: the limiter state, metrics, and logs are
updated, but the request does not sleep.
Both host-level and table-level dry-run paths reserve against the same
limiter state used by enforcement, matching the FE dry-run model:
dry-run suppresses sleeping but preserves reservation state. When a
table-level downgrade restores a previous QPS limit, it resets queued
reservations so stale wait debt does not carry into the relaxed limit;
the final downgrade removes the limiter.
The table-level coordinator uses 64-bit counters with overflow-free
saturation at each timing threshold. Its MS_BUSY downgrade timer is
reset to inactive when there is no pending upgrade history, while the
upgrade cooldown counter is preserved and stops at the configured
threshold so runtime cooldown changes retain the existing timing
semantics.
### Signals after rate limiting is triggered
Throttle-decision logs use `INFO` level and are suppressed independently
per RPC type to at most one log per second. They are emitted only when
the limiter calculates a positive wait.
Host-level dry-run logs explicitly report the estimated wait:
```text
[ms-throttle] host-level rate limiter dry run would throttle MS RPC request, rpc=get rowset, estimated_wait_ns=1250000, qps_limit=320
```
With enforcement enabled and dry-run disabled, the corresponding log
reports the actual sleep:
```text
[ms-throttle] host-level rate limiter throttled MS RPC request, rpc=get rowset, sleep_ns=1250000, qps_limit=320
```
Table-level dry-run and enforcement use the same trigger log so
operators can search one stable pattern:
```text
[ms-throttle] table-level rate limiter triggered for MS RPC request, rpc=commit_rowset, table_id=10001, wait_us=8200, current_qps=146.7, qps_limit=100
```
For table-level dry-run, `wait_us` is the estimated wait and the request
is not delayed. With enforcement enabled and dry-run disabled, the
request sleeps for that wait. MS_BUSY-driven table-level state
transitions also emit `INFO` logs, for example:
```text
[ms-throttle] received MS_BUSY, triggering upgrade
[ms-throttle] upgrade: rpc=commit_rowset, table_id=10001, current_qps=200, old_limit=0, new_limit=150
[ms-throttle] downgrade: rpc=commit_rowset, table_id=10001, removed limit
```
The same events are observable through bvars: host-level per-RPC latency
recorders based on `host_level_ms_rpc_rate_limit_sleep`, table-level
`ms_rpc_backpressure_throttle_wait_<rpc>` latency recorders, and
`ms_rpc_backpressure_ms_busy_*`, `ms_rpc_backpressure_upgrade_*`, and
`ms_rpc_backpressure_downgrade_*` counters/windows.
### Release note
Add dry-run observation for BE-to-MetaService host-level and table-level
RPC rate limiting without delaying requests. Both dry-run switches are
enabled by default and take precedence over enforcement. Dry-run and
enforcement share limiter reservation state, table-level downgrade
resets queued reservations when restoring a previous QPS limit, and
long-running table-level coordinator timers no longer overflow.
### Check List (For Author)
- Test
- [ ] Regression test
- [x] Unit Test
- `./run-be-ut.sh --run
--filter='HostLevelMSRpcRateLimitersTest.*:StrictQpsLimiterTest.*:TableRpcThrottlerTest.*:MSBackpressureHandlerTest.*:RpcThrottleStateMachineTest.*:RpcThrottleIntegrationTest.*'
-j100` (56 tests passed)
- `./run-be-ut.sh --run
--filter='TokenBucketRateLimiterTest.*:S3RateLimiterManagerTest.*:S3RateLimiterMetricsTest.*'
-j100` (11 tests passed)
- `./run-be-ut.sh --run
--filter='MSBackpressureHandlerTest.*:RpcThrottleStateMachineTest.*:RpcThrottleCoordinatorTest.*:RpcThrottleIntegrationTest.*'
-j100` (44 tests passed)
- `./build.sh --be -j100`
- `build-support/check-format.sh`
- `build-support/check-build-hygiene.sh`
- [ ] 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.
- [x] Yes. Dry-run observation for both limiter levels is enabled by
default and does not delay MetaService RPCs; dry-run and enforcement
share reservation state; table-level downgrade resets queued
reservations; coordinator timing counters saturate without overflowing;
actual and dry-run decisions emit per-RPC rate-limited `INFO` logs.
- Does this need documentation?
- [x] No.
- [ ] Yes.
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label
@yiguolei
yiguoleiforce-pushed the auto-pick-66977-branch-4.1 branch from a10f932 to f86296bCompareSeptember 5, 2026 22:17
@yiguolei

Copy link
Copy Markdown
Contributor

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

Cloud UT Coverage Report

Increment line coverage 🎉

Increment coverage report
Complete coverage report

CategoryCoverage
Function Coverage78.33% (1945/2483)
Line Coverage64.91% (34604/53308)
Region Coverage52.30% (33093/63273)
Branch Coverage55.03% (10181/18500)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 88.31% (204/231) 🎉

Increment coverage report
Complete coverage report

CategoryCoverage
Function Coverage74.41% (31371/42158)
Line Coverage58.57% (348573/595136)
Region Coverage55.34% (291008/525857)
Branch Coverage56.16% (131000/233256)

@github-actions

Copy link
Copy Markdown
ContributorAuthor

PR approved by anyone and no changes requested.

@github-actionsgithub-actionsBot added the approved Indicates a PR has been approved by one committer. label Sep 6, 2026
@github-actions

Copy link
Copy Markdown
ContributorAuthor

PR approved by at least one committer and no changes requested.

@yiguolei
yiguolei merged commit 7c165f1 into branch-4.1Sep 6, 2026
32 of 35 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approvedIndicates a PR has been approved by one committer.reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@hello-stephen@bobhan1@yiguolei