The MemCached documentation mentions data is distributed across nodes. That's their definition of distributed cached. If a node A needs data that is on node B, data is transferred from B to A. If A crashes, all data stored on A is not available to B anymore.
However, EhCache has a different definition of distributed caching. Basically, it is more like shared-memory than distributed cache. If node A modifies some data, node B will see that modification. If A crashes, any data A stored in the shared-memory remains available to node B.
This leads me to two questions:
If I have 3 nodes A, B, C each having 1GB of memory, it seems like MemCached will add up memory and make it look like a total of 3 GB of memory for the nodes. However, it seems like EhCache does not add the 3 GB, but rather will allow at most 1GB of shared memory between each nodes. Is this correct?
If answer to 1. is yes, then is it correct to conclude that EhCache and MemCached are actually complementary rather than in competition?
Speaking just as to what Ehcache does as I'm no expert on Memcache.
Ehcache is a "tiered cache." It allows you to scale-up and scale out at every tier. If you had 3 server nodes of Ehcache (Actually the server layer is the TSA, Terracotta Server Array) each of those server nodes would have unique data so not including what can be swapped to disk you would have 3gig. The TSA can be configured to use disk persistence for HA and/or active passive failover. With BigMemory plugged in you can grow any of these tiers to hundreds of gigs of ram without fear of GC issues.
So why is a tiered cache cool? It's how it uses the memory in your client. You can have coherent data, up to hundreds of gigs, just micro-seconds away in process in the on heap and off heap local tiers or milliseconds away on the remote tier. And all the data can be HA.
You can read more about some of this stuff here:
http://scaleaholic.blogspot.com/2010/09/little-bit-about-bigmemory-for-ehcache.html
and here:
http://scaleaholic.blogspot.com/2011/08/what-is-terracotta.html
and of course: ehcache.org and terracotta.org
I've some experience with both.
I'd say 'yes' to both your questions.
I've been using ehcache together with Hibernate. It caches data found in a central database in memory on several server nodes in a cluster. Reason is of course to have less database accesses. If a cached value is written to by one node, then this value should be invalidated on the other nodes to force them to re-read the value from the database, and re-cache it.
Memcached I've used as datasource. It's a simple key=value database. On every service node you define a list of memcached nodes that it can use. Then it will write to some node (by round robin I guess). The key has the information about which memcached node the value is stored on.
So in my experience, memcached is a, often distributed, database (not the relational kind, but still a database), while ehcache is more a traditional cache.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With