121 points · by daniele_dll · 4y ago · 55 comments
It scales up really nicely thanks to a year of research and development of the hashtable implemented in cachegrand, on the hardware used for benchmarking, an AMD EPYC 7502P, it was able to reach up to 5mln GET QPS and 4.5mln SET QPS, with batching up to 60mln GET QPS and up to 26MLN SET QPS.
cachegrand is fast, it's fully Open Source, it's under a BSD 3-clause license - it can be used easily as standalone platform or incorporated in other ones without any licensing issue - and we are working to expand the Redis functionalities supported and to impelement a tiered storage to cache more data than the available memory. Longer term our goal is to expand the support to different platforms (e.g. memcache, kafka, etc.), add support to webassembly to have user defined functions and server side events, and of course a network bypass (combining XDP and a lockless FreeBSD tcp/ip stack) and a storage bypass.
Although it can easily used via docker, here a direct link to the latest release https://github.com/danielealbano/cachegrand/releases/tag/v0....
Currently we are focused on supporting Redis, here the list of commands currently implemented 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.
Other commands are planned to be added soon but the ones already implemented cover already a lot of different use cases.
0: https://github.com/dragonflydb/dragonfly/blob/main/LICENSE.m...
There is a reason for which the BSL is not a recognized open source license.
https://www.linkedin.com/posts/danielesalvatorealbano_cacheg...
In general I am pretty sure cachegrand would be faster than memcache easily but I will add it to the todo list as it makes sense.
Thanks for pointing it out!
- https://aerospike.com/blog/aerospike-4-strong-consistency-an...
Dragonflydb also break Redis license big time.
Since the comment says "Trust me as a committer it smokes aerospike and dragonflydb." we can rule out aerospike and dragonflydb, which leaves us with "it" being Cachegrand. Ain't that deep.
(Obviously it does happen, but statistically speaking it's almost never)
In terms of "just performance", 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, if we leave 15% of marging for peak traffic / issues / surprises / etc, it would still take an application handling 17.5k RPS which is an HUGE amount if we think that this would require easily between 50 and 100 machines beefy machines!
I think the biggest limitation nowadays is instead the cost of using "only" memory for the cache and having to use a bunch of different systems to process your data.
Try to imagine what you would be able to do if cachegrand would ingest your stream as kafka-compatible server, run your webassembly compiled script and/or run your ML/AI models (leveraging webassembly) and then let push data to other databases / systems and/or let you access your processed data via the Redis / Memcache / GraphQL interface!
And on top of this, imagine that all these modules (Kafka, Redis, Memcache, GraphQL, etc.) can leverage a network bypass and a nvme bypass to perform super fast I/O.
It's a lot of stuff, but that's my long term goal / vision.
Of course to achieve all of this, you need a blazing fast and very flexible base! We are currently focusing on the Redis support because needs many different bits and pieces and would allows us to have people starting to use cachegrand which is a key to understand if the grand plan makes sense :)
> 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.
Thanks!
https://news.ycombinator.com/item?id=31563641
TL;DR Unlikely to be apples to apples comparison and you can get much more performance out of Redis easily.
But honestly, performances aren't the "only" goal and they aren't the main goal neither although to get where we want to be of course we need extremely good numbers! :)
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 future addition of secondary index to make it possible and easier to query the internal db properly.
I know that we are talking mainly about Redis right now, but that's just the tip of the iceberg and my long term vision is to build a much more complete and flexible platform which can easily handle streams (e.g. via a Kafka interface) and/or allow you to run more evolved data processing via WASM (e.g. I want yo make possible to calculate rolling window averages in a time-sensible fashion :)).
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.
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.
For folks wanting to learn more, we'll have Daniele's session for cachegrand at P99 CONF next month (free, virtual event): https://www.p99conf.io/
[edit: just realized we'll also have Roman Gershman of DragonflyDB. So you can hear two different ways to tackle the issue.]
I also promise to document more the actual inner workings of the various components, I have some scattered documentation here and there which will help me in the task!
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 :)
My goal is to make it usable enough from the 0.3.0 where I want to have enough Redis commands supported (hashsets, sets, lists, multiple dbs, hyperloglog, etc.), have more memory control and have an MVP of the on-disk database.
Implementing the data replication, which will come right after, will be fairly easy, thanks to all the logics already built in for the on-disk database, so that should be implemented fairly quickly.
Also I have recently bought 2 x AMD EPYC 7551 so I will setup a better performance regression tracking and a proper benchmark suite to track everything (a contributor is working on leveraging the tests and use them as base for the two things mentioned above)
Most of the performance exploits for the hashtable (which is the driving engine here) are explained after minute 8.30 (although I would suggest you to watch the entire presentstion).
I will present my work at the p99conf as well.