Skip to content

Commit d4a37d1

Browse files
authored
chore: add default configuration for throttler (#89)
* add default throttler * refine
1 parent 6558a8a commit d4a37d1

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

crates/core/src/engine.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ use exn::Result;
2020
use exn::bail;
2121
use foyer::BlockEngineBuilder;
2222
use foyer::DeviceBuilder;
23-
use foyer::FifoConfig;
2423
use foyer::FsDeviceBuilder;
2524
use foyer::HybridCache;
2625
use foyer::HybridCacheBuilder;
2726
use foyer::HybridCachePolicy;
2827
use foyer::IoEngineBuilder;
28+
use foyer::IopsCounter;
29+
use foyer::LfuConfig;
2930
use foyer::PsyncIoEngineBuilder;
3031
use foyer::RecoverMode;
3132
use foyer::RuntimeOptions;
@@ -69,6 +70,23 @@ impl FoyerEngine {
6970
let mut db = FsDeviceBuilder::new(data_dir).with_capacity(disk_capacity as usize);
7071
if let Some(throttle) = disk_throttle {
7172
db = db.with_throttle(throttle.into());
73+
} else {
74+
const DEFAULT_THROUGHPUT_PER_CORE: usize = 187_500_000; // ~1.5Gbps
75+
const IOPS_PER_CORE: usize = 10_000; // 10k IOPS
76+
let throughput = DEFAULT_THROUGHPUT_PER_CORE * num_cpus().get();
77+
let write_throughput_quota = throughput / 4; // 25% of throughput for writes
78+
let read_throughput_quota = throughput - write_throughput_quota; // Remaining for reads
79+
let iops = IOPS_PER_CORE * num_cpus().get();
80+
let write_iops_quota = iops / 4; // 25% of IOPS for writes
81+
let read_iops_quota = iops - write_iops_quota; // Remaining for reads
82+
let throttle = foyer::Throttle {
83+
write_iops: Some(write_iops_quota.try_into().unwrap()),
84+
read_iops: Some(read_iops_quota.try_into().unwrap()),
85+
write_throughput: Some(write_throughput_quota.try_into().unwrap()),
86+
read_throughput: Some(read_throughput_quota.try_into().unwrap()),
87+
iops_counter: IopsCounter::PerIo,
88+
};
89+
db = db.with_throttle(throttle);
7290
}
7391
let dev = db
7492
.build()
@@ -90,7 +108,7 @@ impl FoyerEngine {
90108
key_size + value_size
91109
})
92110
.with_shards(parallelism)
93-
.with_eviction_config(FifoConfig::default())
111+
.with_eviction_config(LfuConfig::default())
94112
.storage()
95113
.with_engine_config(
96114
BlockEngineBuilder::new(dev)

0 commit comments

Comments
 (0)