Skip to content

Commit 5c0e1a9

Browse files
authored
feat(foyer): cherry-pick disk cache optimization related PRs (#21844)
1 parent 362ac2b commit 5c0e1a9

File tree

30 files changed

+274
-214
lines changed

30 files changed

+274
-214
lines changed

Cargo.lock

Lines changed: 12 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ license = "Apache-2.0"
8181
repository = "https://github.com/risingwavelabs/risingwave"
8282

8383
[workspace.dependencies]
84-
foyer = { version = "0.15.4", features = ["tracing", "nightly"] }
85-
mixtrics ={ version = "0.0.4", features = ["prometheus"] }
84+
foyer = { version = "0.17.2", features = ["serde", "tracing", "nightly"] }
85+
mixtrics = { version = "0.1", features = ["prometheus_0_13"] }
8686
apache-avro = { git = "https://github.com/risingwavelabs/avro", rev = "25113ba88234a9ae23296e981d8302c290fdaa4b", features = [
8787
"snappy",
8888
"zstandard",

src/batch/executors/src/executor/insert.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ mod tests {
265265
use std::ops::Bound;
266266

267267
use assert_matches::assert_matches;
268-
use foyer::CacheHint;
268+
use foyer::Hint;
269269
use futures::StreamExt;
270270
use risingwave_common::array::{Array, ArrayImpl, I32Array, StructArray};
271271
use risingwave_common::catalog::{
@@ -396,7 +396,7 @@ mod tests {
396396
epoch,
397397
None,
398398
ReadOptions {
399-
cache_policy: CachePolicy::Fill(CacheHint::Normal),
399+
cache_policy: CachePolicy::Fill(Hint::Normal),
400400
..Default::default()
401401
},
402402
)

src/common/src/config.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ use std::num::NonZeroUsize;
2424
use anyhow::Context;
2525
use clap::ValueEnum;
2626
use educe::Educe;
27-
use foyer::{Compression, LfuConfig, LruConfig, RecoverMode, RuntimeOptions, S3FifoConfig};
27+
use foyer::{
28+
Compression, LfuConfig, LruConfig, RecoverMode, RuntimeOptions, S3FifoConfig, Throttle,
29+
};
2830
use risingwave_common_proc_macro::ConfigDoc;
2931
pub use risingwave_common_proc_macro::OverrideConfig;
3032
use risingwave_pb::meta::SystemParams;
@@ -994,6 +996,7 @@ pub struct FileCacheConfig {
994996
#[serde(default = "default::file_cache::recover_concurrency")]
995997
pub recover_concurrency: usize,
996998

999+
/// Deprecated soon. Please use `throttle` to do I/O throttling instead.
9971000
#[serde(default = "default::file_cache::insert_rate_limit_mb")]
9981001
pub insert_rate_limit_mb: usize,
9991002

@@ -1006,6 +1009,12 @@ pub struct FileCacheConfig {
10061009
#[serde(default = "default::file_cache::flush_buffer_threshold_mb")]
10071010
pub flush_buffer_threshold_mb: Option<usize>,
10081011

1012+
#[serde(default = "default::file_cache::throttle")]
1013+
pub throttle: Throttle,
1014+
1015+
#[serde(default = "default::file_cache::fifo_probation_ratio")]
1016+
pub fifo_probation_ratio: f64,
1017+
10091018
/// Recover mode.
10101019
///
10111020
/// Options:
@@ -1912,7 +1921,9 @@ pub mod default {
19121921
}
19131922

19141923
pub mod file_cache {
1915-
use foyer::{Compression, RecoverMode, RuntimeOptions, TokioRuntimeOptions};
1924+
use std::num::NonZeroUsize;
1925+
1926+
use foyer::{Compression, RecoverMode, RuntimeOptions, Throttle, TokioRuntimeOptions};
19161927

19171928
pub fn dir() -> String {
19181929
"".to_owned()
@@ -1954,13 +1965,28 @@ pub mod default {
19541965
None
19551966
}
19561967

1968+
pub fn fifo_probation_ratio() -> f64 {
1969+
0.1
1970+
}
1971+
19571972
pub fn recover_mode() -> RecoverMode {
19581973
RecoverMode::None
19591974
}
19601975

19611976
pub fn runtime_config() -> RuntimeOptions {
19621977
RuntimeOptions::Unified(TokioRuntimeOptions::default())
19631978
}
1979+
1980+
pub fn throttle() -> Throttle {
1981+
Throttle::new()
1982+
.with_iops_counter(foyer::IopsCounter::PerIoSize(
1983+
NonZeroUsize::new(128 * 1024).unwrap(),
1984+
))
1985+
.with_read_iops(100000)
1986+
.with_write_iops(100000)
1987+
.with_write_throughput(1024 * 1024 * 1024)
1988+
.with_read_throughput(1024 * 1024 * 1024)
1989+
}
19641990
}
19651991

19661992
pub mod cache_refill {

src/config/docs.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,17 @@ This page is automatically generated by `./risedev generate-example-config`
195195
| capacity_mb | | 1024 |
196196
| compression | | "None" |
197197
| dir | | "" |
198+
| fifo_probation_ratio | | 0.1 |
198199
| file_capacity_mb | | 64 |
199200
| flush_buffer_threshold_mb | | |
200201
| flushers | | 4 |
201202
| indexer_shards | | 64 |
202-
| insert_rate_limit_mb | | 0 |
203+
| insert_rate_limit_mb | Deprecated soon. Please use `throttle` to do I/O throttling instead. | 0 |
203204
| reclaimers | | 4 |
204205
| recover_concurrency | | 8 |
205206
| recover_mode | Recover mode. Options: - "None": Do not recover disk cache. - "Quiet": Recover disk cache and skip errors. - "Strict": Recover disk cache and panic on errors. More details, see [`RecoverMode::None`], [`RecoverMode::Quiet`] and [`RecoverMode::Strict`], | "None" |
206207
| runtime_config | | |
208+
| throttle | | |
207209

208210
## storage.meta_file_cache
209211

@@ -212,15 +214,17 @@ This page is automatically generated by `./risedev generate-example-config`
212214
| capacity_mb | | 1024 |
213215
| compression | | "None" |
214216
| dir | | "" |
217+
| fifo_probation_ratio | | 0.1 |
215218
| file_capacity_mb | | 64 |
216219
| flush_buffer_threshold_mb | | |
217220
| flushers | | 4 |
218221
| indexer_shards | | 64 |
219-
| insert_rate_limit_mb | | 0 |
222+
| insert_rate_limit_mb | Deprecated soon. Please use `throttle` to do I/O throttling instead. | 0 |
220223
| reclaimers | | 4 |
221224
| recover_concurrency | | 8 |
222225
| recover_mode | Recover mode. Options: - "None": Do not recover disk cache. - "Quiet": Recover disk cache and skip errors. - "Strict": Recover disk cache and panic on errors. More details, see [`RecoverMode::None`], [`RecoverMode::Quiet`] and [`RecoverMode::Strict`], | "None" |
223226
| runtime_config | | |
227+
| throttle | | |
224228

225229
## streaming
226230

src/config/example.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,18 @@ recover_concurrency = 8
226226
insert_rate_limit_mb = 0
227227
indexer_shards = 64
228228
compression = "None"
229+
fifo_probation_ratio = 0.1
229230
recover_mode = "None"
230231

232+
[storage.data_file_cache.throttle]
233+
write_iops = 100000
234+
read_iops = 100000
235+
write_throughput = 1073741824
236+
read_throughput = 1073741824
237+
238+
[storage.data_file_cache.throttle.iops_counter]
239+
PerIoSize = 131072
240+
231241
[storage.data_file_cache.runtime_config.Unified]
232242
worker_threads = 0
233243
max_blocking_threads = 0
@@ -242,8 +252,18 @@ recover_concurrency = 8
242252
insert_rate_limit_mb = 0
243253
indexer_shards = 64
244254
compression = "None"
255+
fifo_probation_ratio = 0.1
245256
recover_mode = "None"
246257

258+
[storage.meta_file_cache.throttle]
259+
write_iops = 100000
260+
read_iops = 100000
261+
write_throughput = 1073741824
262+
read_throughput = 1073741824
263+
264+
[storage.meta_file_cache.throttle.iops_counter]
265+
PerIoSize = 131072
266+
247267
[storage.meta_file_cache.runtime_config.Unified]
248268
worker_threads = 0
249269
max_blocking_threads = 0

src/storage/benches/bench_compactor.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::sync::Arc;
1818

1919
use criterion::async_executor::FuturesExecutor;
2020
use criterion::{criterion_group, criterion_main, Criterion};
21-
use foyer::{CacheHint, Engine, HybridCacheBuilder};
21+
use foyer::{Engine, Hint, HybridCacheBuilder};
2222
use risingwave_common::catalog::{ColumnDesc, ColumnId, TableId};
2323
use risingwave_common::config::{MetricLevel, ObjectStoreConfig};
2424
use risingwave_common::hash::VirtualNode;
@@ -95,7 +95,7 @@ pub fn default_writer_opts() -> SstableWriterOptions {
9595
SstableWriterOptions {
9696
capacity_hint: None,
9797
tracker: None,
98-
policy: CachePolicy::Fill(CacheHint::Normal),
98+
policy: CachePolicy::Fill(Hint::Normal),
9999
}
100100
}
101101

@@ -132,7 +132,7 @@ async fn build_table(
132132
SstableWriterOptions {
133133
capacity_hint: None,
134134
tracker: None,
135-
policy: CachePolicy::Fill(CacheHint::Normal),
135+
policy: CachePolicy::Fill(Hint::Normal),
136136
},
137137
);
138138
let table_id_to_vnode = HashMap::from_iter(vec![(0, VirtualNode::COUNT_FOR_TEST)]);
@@ -181,7 +181,7 @@ async fn build_table_2(
181181
SstableWriterOptions {
182182
capacity_hint: None,
183183
tracker: None,
184-
policy: CachePolicy::Fill(CacheHint::Normal),
184+
policy: CachePolicy::Fill(Hint::Normal),
185185
},
186186
);
187187

@@ -345,7 +345,7 @@ fn bench_merge_iterator_compactor(c: &mut Criterion) {
345345
});
346346
let level2 = vec![info1, info2];
347347
let read_options = Arc::new(SstableIteratorReadOptions {
348-
cache_policy: CachePolicy::Fill(CacheHint::Normal),
348+
cache_policy: CachePolicy::Fill(Hint::Normal),
349349
prefetch_for_large_query: false,
350350
must_iterated_end_user_key: None,
351351
max_preload_retry_times: 0,

src/storage/hummock_test/benches/bench_hummock_iter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::sync::Arc;
1717

1818
use bytes::Bytes;
1919
use criterion::{criterion_group, criterion_main, Criterion};
20-
use foyer::CacheHint;
20+
use foyer::Hint;
2121
use futures::pin_mut;
2222
use risingwave_common::util::epoch::test_epoch;
2323
use risingwave_hummock_sdk::key::TableKey;
@@ -109,7 +109,7 @@ fn criterion_benchmark(c: &mut Criterion) {
109109
epoch,
110110
ReadOptions {
111111
prefetch_options: PrefetchOptions::default(),
112-
cache_policy: CachePolicy::Fill(CacheHint::Normal),
112+
cache_policy: CachePolicy::Fill(Hint::Normal),
113113
..Default::default()
114114
},
115115
))

src/storage/hummock_test/src/compactor_tests.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub(crate) mod tests {
1919
use std::sync::Arc;
2020

2121
use bytes::{BufMut, Bytes, BytesMut};
22-
use foyer::CacheHint;
22+
use foyer::Hint;
2323
use itertools::Itertools;
2424
use rand::{Rng, RngCore, SeedableRng};
2525
use risingwave_common::bitmap::BitmapBuilder;
@@ -338,7 +338,7 @@ pub(crate) mod tests {
338338
TableKey(key.clone()),
339339
get_epoch,
340340
ReadOptions {
341-
cache_policy: CachePolicy::Fill(CacheHint::Normal),
341+
cache_policy: CachePolicy::Fill(Hint::Normal),
342342
..Default::default()
343343
},
344344
)
@@ -668,7 +668,7 @@ pub(crate) mod tests {
668668
ReadOptions {
669669
table_id: TableId::from(existing_table_id),
670670
prefetch_options: PrefetchOptions::default(),
671-
cache_policy: CachePolicy::Fill(CacheHint::Normal),
671+
cache_policy: CachePolicy::Fill(Hint::Normal),
672672
..Default::default()
673673
},
674674
)
@@ -874,7 +874,7 @@ pub(crate) mod tests {
874874
ReadOptions {
875875
table_id: TableId::from(existing_table_id),
876876
prefetch_options: PrefetchOptions::default(),
877-
cache_policy: CachePolicy::Fill(CacheHint::Normal),
877+
cache_policy: CachePolicy::Fill(Hint::Normal),
878878
..Default::default()
879879
},
880880
)
@@ -1088,7 +1088,7 @@ pub(crate) mod tests {
10881088
prefix_hint: Some(Bytes::from(bloom_filter_key)),
10891089
table_id: TableId::from(existing_table_id),
10901090
prefetch_options: PrefetchOptions::default(),
1091-
cache_policy: CachePolicy::Fill(CacheHint::Normal),
1091+
cache_policy: CachePolicy::Fill(Hint::Normal),
10921092
..Default::default()
10931093
},
10941094
)

0 commit comments

Comments
 (0)