Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add write stall config for read only file store #20

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading