airborne12 opened a new pull request, #69882:
URL: https://github.com/apache/doris/pull/69882
### What problem does this PR solve?
Issue Number: None
Related PR: #69648
Problem Summary: #69648 reads a SNII batch on the calling thread when the
index file is local, the
batch has at most `snii_inline_read_max_segments` (4) physical segments and
256 KiB, and the
moving average of recent reads is under 20 us, i.e. they hit the page cache.
A phrase prefix reads
the postings of every term its prefix expands to, in batches of 5 to 16
segments that stay well
under 256 KiB, so those still went segment by segment through the shared
buffered-reader prefetch
pool: on a hot 99M-row table, about a fifth of the SNII time of such a query
was spent on the
pool's lock and latch (`ThreadPool::do_submit`, `CountDownLatch::wait` in
`read_batch`).
The default of `snii_inline_read_max_segments` becomes 16, which covers
those batches, and two
changes keep larger inline batches safe when the data is not in the page
cache:
- A batch read inline hands the segments it has left to the pool as soon as
one of its reads is
slow. When the average is low but this batch's data is not cached, the
batch pays one read on
the calling thread and overlaps the rest. A single segment left is still
read inline.
- A read counts by how much longer it took than copying its bytes out of the
page cache (at 4
bytes/ns, the low end for one thread), for both the average and the slow
test. A page-cache hit
of 64-256 KiB spends tens of microseconds on the copy alone, which pushed
the average over 20 us
and sent about 5% of a phrase query's small batches to the pool.
On the 99M-row table, the phrase prefix's batches of 5-16 segments are now
all read inline when
hot, and the small batches of a phrase query that still went to the pool
dropped by 77%. In a cold
run (BE restarted, index files evicted from the page cache), the average was
at least 40 us
whenever such a batch was decided, so they all went to the pool, as before.
| Query (99M rows) | Hot, new/previous rule | Cold, new/previous rule |
|---|---|---|
| phrase prefix 'retry budget dep' | 0.79 / 0.85 / 0.96 (three runs) | 0.96 |
| other phrase queries | 0.87-0.95 | 1.01 (A6) |
| the other 19 queries | 0.98-1.03 | |
Hot: both rules interleaved in one BE process. Cold: BE restarted and the
index files evicted
before every run, configuration order alternated, 5 runs each.
### Release note
Speed up SNII phrase-prefix queries on local, cached index files.
### Check List (For Author)
- Test: Unit Test (`DorisSniiFileReaderInlineReadTest`: a 16-segment batch
runs on the calling
thread and a 17-segment one fans out; a slow read hands the rest to the
pool, one inline round
plus one wave; one segment left stays inline; the first slow batch now
reads one segment inline;
with the early hand-off disabled, two of them fail; all 1506 *Snii* tests
pass under ASAN).
Manual test: the hot and cold A/B above.
- Behavior changed: No (only the default of `snii_inline_read_max_segments`,
from 4 to 16)
- Does this need documentation: No
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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]