mrhhsg opened a new pull request, #71024:
URL: https://github.com/apache/doris/pull/71024
### Background
Page read-ahead keeps reader-private statistics and periodically drains them
into the `SegmentIterator` runtime profile shared by a scan local state.
Multiple scanners can report to that profile during scheduling and final
collection.
### What problem does this PR solve?
Issue Number: None
Related PR: #67292 (introduced page read-ahead), #70836 (adjacent FileCache
counter caching)
PR Type: Performance
Problem Summary:
Each report repeats 59 counter registrations/lookups, even for existing
counters or zero deltas. Cache the destination handles lazily once per local
state and reuse them for realtime and final reports. Most production changes
move the existing metric mapping into one constant table; the remainder adds
shared ownership and focused tests. Query results, counter names, units,
hierarchy, levels and configuration defaults remain unchanged.
### Details
- **Change map:** Production +257/-71 lines; tests +178/-7; generated files
and docs unchanged.
1. Separate binding from draining: 295 changed lines in
`ReadAheadProfileReporter` and its mapping, mostly mechanical relocation of 54
existing metrics.
2. Share lazy bindings across scanners: 33 changed lines for local-state
ownership, out-of-line construction/destruction and both reporting entry points.
- **Why it was slow:** `RuntimeProfile::add_counter` acquires the shared
profile's counter-map mutex before checking whether a counter exists. Every
report repeats this for one root, four groups and 54 metrics.
- **Optimization:** Use `std::call_once` to publish one reporter per used
local state. Its fixed bindings retain destination handles and source member
pointers, not reader objects. Each update preserves the atomic
snapshot/add/subtract transfer; point queries retain the one-shot API.
- **Results:** Local x86_64 ASAN instrumentation with two scanners sharing
one local state measured the following registration-call counts, not query
performance. The measured reporter predates only a mechanical
designated-initializer cleanup; the final mapping and runtime tests were
revalidated.
| Reporting workload | Before | After |
|---|---:|---:|
| 1,000 realtime reports, including zero deltas | 59,000 | 59 |
| Two subsequent final reports | 118 | 0 |
| First report in an independent final-only state | 59 | 59 |
No Release throughput, CPU or lock-wait improvement has been measured.
- **Applicability and cost:** Applies to cloud query scans that create
read-ahead statistics with `enable_query_read_ahead` and
`enable_async_file_cache_write` enabled; both default to `false`. Each active
local state allocates 54 bindings (864 bytes on x86_64, excluding allocator
overhead); inactive states add only a once flag and pointer. Active reports
still transfer 54 counters and check the completed once flag. No benefit is
claimed for one-shot reporting.
### Testing
- Local ASAN BE UT: 91 tests passed across `ReadAheadMetricsTest`,
`ScannerContextTest`, `FileRangeReadSchedulerTest`, `ReadAheadRangeBufferTest`
and `SegmentIteratorReadAheadTest`, using `./run-be-ut.sh --run` with those
suite filters.
- The registration-budget comparison failed its budget assertions on the
baseline and passed with cached bindings. Temporary instrumentation was removed
before final validation.
- Existing `query_profile/scanner_profile` regression passed locally: 1
suite, 0 failures, fatal errors or skipped scripts. This is shared-nothing
SQL/Profile smoke coverage, not cloud read-ahead E2E coverage.
- Cloud Release A/B and cloud EOS/LIMIT/cancellation E2E validation have not
been run.
### Notes for Reviewers
Bindings are immutable after publication. Each statistics object retains one
draining thread; independent statistics objects can aggregate concurrently. The
reporter is destroyed before its owning profile, and asynchronous I/O retains
no destination handles.
### Release note
None
### Check List (For Author)
- Behavior changed: No
- Does this need documentation: No
- Pre-submission status: Partially verified: cloud Release performance and
cloud EOS/LIMIT/cancellation E2E validation have not been run.
### AI Disclosure
- Tool: Codex; implementation model not recorded.
- Generated: Implementation, unit tests and this description.
- Human review: Not stated.
--
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]