我们正在尝试在应用程序中使用Hazelcast作为分布式缓存。下面是我们的配置:
<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>从文档中,我可以看到,每次调用Hazelcast时,都涉及反序列化。因此,为了优化调用,我们使用Kryo作为默认序列化程序,并实现了近缓存。我们必须将大小为500 in的对象放入地图中,并且在内存中可以有大约400-500个这样的活动对象。我们在应用程序中经常使用缓存。
早些时候,我们使用EhCache和为缓存实现配置的JGroups。手术更快了。但是当我们尝试使用Hazelcast的时候,我发现在操作时间上有很大的不同。我可以指出,Hazelcast不仅仅是一个缓存实现。但是,我只是想知道为什么与EhCache(使用jgroup)相比,操作变得非常慢。我们所做的配置有什么问题吗?请给我建议!
另外,请注意,我正在一个节点的机器上测试这一点。
发布于 2017-03-13 13:43:54
主要的区别是,EHcache最终成为应用程序的本地缓存,而Hazelcast仍然是分布式缓存。然而,Nearcache如果--而且只有在--多次使用相同的对象时,才能带来很大的性能优势。Nearcache不是一个复制机制,而是一个简单的附加(本地)缓存层。
在3.8中,连续查询缓存是开源的,每当出现更新时,这将自动更新本地缓存。另一种选择是查看ReplicatedMap,它将信息复制到集群中的每个节点(但只有集群成员,而CQC也适用于客户端)。
发布于 2017-03-14 10:59:12
所有分布式缓存解决方案都将导致与序列化相关的成本。因为您希望数据驻留在JVM之外,所以没有办法绕过它。
使用JGroups进行复制的Ehcache可能通过异步执行复制来隐藏此成本,但在此设置中有效地保证了零一致性。
分布式解决方案,无论是使用Ehcache还是Hazelcast,都将提供一致性保证。但是,由于一致性的执行,这增加了成本。
https://stackoverflow.com/questions/42764205
复制相似问题