Skip to content

[enhance](load) Isolate load cancellation in a dedicated thread pool - #68328

Open
sollhui wants to merge 4 commits into
apache:masterfrom
sollhui:improvement/isolate-load-rpc-work-pools
Open

sollhui wants to merge 4 commits into
apache:masterfrom
sollhui:improvement/isolate-load-rpc-work-pools

Conversation

@sollhui

@sollhui sollhui commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

tablet_writer_cancel shares the BRPC heavy work pool with load open, write, and close requests. When these operations saturate the pool, cancellation requests also queue behind them, delaying cancellation and resource release.

Dispatch tablet_writer_cancel through a dedicated brpc_load_light pool. Writer open and stream open remain in the heavy pool because they can block on locks or metadata RPCs; writes and closes also keep their existing scheduling. This isolates cancellation dispatch from heavy-pool congestion, while cancellation still follows the existing locking and cleanup logic.

The new pool adds queue-size, active-thread, and capacity metrics. brpc_load_light_work_pool_threads controls its worker count, defaults to 32, and accepts positive values. Its queue capacity is controlled by brpc_load_light_work_pool_max_queue_size: -1 selects max(1024, CPU cores * 32), and a positive value sets an explicit limit. Both settings require a BE restart.

Release note

Isolate tablet writer cancellation RPCs in a dedicated thread pool to reduce cancellation delays caused by a saturated BRPC heavy work pool.

Check List (For Author)

  • Test
    • Unit Test: added coverage for a non-default worker count, cancellation routing, and queue-full completion, plus checks that open, add-block, and streaming close retain the heavy pool. Tests have not been run.
    • Passed: clang-format 16, build header hygiene checks, and git diff --check.
    • BE compilation and runtime tests have not been completed.
  • Behavior changed:
    • Yes. Tablet writer cancellation uses a dedicated pool.
  • Does this need documentation?
    • No separate documentation change. Pool sizing and queue configuration are documented in code comments.

### What problem does this PR solve?

When load writes, flush waits, or closes occupy the shared BRPC heavy pool, `tablet_writer_open`, `tablet_writer_cancel`, and `open_load_stream` queue behind that work. In particular, a cancellation intended to release load resources cannot be dispatched promptly under heavy-pool saturation.

Add two dedicated load pools:
- `brpc_load_light`: writer open/cancel and stream open.
- `brpc_load_heavy`: add-block RPCs (including the HTTP forwarding path) and `LoadStreamMgr` flush/pre-close/close tasks.

Both pools have independent thread/queue settings and queue-size, active-thread, effective thread-limit, and effective queue-limit metrics. The four new `brpc_load_{heavy,light}_work_pool_{threads,max_queue_size}` settings require a restart and accept `-1` or a positive value. By default, load-heavy inherits the existing heavy-pool settings; load-light uses `max(32, CPU cores)` threads and `max(1024, CPU cores * 32)` queued requests.

The split reserves execution capacity for load control requests. It does not remove locks or storage operations inside open/cancel, and it creates additional fixed worker threads. Existing generic heavy/light pools, RPC response contracts, and storage/transaction semantics are retained. No throughput or latency benchmark is claimed.

### Release note

Isolate load open and cancellation RPCs from load write/close queues to reduce control-request queueing under load. Add independently configurable load-heavy and load-light BRPC worker pools and metrics.

### Check List (For Author)

- Test
    - [x] Unit Test: added deterministic queue-routing and queue-full callback/status coverage for writer open/cancel, stream open, and add-block, plus streaming close-pool wiring. **Not executed**, as requested by the author.
    - Validation completed: clang-format 16.0.5 on all five changed C++ files and `git diff --check`.
    - Build/UT execution skipped at the author's request. An initial build-environment probe was stopped during third-party dependency setup; no BE build or test result is claimed.
- Behavior changed:
    - [x] Yes. Load control and data requests use separate pools; existing generic RPC pools retain their configuration names.
- Does this need documentation?
    - [x] No separate documentation change in this PR. New tuning defaults and restart requirements are documented alongside the BE configuration declarations.

### Review notes

- Concurrency: only dispatch destinations change; handlers retain their existing locks and memory-tracking contexts. The new pools introduce no new lock order.
- Lifetime: pools remain owned by `PInternalService`; `LoadStreamMgr` borrows its load-heavy pool using the existing ownership model. New metric hooks are deregistered on destruction.
- Compatibility: no protobuf, persistent format, FE variable, visibility, or transaction protocol change.
- Parallel paths: HTTP add-block delegates to the modified RPC; streaming open and flush/close are included; shared service dispatch covers cloud and local storage modes.
- Failure handling: queue rejection reports the destination pool and preserves exactly-once completion behavior, including the empty cancellation response.
- Coverage limit: the added tests cover dispatch/backpressure and wiring; end-to-end load behavior and performance were not exercised.
@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?

### What problem does this PR solve?

Problem Summary: Keep load open/cancel isolated with one dedicated load-light pool,
while retaining the existing heavy pool for writes and streaming flush/close.
Remove the redundant load-heavy pool and its settings and metrics, reducing the
additional fixed worker count. Update dispatch and backpressure test coverage.

### Release note

Only load control RPCs use the new load-light pool. Existing heavy-pool settings
and metrics continue to apply to load data work.

### Check List (For Author)

- Test: Updated unit tests; compilation and test execution skipped at user request.
  Formatting, build header hygiene, and git diff --check passed.
- Behavior changed: Yes; load data work uses the original heavy pool.
- Does this need documentation: No; configuration comments describe the new pool.
@sollhui sollhui changed the title [improvement](be) Isolate load control RPCs from heavy load work [improvement](be) Isolate load open and cancel RPCs in a dedicated pool Sep 21, 2026
### What problem does this PR solve?

Problem Summary: Open requests can block on locks or metadata RPCs and exhaust
workers shared with cancellation. Route only tablet_writer_cancel to load-light,
restore both open handlers to the existing heavy pool, and fix the cancellation
worker count at 32. Keep queue capacity configurable and update metrics and tests.

### Release note

Only tablet writer cancellation uses the dedicated 32-thread pool. Load open,
write, and close continue using the existing heavy pool.

### Check List (For Author)

- Test: Updated unit tests; compilation and execution skipped at user request.
  Clang-format 16, build header hygiene, and git diff --check passed.
- Behavior changed: Yes; only cancellation moves to a fixed 32-thread pool.
- Does this need documentation: No; code/config comments describe the settings.
@sollhui sollhui changed the title [improvement](be) Isolate load open and cancel RPCs in a dedicated pool [improvement](be) Isolate load cancellation in a fixed 32-thread pool Sep 21, 2026
@sollhui sollhui changed the title [improvement](be) Isolate load cancellation in a fixed 32-thread pool [improvement](be) Isolate load cancellation in a dedicated thread pool Sep 21, 2026
### What problem does this PR solve?

Problem Summary: Replace the hard-coded cancellation worker count with
brpc_load_light_work_pool_threads, defaulting to 32. Validate that the value is
positive, use it when constructing the pool, and expose it in the capacity
metric. Update unit test coverage to use a non-default worker count.

### Release note

Allow configuring the cancellation pool worker count, default 32. A BE restart
is required for changes to take effect.

### Check List (For Author)

- Test: Unit tests updated but not run; compilation skipped at user request.
  Clang-format 16, header hygiene, and git diff --check passed.
- Behavior changed: Yes; cancellation worker count is configurable.
- Does this need documentation: No separate change; defaults and restart
  requirements are documented in configuration comments.
@sollhui

sollhui commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@sollhui sollhui changed the title [improvement](be) Isolate load cancellation in a dedicated thread pool [enhance](load) Isolate load cancellation in a dedicated thread pool Sep 21, 2026
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