Commit 9fd4c4c
CNDB-13639: Adds optional prefetching for known sequential reads (#1692)
This introduces a `PrefetchingRebufferer` that, when enabled, prefetches
(read from the underlying reader) a configurable number of chunks in
advance (so only work on top of rebufferer factories that work with
chunks, i.e. not uncompressed mmap).
Prefetching must first be enabled globally by setting
`-Dcassandra.read_prefetching_size_kb` to the desired value. With that,
and assuming the disk access mode allows it (meaning, it's not
uncompressed mmap), then prefetching will be applied to reads that are
"clearly" sequential. Mostly, as of this patch, this means the sstable
"scanners" and `SortedStringTableCursor`, so compaction, SAI index
building and tools that read sstable fully (scrub, verifier) will
benefit from it.
Since rebufferers are synchronous, prefetching is done through a fixed
thread pool. The number of thread of that pool can be set with
`-Dcassandra.read_prefetching_threads` (but default to the number of
"processors").
The `-Dcassandra.read_prefetching_window` can also be set to define how
often prefetching is re-triggered. By default, when there is less than
half of the value of `-Dcassandra.read_prefetching_size_kb` prefetched,
then prefetching is triggered.
See riptano/cndb#13639 for additional
motivation.
I'll note that this patch is adapted from the similar DSE behavior.
However, there is a fair bit of modification since the DSE version was
relying on the asynchronous nature of rebufferers there (it also had a
few behavior I didn't fully understood and I didn't dig when it felt a
bit specific to DSE).
One point worth mentioning was that the DSE version was relying on the
ability of the underlying channel to create batches when multiple chunks
are prefetched. This is something that could have advantages and we
could try to add back over time, but it's a lot harder to see how to do
that in the non-async world of C*. Typically, in DSE, since all the
prefetches were initiated on the current thread (without blocking it),
building the "batch" was relatively easy, but it doesn't translate in
this patch. Not to mention that currently the underlying channels have
no batching options and those would have to be added (in a way that
trickled down to the channel implementation within CNDB). Anyway, as of
this patch, chunks are prefetched in parallel but with no batching
optimization. Which does mean the `window' parameter is probably not as
useful as for DSE, but I've kept it nonetheless as it's not exactly
adding complexity.
In the context of compaction in CNDB though, I think this mean that it
would kind of be ideal if we could use a relatively large "chunk size"
for the readers: we read the full file anyway, so there is no waste
there to use a large-ish chunk size, and it would kind of provide
batching for prefetching "for free" (in the sense that if we want to
prefetch, say, 128kb in advance, then we only need 2 chunks with a 64kb
chunk, but need a lot more with a 4kb chunk size).
---------
Co-authored-by: Branimir Lambov <[email protected]>1 parent 1d762c6 commit 9fd4c4c
File tree
29 files changed
+1077
-47
lines changed- src/java/org/apache/cassandra
- cache
- config
- db/compaction
- index
- sai
- sasi
- io
- sstable
- compaction
- format
- big
- trieindex
- util
- test
- distributed/org/apache/cassandra/io/sstable/format
- unit/org/apache/cassandra
- cache
- cql3/validation/miscellaneous
- io
- sstable
- util
29 files changed
+1077
-47
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
| 56 | + | |
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
| |||
688 | 690 | | |
689 | 691 | | |
690 | 692 | | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
691 | 699 | | |
692 | 700 | | |
693 | 701 | | |
| |||
Lines changed: 24 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
601 | 602 | | |
602 | 603 | | |
603 | 604 | | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
604 | 628 | | |
605 | 629 | | |
606 | 630 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
352 | 353 | | |
353 | 354 | | |
354 | 355 | | |
355 | | - | |
| 356 | + | |
356 | 357 | | |
357 | 358 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
| |||
157 | 158 | | |
158 | 159 | | |
159 | 160 | | |
160 | | - | |
161 | | - | |
| 161 | + | |
| 162 | + | |
162 | 163 | | |
163 | 164 | | |
164 | 165 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
| |||
139 | 140 | | |
140 | 141 | | |
141 | 142 | | |
142 | | - | |
143 | | - | |
| 143 | + | |
| 144 | + | |
144 | 145 | | |
145 | 146 | | |
146 | 147 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| |||
155 | 156 | | |
156 | 157 | | |
157 | 158 | | |
158 | | - | |
| 159 | + | |
159 | 160 | | |
160 | 161 | | |
161 | 162 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
83 | | - | |
| 84 | + | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| |||
Lines changed: 4 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| |||
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
86 | | - | |
| 87 | + | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
91 | | - | |
| 92 | + | |
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
96 | | - | |
| 97 | + | |
97 | 98 | | |
98 | 99 | | |
99 | 100 | | |
| |||
Lines changed: 10 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
128 | 129 | | |
129 | 130 | | |
130 | 131 | | |
| |||
1966 | 1967 | | |
1967 | 1968 | | |
1968 | 1969 | | |
1969 | | - | |
| 1970 | + | |
| 1971 | + | |
| 1972 | + | |
1970 | 1973 | | |
1971 | 1974 | | |
1972 | 1975 | | |
| |||
2321 | 2324 | | |
2322 | 2325 | | |
2323 | 2326 | | |
2324 | | - | |
| 2327 | + | |
2325 | 2328 | | |
2326 | 2329 | | |
2327 | | - | |
| 2330 | + | |
2328 | 2331 | | |
2329 | 2332 | | |
2330 | | - | |
| 2333 | + | |
2331 | 2334 | | |
2332 | | - | |
| 2335 | + | |
2333 | 2336 | | |
2334 | 2337 | | |
2335 | | - | |
| 2338 | + | |
2336 | 2339 | | |
2337 | 2340 | | |
2338 | | - | |
| 2341 | + | |
2339 | 2342 | | |
2340 | 2343 | | |
2341 | 2344 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
74 | | - | |
| 75 | + | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
| |||
0 commit comments