Skip to content

Commit 3e70b0f

Browse files
authored
feat: add write stall config for read only file store (#20)
Signed-off-by: MrCroxx <[email protected]>
1 parent a4d7018 commit 3e70b0f

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

foyer-bench/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ pub struct Args {
101101
/// read only file store: ratio of randomly dropped entries (0 ~ 1)
102102
#[arg(long, default_value_t = 0.0)]
103103
rofs_random_drop_ratio: f64,
104+
105+
/// read only file store: ratio of size to trigger write stall, every new entry to insert will be dropped (0 ~ 1)
106+
#[arg(long, default_value_t = 0.0)]
107+
rofs_write_stall_threshold_ratio: f64,
104108
}
105109

106110
impl Args {
@@ -149,6 +153,7 @@ async fn main() {
149153
trigger_reclaim_capacity_ratio: args.rofs_trigger_reclaim_capacity_ratio,
150154
trigger_random_drop_ratio: args.rofs_trigger_random_drop_ratio,
151155
random_drop_ratio: args.rofs_random_drop_ratio,
156+
write_stall_threshold_ratio: args.rofs_write_stall_threshold_ratio,
152157
};
153158

154159
let policy_config = TinyLfuConfig {

foyer/src/store/read_only_file_store.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ pub struct Config {
6262

6363
/// ratio of randomly dropped entries
6464
pub random_drop_ratio: f64,
65+
66+
/// ratio of size to trigger write stall
67+
///
68+
/// every new entry to insert will be dropped
69+
pub write_stall_threshold_ratio: f64,
6570
}
6671

6772
struct Frozen {
@@ -196,10 +201,16 @@ where
196201

197202
// append cache file and meta file
198203
let (fid, sid, location) = {
199-
// randomly drop if size exceeds the threshold
200-
if self.size.load(Ordering::Relaxed) as f64
201-
>= self.config.capacity as f64 * self.config.trigger_random_drop_ratio
204+
let size_ratio = self.size.load(Ordering::Relaxed) as f64 / self.config.capacity as f64;
205+
if self.config.write_stall_threshold_ratio > 0.0
206+
&& size_ratio >= self.config.write_stall_threshold_ratio
207+
{
208+
// write stall
209+
return Ok(());
210+
} else if self.config.trigger_random_drop_ratio > 0.0
211+
&& size_ratio >= self.config.trigger_random_drop_ratio
202212
{
213+
// random drop
203214
let mut rng = thread_rng();
204215
if rng.gen_range(0.0..1.0) < self.config.random_drop_ratio {
205216
return Ok(());
@@ -553,8 +564,9 @@ mod tests {
553564
capacity: 16 * 1024,
554565
trigger_reclaim_garbage_ratio: 0.0, // disabled
555566
trigger_reclaim_capacity_ratio: 0.75,
556-
trigger_random_drop_ratio: 0.0, // disabled
557-
random_drop_ratio: 0.0, // disabled
567+
trigger_random_drop_ratio: 0.0, // disabled
568+
random_drop_ratio: 0.0, // disabled
569+
write_stall_threshold_ratio: 0.0, // disabled
558570
};
559571

560572
let store: ReadOnlyFileStore<u64, Vec<u8>> =
@@ -607,8 +619,9 @@ mod tests {
607619
capacity: 16 * 1024,
608620
trigger_reclaim_garbage_ratio: 0.0, // disabled
609621
trigger_reclaim_capacity_ratio: 0.75,
610-
trigger_random_drop_ratio: 0.0, // disabled
611-
random_drop_ratio: 0.0, // disabled
622+
trigger_random_drop_ratio: 0.0, // disabled
623+
random_drop_ratio: 0.0, // disabled
624+
write_stall_threshold_ratio: 0.0, // disabled
612625
};
613626

614627
let store: ReadOnlyFileStore<u64, Vec<u8>> =

0 commit comments

Comments
 (0)