https://slatedb.io logo
<@965845316370833408> If `max_cache_size_bytes` i...
# general
a
@flaneur233 If
max_cache_size_bytes
is None, will we write the data to the disk cache?
f
in my memory, if max_cache_size_bytes is set as None, it only disables the Evictor, and writes are still allowed
a
So when
max_cache_bytes_size
is None, I think we should do nothing with elements that are only accessed once.🧐
f
i consider this option is for evictor only, if it's None, evictor does nothing, and the cached files will keep increase withou eviction quq
i suppose setting max_cache_bytes_size as
Some(0)
is more like disabling the cache
a
I have an immature idea. If
max_cache_bytes_size
is None, we will not enable size aware eviction of ghost queue, and the initial size of the ghost queue is set to 32 entries. In this way, we can provide resistance even when there is no evictor.(32 is magic number)
When
max_cache_bytes_size
is None, it looks like this:
let ghost = LruBuilder::new(NonZeroUsize::new(32).unwrap()).build();
f
if i understand correctly, the ghost queue's intent is to avoid writing cache files which are only accessed once into disk, right? and evictor mainly targets the files that already exist on the disk. i am afraid my understanding about ghost queue is still limited, can you help give an example about the lifecycle of a cached part file with ghost queue considered? quq
a
Ghost Queue: LruCache size: 2 a simple example: read Location a(first access) -> ghost queue{a}, disk {} read Location b(first access) -> ghost queue{b, a} disk {} read Location a -> ghost queue{b} disk{a}(actual data write) read Location c(first access) -> ghost queue{c, b} disk {a} read Location d(first access) -> ghost queue{d, c} disk {a}
I ignored the part about ghost queue adaptively adjusting its capacity.
If we use size aware eviction, it might look like this:
let ghost = LruBuilder::new(NonZeroUsize::new(capacity).unwrap()).with_weighter(|_, v: &ObjectMeta| v.size).build();
f
thank you for the explanation! i haven't fully caught up about the relationship with ghost queue and max_cache_bytes_size yet, but i suppose it might be easy to start with a standalone config like
ghost_queue_capacity
? and we can unify them later when we find there is always duplication between these configs. what do you think?
a
If
max_cache_bytes_size
is not None, we enable size aware eviction and set the initial capacity of the ghost queue to
max_cache_bytes_size * 0.1
.
message has been deleted
The reason why
weighter
is introduced is this. If we use a fixed number of entries (e.g. ghost queue holds 32 elements), there will be almost no hit in ghost cache for read dominant workloads and the cache content remains unchanged.
In other words, a low hit rate probably means 1) a lot of popular blocks are out of cache or 2) the workload lacks locality and there are no popular blocks at all.
This is indeed a very subtle question, but it doesn't matter if we don't provide resistance to accessing elements only once when
max_cache_bytes_size
is None.🤣
If
max_cache_bytes_size
is None, our processing logic is the same as the current implementation. This is how my uncommitted code do right now.
f
thank you for sharing this! sorry I fell asleep during half of this thread. it makes sense to me that when setting it as None, we'd use a default value. is this understanding correct?
a
Copy code
// If `max_cache_size_bytes` is None, `ghost` will be `None` and we do nothing with elements that are only accessed once
        let ghost = max_cache_size_bytes.map(|max_cache_size_bytes| {
            Arc::new(Mutex::new(
                LruBuilder::new(NonZeroUsize::new(max_cache_size_bytes / 10).unwrap())
                    .with_weighter(|_, v: &ObjectMeta| v.size)
                    .build(),
            ))
        });
This is how I currently handle it.
f
looks great to me 👍
a
My idea is to give a default size to the ghost queue when
max_cache_bytes_size
is None, thus providing some resistance.