https://slatedb.io logo
Regarding keeping data we don’t need on local disk...
# general
c
Regarding keeping data we don’t need on local disk, I feel that’s relatively cheap. I’m thinking we should design for working set fitting on disk anyway.
r
My concern is less the cost of the added space and more about displacement. The data sitting next to a read record in an sst is no more likely to be read than anything else in the db. So when space is limited we are pulling in a ton of data that isnt particularly likely to be read soon. And when we promote something in the lru queue we are also promoting a bunch of other data that thats not particularly likely to be accessed soon. With cachelibs architecture they dont do this because they accumulate smaller sized units of data into a larger chunk alongside other stuff that was also recently accessed, and then treat that as the cache unit.
f
when comparing with flashcache, cachelib is more like an high level K/V cache or even in-memory db, it offers some high level abstractions like HashMap so they could merge the data placement in a fine-grained level. am i understand correctly?
so that they could shuffle the recently accessed K/V together into a same cache unit, which resembles a MemTable (but be filled up by recently read) and a SST when it's flushed on disk.
c
That sounds right. One point of clarification from Rohan: were you thinking of doing KV-based or block-based with the cachelib approach? I was thinking of using blocks. So there is still some waste, but I think it becomes much easier to implement.
r
I was imagining block-based. there'd be way too much metadata with kv-based
c
💯
That’s exactly what I was thinking
And cachdlib tries to do all this key shortening stuff
But our keys would all be usizes
So it’s a lot easier
r
and yeah that sounds about right @flaneur233 . Also I think I've been causing some confusion by using cachelib and flashcache interchangeably. I think flashcache refers to some older in-kernel caching thing facebook built. Cachelib also has an on-disk cache that they call Flash (https://cachelib.org/docs/Cache_Library_Architecture_Guide/overview_a_random_walk#flash-overview). It also has a small-item (BigHash) and large-item (Block Cache) component That latter thing is what I'm referring to here
c
lol ok that really confused me
Cuz flash cash is tiered kernel thing now
Hahaha
@Rohan this is what I was thinking ^
f
oh, in my memory flash cache is a disk block cache, i think it caches a more coarse grained manner than cachelib
r
yep. I think I had read about flashcache a while back and then that term stuck in my brain because the on-disk part of cachelib is referred to as Flash
yes that makes a ton of sense to me. That's basically how I was thinking about it too
I was not sure about the best way to persist the block->file+offset metadata
snapshotting it periodically seems reasonable. I was also trying to seei f we could just stick it in slatedb, but I haven't taken that idea far at all.
f
so comparing with the block storage layer caching like alluxio approoach, i guess this cachelib like approach has the benefits: 1. it does not introduce read amplification like (4kb or 4mb) boundary 2. it could arrange the recently accessed blocks into a big blob file (like 128mb), in the timely order 3. evict is easy in FIFO
c
I think periodic background write is fine. On restart we can load it back in async too.
I thought about using manifest—similar to slate db. But it’s too big. And it’s local. Different machine would have old/no cache. So it felt odd to put it remote.
f
the mapping would better to be mmap-able
or else it would slow down the start up time
c
Yea that sounds right. But I think there might be tradeoffs. For example range query would benefit from alluxio approach
Great idea.
r
any references for alluxio? I'm not familiar
c
It’s just the partition approach we have now.
(IIUC)
alluxio is a famous object store's transparent cache solution used on some big data workload
i guess mostly of the big data workload are range queries
c
Ya was gonna say
f
beside caching, it can also play as an acceleration layer, with replacing a single GET into parallel GET requests
c
@flaneur233 is there a point in this doc where they actually describe the design? I couldn’t find that earlier.
f
this doc is not describing the design but the usage, let me find whether they ve published some papers or not...
r
doesn't the cachelib design basically degrade into that if you use a large enough unit? e.g. you could do 1 block, but nothing prevents you from loading more than 1 block at a time either
f
not exactly, the partitioned approach kinad assumes memory access locality, it aggregate the smaller access units (like 4kb blocks) into bigger units (like 4mb or 64mb), and assumes that the memory access pattern (especially RANGE) kinda leverage these locality
c
I think Rohan is saying you could accomplish the same thing by treating the cache item not as one block but as several. For example you might read from object storage and cache 4 blocks at a time rather than 1.
This gives you some flexibility. If you did 4mb block collections, you’d end up with what we have now, roughly.
r
yeah. It could be some config option that you can tune based on the expected workload.
c
That’s what I was thinking
f
to use the persisted block cache way, i think it's not cache on read, but to flush the evicted in memory block cache into disk? so i think this approach could be less coupled with networking
c
Yea. So we’d have to fetch N blocks on read to force them into the in memory cache. From there, the actual block that needs to be read will be returned. The remaining will either be read later or evicted into the on disk cache. So the collection could get a bit split up depending on eviction and read order. But it should be close I think.
r
> The remaining will either be read later or evicted into the on disk cache. what does the remaining refer to here?
f
but one thing i still did not fully understood is that, if the written blocks to disk are the evicted ones from the memory block cache, could these blocks regarded as frequently accessed at the same time? 👀 imho the hottest blocks are more likely to be frequently accessed together.
r
I think we have to promote them back to in-memory cache when they're accessed. Is that what you mean @flaneur233 ?
f
i still not quite clear is the time we put these memory blocks into disk is considered when the memory cache is full, and then it will flush some of the evicted blocks from memory into disk, right? the hottest blocks if they're frequently being accessed, will remain in the memory
r
right, so the question is what would the LRU for the on-disk cache track? I suppose it would be the blocks that were least recently promoted to the in-memory cache.
f
suggestion about how to track the promotion numbers?
r
we'd probably want to be somewhat careful about promoting blocks to the in-memory cache. Like we shouldn't promote a block whenever it's accessed to avoid thrashing. So sometimes we'd just serve from the disk cache and not promote. I need to think about it more. It's getting late here in NYC and my brain is turning off 😄