al8n / caches-rs

This is a Rust implementation for popular caches (support no_std).
104 stars 14 forks source link

How do you choose a sample size for the cache ? #6

Open abdulmi opened 1 year ago

abdulmi commented 1 year ago

Is there a strategy for choosing the sample size for the cache ? Based on the example provided its the sum of all windows, but just wanted to check if there's a suggested way to choose the sample size, and what are the implications for choosing a bigger or smaller sample size ?

The parameter I am talking about is the one passed to the WTinyLFUCache::with_sizes function

pub fn with_sizes(
    window_cache_size: usize,
    protected_cache_size: usize,
    probationary_cache_size: usize,
    samples: usize
) -> Result<Self, WTinyLFUError>
al8n commented 1 year ago

Hi, sorry for the late reply, for the size, highly depends on the content that will be stored. So, unfortunately, there are no suggestions here.

vlovich commented 1 year ago

I had a similar question and I think the root is that it's unclear how to connect the size + sample parameters into an estimate of total memory usage & vice-versa (& just in general what those parameters control). More broadly, it's not even really clear what the size & sample values control. AFAICT:

Is that correct? Is there a more elegant way to convert human-friendly requirements (e.g. "I want to use at most 100 MiB of space with a false-positive rate of 1%" and maybe something like "here's the percentage breakdown among the different components within the LFU") into the actual parameters needed?

vlovich commented 1 year ago

@al8n can you help provide some color commentary on what the different parameters control & how they relate to memory usage / cache hit ratio? I'm not sure I fully understand how to convert target memory usage requirements into the parameters for the cache.