https://slatedb.io logo
https://github.com/slatedb/slatedb/pull/284 It's g...
# general
a
https://github.com/slatedb/slatedb/pull/284 It's great to be back in the Rust world!
c
Hey! Still digging my way through, but left a high-level question for you.
In general, the code is pretty sophisticated (and my Rust foo is ๐Ÿ˜ญ ). I'm trying to tease apart if the addedd complexity is worth it vs. using existing LRU caches?
a
I'm sorry I couldn't reply in time. The reasons why I chose to implement LRU myself are as follows: moka and foyer support size aware eviction, but there are too many unnecessary functions.
lru-rs
is good enough, but does not support size aware eviction.
If you choose to add size aware eviction to
lru-rs
, you will get my implementation.
message has been deleted
Why we need size aware evictionโฌ†๏ธ
However, I finally chose to change the LRU implementation into a generic version instead of a special version. But the general idea has not changed.
message has been deleted
I had some discussions with @flaneur233 about choosing the current implementation.
f
i suppose it'd better to start by using an existing library when introducing a new algorithm. If an algorithm can't be easily implemented using established libraries, that could signal potential hidden complexities we should be cautious about ๐Ÿค”
i am kinda afraid of maintaining low level data structures & battling lifetimes with rust ๐Ÿ˜ข , if it's possible, i'd strongly suggest using a crate instead of having a hand-crafted data structure inside the repo.
a
This is moka's document. To be precise, we don't need a cache here, just an LRU queue. However,
lru-rs
does not support size aware eviction. Using it also requires the introduction of a new crate.
If we fork
lru-rs
, and modify it, we will get my implementation.๐Ÿ˜ In fact, I donโ€™t want to manually implement the data structure myself. But there is no other particularly good way.
My computer has encountered some strange problems again, and I can only use my mobile phone right now๐Ÿ˜…
f
i guess size-aware eviction could be seperated in a standalone feature? having basic & simple eviction might be enough for most of the workloads at the moment. imho in most of cases, we can choose let things dumb & simple at first and observe how it goes in real workloads, then we can always add more flavors after new requirements from the real workloads emerged.
a
This is the problem. The reason why we use size aware eviction is to cleverly determine the size of the ghost queue.
https://github.com/slatedb/slatedb/blob/main/src/db_cache/moka.rs#L81 In other words this is a question of cache entry number and cache size conversion.
Since we are only tracking unique identifier(Path), this is small relative to the entire cache. Consider this situation:
max_cache_size_bytes
is 16GB, then the ghost queue is initialized to 1.6GB Obviously, if there is no size aware eviction, our LRU is too big to hold a bunch of Paths. Doesn't work as a filter at all
f
i still can not fully understand why it's a must to fork a crate. if i understand correctly, what we hope is to limit the memory usage of a lru, right? i guess we could estimate the size by a wrapper over the lru, and count the bytes by ourselves, instead of fork it.
came up with another idea but might help with this: can we store a u32 hash of the key in the ghost queue, instead of a full Path?
a
So import a new crate and make a wrapper?๐Ÿค”
f
i don't know, but i guess if we have to depends on some crates, it's better to depends on some well-adapted crates.
a
I can give it a try after my computer is repaired.
f
what dou you think about this?
if u32 hashes are stored, the size of them are unificated at 32 bits, and all you need is to estimate how many bytes per key in the lru is consumed.
besides that, i think a
ghost_queue_size
config might already makes senses to me instead of calculating it with
max_cache_size_bytes
๐Ÿค”
a
However, the capacity of ghost should correspond to disk cache, such as 16GB. We will still suffer from this problem. store hash only contributes to the memory footprint of the LRU itself.
f
in my understanding, a
ghost_queue_size
config could make it works for me ๐Ÿค”
a
Consider a 16GB disk cache, assuming we use a fixed-length LRU, such as 32 entries. We may suffer from a low disk cache hit rate, then we should increase the ghost capacity to increase the replacement rate and allow popular elements to be written to the disk cache as much as possible.
If it is too large, then the hit rate of the ghost itself is too high and we will not be able to achieve the filtering effect.
I don't think users want to know what this thing does. They will only want to specify the size of the disk cache itself.
But I can try to do wrapper based on LRU.
f
ok, let's figure out a way to avoid checking in the LRU implementation code in the repo ๐Ÿ™‚
a
I hope my computer can be repaired as soon as possible in the next two days.๐Ÿ˜