Skip to content
Draft
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ use std::sync::Arc;
use anyhow::Result;
use chrono::Datelike;
use foyer::{
CacheContext, DirectFsDeviceOptionsBuilder, FifoPicker, HybridCache, HybridCacheBuilder, LruConfig,
CacheContext, DirectFsDeviceOptionsBuilder, HybridCache, HybridCacheBuilder, LfuConfig, LruConfig, OrderPicker,
RateLimitPicker, RecoverMode, RuntimeConfigBuilder, TombstoneLogConfigBuilder,
};
use tempfile::tempdir;
Expand Down Expand Up @@ -118,7 +118,7 @@ async fn main() -> Result<()> {
.with_flushers(2)
.with_reclaimers(2)
.with_clean_region_threshold(4)
.with_eviction_pickers(vec![Box::<FifoPicker>::default()])
.with_eviction_pickers(vec![Box::new(OrderPicker::new(LfuConfig::default()))])
.with_admission_picker(Arc::new(RateLimitPicker::new(100 * 1024 * 1024)))
.with_reinsertion_picker(Arc::new(RateLimitPicker::new(10 * 1024 * 1024)))
.with_compression(foyer::Compression::Lz4)
Expand Down
4 changes: 2 additions & 2 deletions examples/hybrid_full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::sync::Arc;
use anyhow::Result;
use chrono::Datelike;
use foyer::{
CacheContext, DirectFsDeviceOptionsBuilder, FifoPicker, HybridCache, HybridCacheBuilder, LruConfig,
CacheContext, DirectFsDeviceOptionsBuilder, HybridCache, HybridCacheBuilder, LfuConfig, LruConfig, OrderPicker,
RateLimitPicker, RecoverMode, RuntimeConfigBuilder, TombstoneLogConfigBuilder,
};
use tempfile::tempdir;
Expand Down Expand Up @@ -49,7 +49,7 @@ async fn main() -> Result<()> {
.with_flushers(2)
.with_reclaimers(2)
.with_clean_region_threshold(4)
.with_eviction_pickers(vec![Box::<FifoPicker>::default()])
.with_eviction_pickers(vec![Box::new(OrderPicker::new(LfuConfig::default()))])
.with_admission_picker(Arc::new(RateLimitPicker::new(100 * 1024 * 1024)))
.with_reinsertion_picker(Arc::new(RateLimitPicker::new(10 * 1024 * 1024)))
.with_compression(foyer::Compression::Lz4)
Expand Down
38 changes: 33 additions & 5 deletions foyer-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

use bytesize::MIB;
use foyer::{
DirectFsDeviceOptionsBuilder, FifoPicker, HybridCache, HybridCacheBuilder, LfuConfig, RateLimitPicker,
RuntimeConfigBuilder,
DirectFsDeviceOptionsBuilder, EvictionConfig, FifoConfig, HybridCache, HybridCacheBuilder, LfuConfig, LruConfig,
OrderPicker, RateLimitPicker, RuntimeConfigBuilder, S3FifoConfig,
};
use metrics_exporter_prometheus::PrometheusBuilder;

Expand All @@ -36,7 +36,7 @@ use std::{
};

use analyze::{analyze, monitor, Metrics};
use clap::Parser;
use clap::{Parser, ValueEnum};

use futures::future::join_all;
use itertools::Itertools;
Expand All @@ -62,6 +62,14 @@ pub struct Args {
#[arg(long, default_value_t = 1024)]
mem: usize,

/// In-memory cache eviction algorithm.
#[arg(long, value_enum, default_value_t = Eviction::Lfu)]
mem_eviction: Eviction,

/// Disk cache eviction algorithm.
#[arg(long, value_enum, default_value_t = Eviction::Lfu)]
disk_eviction: Eviction,

/// Disk cache capacity. (MiB)
#[arg(long, default_value_t = 1024)]
disk: usize,
Expand Down Expand Up @@ -175,6 +183,26 @@ pub struct Args {
flush: bool,
}

#[derive(Debug, Clone, ValueEnum)]
#[clap(rename_all = "lower")]
enum Eviction {
Fifo,
S3Fifo,
Lru,
Lfu,
}

impl From<Eviction> for EvictionConfig {
fn from(value: Eviction) -> Self {
match value {
Eviction::Fifo => Self::Fifo(FifoConfig::default()),
Eviction::S3Fifo => Self::S3Fifo(S3FifoConfig::default()),
Eviction::Lru => Self::Lru(LruConfig::default()),
Eviction::Lfu => Self::Lfu(LfuConfig::default()),
}
}
}

#[derive(Debug)]
enum TimeSeriesDistribution {
None,
Expand Down Expand Up @@ -372,7 +400,7 @@ async fn main() {
let mut builder = HybridCacheBuilder::new()
.memory(args.mem * MIB as usize)
.with_shards(args.shards)
.with_eviction_config(LfuConfig::default())
.with_eviction_config(args.mem_eviction.clone())
.with_weighter(|_: &u64, value: &Value| u64::BITS as usize / 8 + value.len())
.storage()
.with_device_config(
Expand All @@ -386,7 +414,7 @@ async fn main() {
.with_recover_concurrency(args.recover_concurrency)
.with_flushers(args.flushers)
.with_reclaimers(args.reclaimers)
.with_eviction_pickers(vec![Box::<FifoPicker>::default()])
.with_eviction_pickers(vec![Box::new(OrderPicker::new(args.disk_eviction.clone()))])
.with_compression(
args.compression
.as_str()
Expand Down
12 changes: 7 additions & 5 deletions foyer-memory/src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct CacheSharedState<T> {

// TODO(MrCroxx): use `expect` after `lint_reasons` is stable.
#[allow(clippy::type_complexity)]
struct CacheShard<K, V, E, I, S>
struct GenericCacheShard<K, V, E, I, S>
where
K: Key,
V: Value,
Expand All @@ -76,7 +76,7 @@ where
state: Arc<CacheSharedState<E::Handle>>,
}

impl<K, V, E, I, S> CacheShard<K, V, E, I, S>
impl<K, V, E, I, S> GenericCacheShard<K, V, E, I, S>
where
K: Key,
V: Value,
Expand Down Expand Up @@ -368,7 +368,7 @@ where
}
}

impl<K, V, E, I, S> Drop for CacheShard<K, V, E, I, S>
impl<K, V, E, I, S> Drop for GenericCacheShard<K, V, E, I, S>
where
K: Key,
V: Value,
Expand Down Expand Up @@ -465,7 +465,7 @@ where
I: Indexer<Key = K, Handle = E::Handle>,
S: BuildHasher + Send + Sync + 'static,
{
shards: Vec<Mutex<CacheShard<K, V, E, I, S>>>,
shards: Vec<Mutex<GenericCacheShard<K, V, E, I, S>>>,

capacity: usize,
usages: Vec<Arc<AtomicUsize>>,
Expand Down Expand Up @@ -496,7 +496,9 @@ where

let shards = usages
.iter()
.map(|usage| CacheShard::new(shard_capacity, &config.eviction_config, usage.clone(), context.clone()))
.map(|usage| {
GenericCacheShard::new(shard_capacity, &config.eviction_config, usage.clone(), context.clone())
})
.map(Mutex::new)
.collect_vec();

Expand Down
2 changes: 2 additions & 0 deletions foyer-memory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,6 @@ mod indexer;
mod metrics;
mod prelude;

mod order;

pub use prelude::*;
Loading