64

Question is clear as you see in the title, it would be appreciated to hear your ideas about adv./disadv. differences between them.

UPDATE: I have decided to use Hazelcast because of the advantages like distributed caching/locking mechanism as well as the extremely easy configuration while adapting it to your application.

7 Answers 7

94

We tried both of them for one of the largest online classifieds and e-commerce platform. We started with ehcache/terracotta(server array) cause it's well-known, backed by Terracotta and has bigger community support than hazelcast.
When we get it on production environment(distributed,beyond one node cluster) things changed, our backend architecture became really expensive so we decided to give hazelcast a chance.

Hazelcast is dead simple, it does what it says and performs really well without any configuration overhead.

Our caching layer is on top of hazelcast for more than a year, we are quite pleased with it.

1
  • 1
    Is there a notable slowdown when switching from one-node in-memory Java cache to Hazelcache?
    – Pinch
    Jan 9, 2016 at 2:39
19

Even though Ehcache has been popular among Java systems, I find it less flexible than other caching solutions. I played around with Hazelcast and yes it did the job, it was easy to get running etc and it is newer than Ehcache. I can say that Ehcache has much more features than Hazelcast, is more mature, and has big support behind it.

There are several other good cache solutions as well, with all different properties and solutions such as good old Memcache, Membase (now CouchBase), Redis, AppFabric, even several NoSQL solutions which provides key value stores with or without persistence. They all have different characteristics in the sense they implement CAP theorem, or BASE theorem along with transactions.

You should care more about, which one have the functionality you want in your application, again, you should consider CAP theorem or BASE theorem for your application.

This test was done very recently with Cassandra on the cloud by Netflix. They reached to million writes per second with about 300 instances. Cassandra is not a memory cache but you data model is like a cache, which is consist of key value pairs. You can as well use Cassandra as a distributed memory cache.

2
  • 1
    How does one implement CAP theorem?
    – Kyle
    Dec 31, 2012 at 16:12
  • 2
    CAP is not meant to be implemented, it says that in a distributed system you can't have Consistency Availability and Partition-tolerance at the same time. Basically Available Soft-state Eventual-consistency, means that availability has priority over consistency, however the data will be eventually consistent, soft state means that data is in stored in volatile storage,e.g, RAM. Most distributed caches and NoSQL products implement BASE.... So BASE is way to deal with CAP
    – user454322
    Jan 23, 2014 at 12:44
12

Hazelcast has been a nightmare to scale and stability is still a major issue.

The dedicated client to grid component choices are

  1. The messy version that cant survive node loss anywhere, negating the point of backups (superclient), or
  2. An incredibly slow native client option that does not allow for any type of load balancing to processing nodes in the grid.

If any host could request records from this data grid it would be a sweet design, but you are stuck with those two lackluster option to get anything out of it.

Also multiple issues with database thread pools locking up on individual members and not writing anything to the databases, causing permanent records loss is a frequent issue and we often have to take the whole thing down for hours to refresh any of the JVM's. Split brain is also still an issue, although in 1.9.6 it seems to have calmed down a little.

Rallying to move to Ehcache and improving the database layer instead of using this as a band-aid.

2
  • 38
    PS: I work for Hazelcast. James, I am really sorry that you had major issues with Hazelcast. As far as I remember you were using Hazelcast just like a relational database with queries and we advised to change it to a key/value pattern. An access pattern with a key is much faster than doing a query. However I agree that with Hazelcast 1.9 sometimes, a node loss forced to restart the cluster. After 1.9 we released Hazelcast 2 which is on its 2.6.2 version now and recently Hazelcast 3. We improved the clustering layer a lot. Oct 8, 2013 at 17:06
  • 1
    James - did you PoC on a different solution? what were the results? Did you have to change your app architecture? Apr 17, 2017 at 13:55
7

Hazelcast serializes everything whenever there is a node (standard-one), so the data you will save to Hazelcast must implement serialization.

http://open.bekk.no/efficient-java-serialization/

2
  • 1
    Is Terracotta not doing serialization of objects when they are streamed?
    – FreeDevz
    May 4, 2015 at 3:54
  • @FreeDevz - TerraCotta, according to its documentation - is using bytecode insertions to automatically serialize the objects without you having to write serialization code yourself. I can't speak to this being more or less efficient than standard or hand-coded serialization though.
    – Tom Dibble
    Feb 5, 2016 at 14:53
6

Hazelcast has been a nightmare for me. I was able to get it "working" in a clustered Websphere environment. I use the term "working" loosely. First, all of Hazelcast's documentation is out of date and only shows examples using deprecated method calls. Trying to use the new code without comments in the Javadocs and no examples in the documentation is very hard. Also, the J2EE container code simply does not work at this point because it does not support XA transactions in Websphere. An error is thrown calling code that follows their only J2EE example explicitly(it does look like Milestone 3.0 is addressing this). I had to forget about joining Hazelcast to a J2EE transaction. It does seem Hazelcast is definitely geared to a non EJB/Non-J2EE container environment. Making calls to Hazelcast.getAllInstances() fails to retain any information about Hazelcast's state when switching from one enterprise java bean to another. That forces me to create a new Hazelcast instance just to run calls that give me access to my data. That causes many Hazelcast Instances to start up on the same JVM. Also,retrieving data from Hazelcast is not fast. I tried retrieving data using both the Native Client and directly as a member of the cluster. I stored 51 lists, each containing only 625 objects in Hazelcast. I could not perform a query directly on a list and did not want to store a map just to get access to that feature (SQL operations can be performed on a map). It took about a half second to retrieve each list of 625 objects because Hazelcast Serializes the entire list and sends it over the wire rather than just giving me the delta (what has changed). Another thing, I had to switch to a TCPIP configuration and explicitly list the ip addresses of the servers I wanted to be in the cluster. The default Multicast configuration did not work and from the group discussions in google, other people are experiencing that difficulty as well. To sum up; I did eventually get 8 machines communicating in a cluster through many hours of torturous programmatic configuration and trial and error (the documentation will be little help) but when I did, I still had no control over the number of instances and partitions being created on each JVM due to the half finished nature of Hazelcast for EJB/J2EE and it was VERY SLOW. I implemented a real use case in the unemployment insurance application I work on and the code was much faster making direct calls to the database. It would have been cool if Hazelcast worked as advertised because I really did not want to use a separate service to implement what I am trying to do. I have used MongoDB extensively so I may skip the whole in memory cache and just serialize my objects as documents in a separate repository.

1
  • Did you compare that to the hazelcast "elastic memcached" configuration? hazelcast.org/use-cases/caching Interested to know how storing documents compares to native interface.
    – elwarren
    Mar 5, 2014 at 23:05
4

One advantage of Ehcache is that it is backed by a company (Terracotta) that does extensive performance, failover, and platform testing in a large performance lab. Terracotta provides support, indemnity, etc. For many companies, that sort of thing is important.

I have not used Hazelcast but I've heard that it is easy to use and that it works. I haven't heard anything with respect to scalability or performance of Hazelcast vs Terracotta/Ehcache but given the amount of scalability and failover testing that Terracotta does, it's hard for me to imagine that Hazelcast would be competitive in a production deployment. But I presume it would work fine for smaller uses.

[Bias: I'm a former employee of Terracotta.]

0
0

Developers describe Ehcache as "Java's Most Widely-Used Cache". Ehcache is an open-source, standards-based cache for boosting performance, offloading your database, and simplifying scalability. It's the most widely-used Java-based cache because it's robust, proven, and full-featured. Ehcache scales from in-process, with one or more nodes, all the way to mixed in-process/out-of-process configurations with terabyte-sized caches. On the other hand, Hazelcast is detailed as "Clustering and highly scalable data distribution platform for Java". With its various distributed data structures, distributed caching capabilities, elastic nature, memcache support, integration with Spring and Hibernate and more importantly with so many happy users, Hazelcast is feature-rich, enterprise-ready and developer-friendly in-memory data grid solution.

Ehcache and Hazelcast are primarily classified as "Cache" and "In-Memory Databases" tools respectively.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.