Live data from Hacker News

Show HN: Cachegrand – a fast OSS Key-Value store built for modern hardware

github.com

41–50 of 59 posts

Re: Show HN: Cachegrand – a fast OSS Key-Value store built for modern hardware

#41

Earlier quoted context omitted.

I would love to sit and write more documentation but I am doing this work during the night and/or over the weekends so sorry for not having it but I promise I will slowly slowly start to put together something more than a "TODO", even if it's a general intro. The timeseriesdb is "half" a consequence of having a Write-Ahead-Log that is split in chunks and it's chained. I am saying "half" because the other one is the f…

So the TSDB is being recorded, it’s just not queryable, or it’s not binary compatible with whatever the future in disk format will look like? Is the time series replicated and merged between nodes or does each have its own log for the keys it manages?

Currently both, the TSDB is a PoC right now.

The timeseries will depend on the keys, as it's the historical sequence of values, so it will be replicated and merged on the nodes that own that specific key in active-active replication with the required replication mode.

Although not mandatory, for the active-active replication mode cachegrand will provide a front-end proxy that "understands" which is the correct node for a key and send the necessary data to always the same node (or subset of nodes, depending on the configuration).

The replication itself will be last-write-wins, if the order of the writes matter it will be important to write always to the same node (very common pattern to reduce syncing and locking on the replication side).

Re: Show HN: Cachegrand – a fast OSS Key-Value store built for modern hardware

#42
post #36

Where does superior performance come from? SSDs optimizations, multi-threading, and O(1) mem allocator?

A bit from everything: the hashtable leverages the CPU caches and the cachelines, it also uses SIMD instructions to search very quickly the hash, once a bucket in the hashtable is identified, only the relevant bits in the hash are compared, on top of this there is the custom memory allocator, fibers and io_uring is of great help network side, etc.

The multithreading helps to scale the access to the hashtable vertically almost linearly.

The use of the fibers make everything easier because cachegrand doesn't have multiple threads running on the same core fighting for the same resources.

On top of this (and thanks to not having multiple threads fighting for the same resources on the same core), the hashtable uses user-space spinlocks (that are "fake" spinlocks as they can't prevent the kernel to preemept, although there are ways to do it) and the "contention" is spread all across the hashtable. The spinlocks though are only used to change the hashtable (with UPSERT, DEL and Read-Modify-Write operations), they are not required to read from it.

Let's say that thread A, B and C, want to access key1, key2 and key3.

If you an hashtable of 10000 buckets, cachegrand will basically split it in chunks of 14 elements and each chunk will have its own localized lock, so there will be about 714 different possible locks. In general, unless you are writing always to the same key, the writes will be distribuited across all the hashtable hitting different locks so it will not be necessary to wait.

Of course I considered different approches a few years ago when I was researching the hashtable including sharding it across multiple threads and let a thread own a slice of it but decided not to go down this way because instead of having 714 locks, like the case above, you will need to use queues to pass messages between the threads (a bit like Scala does) and "focus" the contention on limited number of memory areas (e.g. if you have 4 threads you will have 4 queues and focus the contention on these 4 queues which is bad). Of course you can use atomic operations to push and pop elements from these queues but it will not be able to scale up as the contention will make this system tremble under heavy load.

cachegrand, thanks to the localized spinlocks, can hit 60 million GET and 27 million SET per second on hardware used for benchmarking.

Re: Show HN: Cachegrand – a fast OSS Key-Value store built for modern hardware

#43
post #31

Any plans to make it distributed? Generally need reliability and fail-over more than straight line speed of using all the cores of a machine.

Absolutely, I was planning to introduce the Active-Active replication in a few releases but I changed the plan to do it for the v0.2, together with a memory control and an LRU to evict keys if it's necessary to free up memory, with RDB load support and the ability to work as slave in a Redis cluster, so it will be possible to join it to a cluster and having running to be used for other purposes if wanted (e.g. analytics or similar).

In general is pretty stable, I let it run for hours under memtier_benchmark hammering it, although I relocated in March and all my stuff is still packed in a warehouse (it's impossible to find an apartment in Zurich, Switzerland) but I am getting a new 2 x AMD EPYC 7551 with 512GB of ram to have plenty of room for testing and benchmarking with local hardware instead of asking favours :)

Re: Show HN: Cachegrand – a fast OSS Key-Value store built for modern hardware

#44
post #30

Are there any plans to implement key eviction to use it as a LRU cache?

Yes, I was planning to bring it in after a few releases and focus on more commands right now but I was asked to make it more production ready so the next release I will bring in: - Active-Active replication - memory control (with key eviction using an LRU) - RDB load & save (or at least RDB load) - the ability to run cachegrand as slave of a simple redis cluster (e.g. sharded but active-passive replication), so will be possible to introduce cachegrand slowly and test it out without impacting a whole deployment.

Re: Show HN: Cachegrand – a fast OSS Key-Value store built for modern hardware

#45
post #36

Where does superior performance come from? SSDs optimizations, multi-threading, and O(1) mem allocator?

In case you are interested, here there is a presentation I did for London Performance Summit https://www.youtube.com/watch?v=ZSpxuWQK7sM

For the hashtable part you can jump to minute 8.40.

This year I will present my efforts at the P99Conf, the content will be similar.

Re: Show HN: Cachegrand – a fast OSS Key-Value store built for modern hardware

#46

Earlier quoted context omitted.

I roughly agree that get throughput is not generally a bottleneck, but > 17.5k RPS which is an HUGE amount if we think that this would require easily between 50 and 100 machines beefy machines! Maybe we have different definitions of beefy, but in terms of HTTP, we serve 2-4x this on less than half that.

If I might ask, as I guess from your comments you are using Redis or a compatible platform, which are your numbers? Specifically I am referring to number of servers / vms for Redis, total core count, total memory available, total memory usage. Thanks!

I don't understand this comment in relation to your previous one at all, then.

You said:

Redis can easily chew 200k GET RPS on an average low-core count VM, even if an application does 10 Redis queries per request in average it would still take 20k requests to saturate it... which is an HUGE amount if we think that this would require easily between 50 and 100 machines beefy machines!

Which says you estimate 50-100 machines to saturate one "low-core count VM" Redis. But now you say you meant 50-100 machines for Redis servers?

We run about 20 machines, perhaps the equivalent of 10 "beefy machines", to handle a ~50k/sec request load (with substantially higher peaks). We have less than 100 servers total, most of which are doing asynchronous data processing and not directly in the request pipeline. Our data storage architecture is not really comparable to redis in terms of request load as it's insert/upsert-dominated but the total size is 5-10TB.

Re: Show HN: Cachegrand – a fast OSS Key-Value store built for modern hardware

#47

Earlier quoted context omitted.

If I might ask, as I guess from your comments you are using Redis or a compatible platform, which are your numbers? Specifically I am referring to number of servers / vms for Redis, total core count, total memory available, total memory usage. Thanks!

I don't understand this comment in relation to your previous one at all, then. You said: Redis can easily chew 200k GET RPS on an average low-core count VM, even if an application does 10 Redis queries per request in average it would still take 20k requests to saturate it... which is an HUGE amount if we think that this would require easily between 50 and 100 machines beefy machines! Which says you estimate 50-100 ma…

Let me answer and then give you some background for my question.

> Which says you estimate 50-100 machines to saturate one "low-core count VM" Redis. But now you say you meant 50-100 machines for Redis servers?

No, I was referring to machines running business logic functionalities using Redis as part of their processing pipeline.

Said that, the reason for which I was asking for some numbers was to figure out if my expectation of "very often you need more room for the data than better performance" was making sense.

Because cachegrand will be able to store data on disk and to handle stream writes as well allowing to leverage the time series db, once fully implemented, it will able to cover a number of different needs. This combined with the ability to run Webassembly means that you will also be able to run whatever you want directly in place and data will not have to go out and in from multiple systems to be processing making the pipelines much faster and cheaper to run.

Of course it doesn't take 1 day, especially because I am working on cachegrand during my free time (e.g. At night or over the weekends).

Re: Show HN: Cachegrand – a fast OSS Key-Value store built for modern hardware

#48

The redis compatibility layer seems to be very early stage, see https://github.com/danielealbano/cachegrand/blob/main/docs/a... Compare with e.g. dragonflydb: https://github.com/dragonflydb/dragonfly/blob/main/docs/api_... Interesting to see how this will develop over time.

It is early stage in the sense it only support commands that operate on the strings and some on the key space.

Other commands are planned to be added soon but the ones already implemented cover already a lot of different use cases.

Re: Show HN: Cachegrand – a fast OSS Key-Value store built for modern hardware

#50

The redis compatibility layer seems to be very early stage, see https://github.com/danielealbano/cachegrand/blob/main/docs/a... Compare with e.g. dragonflydb: https://github.com/dragonflydb/dragonfly/blob/main/docs/api_... Interesting to see how this will develop over time.

DragonflyDB is not open source, unfortunately.
Post reply on HN