Which is the best Java memcached client, and why?
-
Define "best". What are you trying to optimize for? – Steve Kuo Apr 08 '09 at 20:50
-
For spymemcached, the newest jar could be found on maven, and the newest source code is on github, but documents are still on google code ...... – Eric May 05 '15 at 09:10
7 Answers
As the author of spymemcached, I'm a bit biased, but I'd say it's mine for the following reasons:
Designed from scratch to be non-blocking everywhere possible.
When you ask for data, issue a set, etc... there's one tiny concurrent queue insertion and you get a Future to block on results (with some convenience methods for common cases like get).
Optimized Aggressively
You can read more on my optimizations page, but I do whole-application optimization.
I still do pretty well in micro-benchmarks, but to compare fairly against the other client, you have to contrive unrealistic usage patterns (for example, waiting for the response on every set operation or building locks around gets to keep them from doing packet optimization).
Tested Obsessively
I maintain a pretty rigorous test suite with coverage reports on every release.
Bugs still slip in, but they're usually pretty minor, and the client just keeps getting better. :)
Well Documented
The examples page provides a quick introduction, but the javadoc goes into tremendous detail.
Provides High-level Abstractions
I've got a Map interface to the cache as well as a functional CAS abstraction. Both binary and text support an incr-with-default mechanism (provided by the binary protocol, but rather tricky in text).
Keeps up with the Specs
I do a lot of work on the server itself, so I keep up with protocol changes.
I did the first binary protocol server implementations (both a test server and in memcached itself), and this was the first production-ready client to support it, and does so first-class.
I've also got support for several hash algorithms and node distribution algorithms, all of which are well-tested for every build. You can do a stock ketama consistent hash, or a derivative using FNV-1 (or even java's native string hashing) if you want better performance.

- 89,080
- 21
- 111
- 133
-
2Using in production, and recently looked through the source code on the site's javadoc. Just wanted to say, really, really nice work. Thanks. – Steve B. Apr 09 '09 at 20:12
-
1As of today there is an issue in the latest release - http://code.google.com/p/spymemcached/issues/detail?id=136. It looks like it is being addressed, but you should note this if you are just starting out. – rado Feb 01 '11 at 00:48
-
2136 has been fixed and is in testing in a few environments. Release is imminent. You can get more up-to-date info from the list. – Dustin Feb 01 '11 at 17:29
-
@Dustin, this is probably a dumb question (coming from a memcached noob), but how does your single-threaded implementation effectively serve a multi-threaded application? – Web User May 23 '12 at 15:12
-
2memcached itself was single-threaded for a very long time, until it actually could benefit from consuming more CPUs. Threads are good for spreading out computation across multiple (mostly) independent processors. Threading APIs are often used as concurrency primitives, but they're primarily parallelism primitives. You don't need more than one thread to model concurrency. – Dustin May 23 '12 at 19:19
-
@Dustin : Will you let me know how spymemcached support for UDP get() ? (http://stackoverflow.com/questions/24103977/how-spymemcache-client-use-udp) – Débora Jun 14 '14 at 05:36
-
@WebUser The other thing to remember is that ethernet is a serial interface, so if you can do non-blocking IO and you're not IO-bound, you don't need more than one thread to saturate the interface. – David Ehrmann Nov 10 '15 at 00:04
-
-
What's happening with spymemcached now that the googlecode repo is down? Which is the canonical version to use? Is it actively updated for Java 8 etc? – Nic Cottrell Oct 26 '16 at 15:07
-
I believe memcached java client is the best client.
Features
- Binary protocol support. fastest way to access the key/value stored in memcached server.
- UDP protocol support. You can set key with tcp protocol, and get with udp protocol. Acctually, some big corporations are doing like this.
- Support customized serialization and deserialization.
- Connection pool with NIO and direct buffer. Dynamically increase connections when out of use for the connection pool.
Performance
- Refer to performance for a benchmark test of existing popular memcached java clients.
- Deserializing while receiving the response
- Performance tuning into each line of the source code.

- 51
- 1
- 2
-
1do you mean this one https://github.com/gwhalin/Memcached-Java-Client ? Maybe hyperlink from the top of your answer... – Nic Cottrell Mar 21 '14 at 07:09
If these are numbers still valid, then ... http://xmemcached.googlecode.com/svn/trunk/benchmark/benchmark.html

- 2,168
- 24
- 29
As of about a year ago, when I had to use a memcached java client, the spymemcached connector was described as an optimized API with more features. Since then there've been a number of new releases of the memcached client so it may be worth checking out.
FWIW the spy client has worked perfectly for me.

- 55,454
- 12
- 93
- 132
I have been using SpyMemcached and have to agree that it is the best one available out there, with lots of newer improvements.

- 3,189
- 7
- 38
- 45
Please try xmemcached, it is also nio based and have some powerful features.

- 155,785
- 88
- 678
- 743
There is the memcached client for Java and spymemcached. Not much experience with either though.

- 616,129
- 168
- 910
- 942