143 points · by mfrw · 4y ago · 87 comments
How much effort would be required to get memc to equal or surpass memcached's performance? Would it require rewriting the datastructures from scratch? Fine-tuning or rewriting the tokio?
Would be surprised if it didn't, and most of the time it should probably be even.
It's the edge cases that separates naive implementation from industrial usage. And off the shelf concurrent hashmaps are already pretty advanced.
Both of these are things a high quality allocator (jemalloc in this case) has to to optimize for as well (in this context "allocation calls" corresponds to syscalls). For example they also allocate different sizes from different buckets.
Applications do have some abilities an allocator does not have, for example:
* It can move allocations, since it can invalidate pointers. This allows defragmentation/compaction to happen
* It can try to predict how long lived an allocation will be
But it's not clear to me if any of these are important for performance.
No it doesn't. A cursory scan through the code will tell you as much.
As an arbitrary example, on my machine if I run memtier_benchmark like so:
memtier_benchmark --port=11211 --protocol=memcache_binary \
-t 4 --ratio=1:1 --pipeline=9 -c 16 \
-d 100 --key-pattern=S:S --key-minimum=1 \
--key-maximum=1000000 -n allkeys
I get the following results: memc: 63999483 ops, 587092 ops/sec, 51.39MB/sec, avg 0.82 msec latency
memcache: 63999936 ops, 2391777 ops/sec, 209.34MB/sec, avg 0.24 msec latency
memtier_benchmark also prints out more detailed stats, but I couldn't get those to work for memc. Not sure what's going on there.If we set the set/get ratio to 1:10 (maybe more realistic), they get much closer:
memc: 6399480 ops, 639989 ops/sec, 28.45MB/sec, avg 0.67 msec latency
memcache: 6399623 ops, 1291566 ops/sec, 57.41MB/sec, avg 0.40 msec latencyUsing memtier_benchmark --pipeline=1 with "memcached -t 1" and "memcrsd -r 1" shows almost identical results (141943 vs 136550) on my machine (keys 1 -> 100000). The network is where most of the CPU is spent in both memcached and memcrsd cases.
I'm slightly impressed with memcrsd/rust scaling, 32 runtimes with 16 memtier_benchark threads with pipeline=9 can produce 4 million ops/sec. They need to fix the networking parts.
I think most will use horizontal scaling anyway, and simply shard the memcached's and skip the threading concurrency. Multiple memcached's with client side sharding is hard to beat.
This also does not mean rust might not have its fair share of bugs; IMHO the probability is a little less.
Edit: I mentioned the log4j RCE as it was new & do not mean to imply that it would not have happened if we had a rust implementation. As the comments have mentioned, it would be the same in any language IMO
Not really. You'd have to fight the language and pull in some crates, to be sure. There's no native object serialization in rust and it's not really a concept in the language or ecosystem - except perhaps in the future with wasm runtimes.
There are numerous details of log4j that, in general, just don't apply to rust code.
edit: Since perhaps people don't believe me...
Rust has no equivalent of JNDI, pickle, etc. There is no way to send rust 'code' except, perhaps, wasm. Certainly there's no well supported way with decades of history of being ingrained into libraries, or patterns that support it.
The root of the log4j problem is a failure to distinguish between log format strings and the formatted log string, beyond that what happens is that Java allows a lot of flexibility at runtime which simply doesn't exist in Rust. In Java it's fine to, at runtime pull in classes you've never used before and run them, you can't do that in Rust - the types only existed at compile time. Indeed this is a key feature of Rust, because it means wrapper types are free at runtime, invaluable to the embedded firmware community who love type checking and other safety features but can't afford runtime overhead.
Exactly, Rust simply eliminates a certain class of bugs. You can still make some really major mistakes in the absence of these bugs, e.g. "goto fail" could have easily been written in Rust.
Here's an explanation of "goto fail", which includes a code snippet.
https://nakedsecurity.sophos.com/2014/02/24/anatomy-of-a-got...
If C conditionals required explicit braces around the body, the second fail would have been redundant code instead of a security vulnerability.
Additonally, Rust will warn you if you have "unreachable" code, such as all the code after the unconditional "goto fail". Though, I'm sure modern C compilers would also warn about this.
All that said, Rust definitely does have plenty of bug classes left for people to trip over. Integer under/overflows come to mind (though they're just logic errors instead of undefined behavior).
Remember heartbleed?...
> Safe: Implemented in Rust programming language and using Tokio runtime ensures memory and thread safety.
Does memcached have issues with memory and thread safety? I've never heard of them if it does.
> Fast: Can process thousands of requests with minimal overhead.
For a network cache you want _predictable_ performance more than "fast" performance, so that you're able to predict how a system will scale. "Fast" is among the top priorities for choosing a network cache implementation.
> Compatible: memc.rs is 100% compatible with memcached binary protocol. No need to rewrite your code. Just start a server and use your favorite language/framework.
What about tools for monitoring memcached in production? Does it support consistent hashing across a pool memcached servers?
Ultimately: why?
This is AGPL or commercial.
The biggest difference I could find was not in the capability of it as a drop-in replacement but in the change of licence as any changes you might have to fit your needs now has different terms.
I guess the bet here is predicated on that... are companies running versions of memcached that are much improved and they're not sharing those improvements? Could this be a way to make those improvements public by this replacing memcached over time?
I'm not sure how they could do a commercial licence once they've accepted contributions, if they don't have a CLA granting the right over the contributions. But IANAL, etc.
Those who wish to share their contributions will, regardless of license. Those who do not, will stick to code with BSD-style licenses.
s/Drop-In Replacement/Rust partial reimplementation/I know it's Redis, but it's basically the same as Memcached if you only use the key-value set/get commands.
See this blog post [2] and this Gophercon 2021 talk [3] for examples of it's use in production.
[1] https://github.com/ideawu/ssdb
[2] https://wakatime.com/blog/45-using-a-diskbased-redis-clone-t...
Sorry this stuck out to me. what would be state of the art in the in memory kv store world then?
You might be confused how a CPU, memory, and I/O are interconnected. First, for an application to access data in memory, all it need to do is issue a MOV with indirect addressing. It might trigger a minor page fault which gets handled quickly by the OS. For an application to read data from disk, it must submit a request to the disk controller through the OS. I am ignoring a lot of details but that's all you need to reconsider the information in the links you shared.
Keep in mind that reading from memory is in the nanoseconds, while reading from NVME is in microseconds.
Memcached also has a mechanism for storing values (but not keys) on disk for larger-than-memory datasets which works well on big parallel flash drives.
EDIT: The website seems down but I was able to find a graph on archive.org via https://web.archive.org/web/20210721201604/https://ssdb.io/ but without latency, only QPS in some simple benchmarks. It's not slow, but if you're pushing high QPS-per-core or low latency, there's no indication it will serve as well as alternatives, and that can have a bigger impact on ROI than just the cost of disk-vs-memory for your servers.
Otherwise, you’re going to be adding equivalent memory to get to equivalent performance between memcached and ssdb.