deardeng opened a new pull request, #71151: URL: https://github.com/apache/doris/pull/71151
pick from https://github.com/apache/doris/pull/69071 Related PR: #65658 Problem Summary: The async file cache write path (#65658) never read from peers: with peer read enabled, `_resolve_cache_write_mode` fell back to SYNC_WRITE, and the async path forced `bypass_peer_read`. So a cluster could use async write (for slow cache disks) or peer cache, but not both. This PR lets the async path read its misses from peers. Peer data stays zero-copy: the RPC attachment IOBuf goes into the inflight index and is persisted with `FileBlock::append_iobuf`; the only copy is into the user buffer. 1. **Peer chain takes ranges.** `PeerFileCacheReader::fetch_blocks` and the peer dispatch helpers take `std::vector<FileBlock::Range>` instead of `FileBlockSPtr`, because the async path has no `FileBlock` for its misses. 2. **IOBuf-backed async write buffers.** `AsyncCacheWriteManager::wrap_iobuf()` wraps one peer block without copying and charges it to the async-write MemTracker. 3. **Async path reads from peers**, same span rules as the sync path: - a span of pure misses is sent to peer as is; - cached / inflight blocks between misses are read locally, and peer is asked only for the misses; - a span with a DOWNLOADING block, or whose tablet has no usable peer candidate, reads from storage as before. 4. **Race S3 pool size.** `PeerRaceS3ThreadPool` runs the S3 leg of every peer/S3 race (sync and async). It had 32 threads for 64 race slots and an unbounded queue; it is now sized `max(max_peer_race_s3_thread_num, max_concurrent_peer_races)`, 64 by default. 5. **Fixes along the way.** - `BytesReadFrom{Cross,Same}CGPeer` counted the whole span instead of the bytes peer returned, which also overcounted on the sync path. - The race lambda copied its arguments twice; now it copies once. 6. **Observability.** - Profile: `AsyncCopyToUserTimer`, `AsyncSubmitWriteTimer`. - Bvars: `cached_remote_file_reader_async_peer_{eligible,no_candidate,bypass}_span_count`. ### Performance Cold full scan of SSB SF1000 `lineorder` (6.0 B rows, 17 columns, 135.8 GB). One source BE with a warm cache and one reader BE, in different compute groups. Default race config. Medians of 3 runs. - **A**: sync write + peer - **B**: async write + S3 (async write before this PR) - **C**: async write + peer (this PR) | Source → reader cache disk | Scanners | A | B | C | C vs B | C vs A | S3 GETs, C vs B | |:--|--:|--:|--:|--:|--:|--:|--:| | NVMe → PL1 | 64 | 216.7 s | 100.7 s | **43.8 s** | **−57%** | **−80%** | −91% | | NVMe → PL1 | 128 | 217.2 s | 55.2 s | **44.2 s** | **−20%** | **−80%** | −90% | | NVMe → NVMe ¹ | 64 | 42.6 s | 104.8 s | 44.9 s | −57% | +6% | −99.9% | | NVMe → NVMe ¹ | 128 | 43.1 s | 60.6 s | 45.6 s | −25% | +6% | −99.9% | | PL1 → PL1 | 64 | 222.8 s | 100.7 s | 127.3 s | +27% | −43% | −28% | | PL1 → PL1 | 128 | – | 56.1 s | 111.9 s | +99% | – | −32% | ¹ Tuned race config (256 slots / 256 S3 threads), not rerun at the default. - **C beats B when the peer source is faster than S3.** With a PL1 source (~0.5 GB/s) peer is slower than S3. Most of that loss comes from the race config: with a larger S3 pool and no hedge delay, C matches B. - **C beats A when the reader's cache disk is slow.** On an NVMe reader, A pays almost nothing for the cache write, so async write gives no gain there. - **Cost: less cache retained.** On a PL1 reader the async path drops pending writes it can't persist in time. After one scan C kept 54 GiB, B kept 80 GiB, A kept 136 GiB. Running the same query again was still faster with C (32.9 s vs B 52.7 s), because C refilled its misses from peer. - **Limits:** - These runs used the old default pool of 32 threads. - C relied on the reader's network burst bandwidth. - Throughput plateaus around 3 GB/s, probably reader CPU; the cause is not isolated. - Not tested: a no-regression run against master with peer off, sparse-read performance, small reads, long-running load, more than one source BE. (cherry picked from commit d2562bc69aa6fddaf2848285508b5119539f03da) <!-- Recommended: develop the change with the develop-with-evidence skill and write this description with the doris-pr-description skill, both from https://github.com/apache/doris-skills (the doris-skills submodule of this repository). --> ### Background <!-- How the feature or module this PR touches works today, in two to four plain sentences, for a reviewer who doesn't know it. Link the user doc if there is one. Leave the problem and the fix to Problem Summary. --> ### What problem does this PR solve? <!-- Issue Number: "close #N" if this PR resolves the issue, "#N" if it only relates to it, "None" if there is none. A Feature needs an issue. --> <!-- Related PR: "#N (relation)" for each PR a reviewer should know about, such as "#123 (introduced the bug)", separated by commas. Write "None" if no related PR is known. --> <!-- PR Type: Bugfix, Performance, Feature, Enhancement, Refactor, Test, Build/CI/Chore, Revert, Release/Dependency, or Other. --> Issue Number: Related PR: PR Type: Problem Summary: <!-- Two to five sentences: the problem or need and who is affected; the approach in one sentence; when the diff is larger than that suggests, what else it had to handle, or that most of it is tests; and what existing users see after an upgrade. --> ### Details <!-- For a diff of more than about 300 changed lines, start with "- **Change map:**": how many lines are production code, tests, generated files, and docs, then the code in parts, each with the problem it handles and its size. Then answer each field of your PR type on its own line, as "- **Field:** answer", in this order: Bugfix: Frequency, Root cause, Why existing tests missed it, Fix, Other paths and branches Performance: Why it was slow, Optimization, Results, Applicability and cost Feature: Scope, Design, Usage, Default behavior, Compatibility Enhancement: Before and after, Configs and defaults, Impact on existing users Refactor: Moves vs. logic changes, Behavior change, Compatibility, Performance impact, Rollback Test, adding tests: Scenarios, What existing tests miss, Fails when broken Test, fixing a test: Failure, Cause, Stability evidence Build/CI/Chore: Affected, Developer and release impact, License and third-party, Rollback Revert: Why not fix forward, Original author notified, Follow-up Release/Dependency: Versions, Upstream changes, Compatibility, Rollback Other: Why Other "None" is a valid answer when it is true. Don't restate the diff. --> ### Testing <!-- The tests, suites, or commands that ran, what each shows, and where it ran (locally or in CI). For a fix, the test that fails before it and passes after. --> ### Notes for Reviewers <!-- Optional; delete this section if there is nothing to say. Why each non-obvious edit was made, what you are unsure about, and where to start reading if Details has no Change map. --> ### Release note <!-- One paragraph on what users will notice, or None. --> ### Check List (For Author) <!-- Behavior changed: "No", or "Yes (see Details)" with a Behavior change field in Details. --> <!-- Does this need documentation: "No", or "Yes" with the apache/doris-website PR or the plan. --> <!-- Pre-submission status: "Ready"; "Partially verified: " and what is not verified; or "Not ready: " and why, for a Draft PR. --> - Behavior changed: - Does this need documentation: - Pre-submission status: ### AI Disclosure <!-- Tool: the agent and model, or None. Generated: the parts it wrote (code, tests, this description), or None. Human review: what you reviewed of the generated parts, or "Not applicable" without AI tools. You may add "- Prompts:" to summarize how you directed the agent. --> - Tool: - Generated: - Human review: -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
