Skip to content

Commit

Permalink
feat: add write stall config for read only file store (#20)
Browse files Browse the repository at this point in the history
Signed-off-by: MrCroxx <mrcroxx@outlook.com>
  • Loading branch information
MrCroxx committed Jun 8, 2023
1 parent 79610aa commit 23e2612
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
5 changes: 5 additions & 0 deletions foyer-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ pub struct Args {
/// read only file store: ratio of randomly dropped entries (0 ~ 1)
#[arg(long, default_value_t = 0.0)]
rofs_random_drop_ratio: f64,

/// read only file store: ratio of size to trigger write stall, every new entry to insert will be dropped (0 ~ 1)
#[arg(long, default_value_t = 0.0)]
rofs_write_stall_threshold_ratio: f64,
}

impl Args {
Expand Down Expand Up @@ -149,6 +153,7 @@ async fn main() {
trigger_reclaim_capacity_ratio: args.rofs_trigger_reclaim_capacity_ratio,
trigger_random_drop_ratio: args.rofs_trigger_random_drop_ratio,
random_drop_ratio: args.rofs_random_drop_ratio,
write_stall_threshold_ratio: args.rofs_write_stall_threshold_ratio,
};

let policy_config = TinyLfuConfig {
Expand Down
27 changes: 20 additions & 7 deletions foyer/src/store/read_only_file_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ pub struct Config {

/// ratio of randomly dropped entries
pub random_drop_ratio: f64,

/// ratio of size to trigger write stall
///
/// every new entry to insert will be dropped
pub write_stall_threshold_ratio: f64,
}

struct Frozen {
Expand Down Expand Up @@ -196,10 +201,16 @@ where

// append cache file and meta file
let (fid, sid, location) = {
// randomly drop if size exceeds the threshold
if self.size.load(Ordering::Relaxed) as f64
>= self.config.capacity as f64 * self.config.trigger_random_drop_ratio
let size_ratio = self.size.load(Ordering::Relaxed) as f64 / self.config.capacity as f64;
if self.config.write_stall_threshold_ratio > 0.0
&& size_ratio >= self.config.write_stall_threshold_ratio
{
// write stall
return Ok(());
} else if self.config.trigger_random_drop_ratio > 0.0
&& size_ratio >= self.config.trigger_random_drop_ratio
{
// random drop
let mut rng = thread_rng();
if rng.gen_range(0.0..1.0) < self.config.random_drop_ratio {
return Ok(());
Expand Down Expand Up @@ -553,8 +564,9 @@ mod tests {
capacity: 16 * 1024,
trigger_reclaim_garbage_ratio: 0.0, // disabled
trigger_reclaim_capacity_ratio: 0.75,
trigger_random_drop_ratio: 0.0, // disabled
random_drop_ratio: 0.0, // disabled
trigger_random_drop_ratio: 0.0, // disabled
random_drop_ratio: 0.0, // disabled
write_stall_threshold_ratio: 0.0, // disabled
};

let store: ReadOnlyFileStore<u64, Vec<u8>> =
Expand Down Expand Up @@ -607,8 +619,9 @@ mod tests {
capacity: 16 * 1024,
trigger_reclaim_garbage_ratio: 0.0, // disabled
trigger_reclaim_capacity_ratio: 0.75,
trigger_random_drop_ratio: 0.0, // disabled
random_drop_ratio: 0.0, // disabled
trigger_random_drop_ratio: 0.0, // disabled
random_drop_ratio: 0.0, // disabled
write_stall_threshold_ratio: 0.0, // disabled
};

let store: ReadOnlyFileStore<u64, Vec<u8>> =
Expand Down

0 comments on commit 23e2612

Please sign in to comment.