问题
We are trying to use Hazelcast as distributed cache in our application. Here is our config:
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.7.xsd" xmlns="http://www.hazelcast.com/schema/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<group>
<name>sample_dev</name>
<password>dev@123</password>
</group>
<management-center enabled="false">http://localhost:8080/mancenter</management-center>
<properties>
<property name="hazelcast.logging.type">slf4j</property>
<property name="hazelcast.socket.bind.any">false</property>
</properties>
<serialization>
<serializers>
<global-serializer override-java-serialization="true">com.prasanth.common.KryoSerializer</global-serializer>
</serializers>
</serialization>
<network>
<join>
<multicast enabled="false"/>
<tcp-ip enabled="true">
<member-list>
<member>127.0.0.1:5701</member>
</member-list>
</tcp-ip>
</join>
<interfaces enabled="false">
<interface>192.168.3.*</interface>
</interfaces>
</network>
<map name="com.prasanth.cache.CachedAsset">
<in-memory-format>BINARY</in-memory-format>
<backup-count>1</backup-count>
<async-backup-count>1</async-backup-count>
<time-to-live-seconds>86400</time-to-live-seconds>
<max-idle-seconds>1200</max-idle-seconds>
<eviction-policy>LRU</eviction-policy>
<max-size policy="PER_NODE">4500</max-size>
<merge-policy>com.hazelcast.map.merge.LatestUpdateMapMergePolicy</merge-policy>
<!--<read-backup-data>true</read-backup-data>-->
<near-cache>
<in-memory-format>OBJECT</in-memory-format>
<cache-local-entries>true</cache-local-entries>
<time-to-live-seconds>86400</time-to-live-seconds>
<max-idle-seconds>1200</max-idle-seconds>
<invalidate-on-change>true</invalidate-on-change>
</near-cache>
</map>
</hazelcast>
From the documentation, I can see that every time call is made to Hazelcast, de-serialization is involved. Hence to optmize the calls, we have used Kryo as default serializer and implemented near-cache. We have to put objects of size 500KB each into map and we can have around 400-500 such active objects in the memory. We use cache very often in the application.
Earlier we were using EhCache with JGroups configured for cache implementations. The operations were pretty faster. But when we tried to use Hazelcast, I see some considerable difference in operating time. I can unserstand that Hazelcast is more than a cache implementation. But just wondering why the operations became very slower when compared to EhCache(with jgroups). Is there some thing wrong with the configuration we have made? Please suggest!
Also please note that I am testing this on a single node machine.
回答1:
The main difference is, that EHcache ends up being a local cache to your application whereas Hazelcast is still a distributed cache. The Nearcache, however, should bring a big performance win if - and only if - you use the same objects multiple times. The Nearcache is not a replication mechanism but a simple additional (local) caching layer.
In 3.8 Continuous Query Caching is opensource and this will automatically update local caches whenever an update comes in. The other option is to look into ReplicatedMap which will replicate information to every single node in the cluster (but only cluster members whereas CQC also works on clients).
回答2:
All distributed caching solutions will incur a cost with regards to serialization. Since you want the data to live outside the JVM there is no way around it.
Ehcache with replication using JGroups was probably hiding this cost by doing the replication asynchronously but you had effectively zero consistency guarantees in this setup.
Distributed solutions, whether using Ehcache or Hazelcast, will offer consistency guarantees. But this adds to the cost due to the consistency enforcement.
来源:https://stackoverflow.com/questions/42764205/hazelcast-performing-slower