谁用过Hazelcast?集群下性能跟ehcache 集群配置相比如何

bwzhang2015很懒,签名啥也没写
回答了问题:
楼主的源头理解的确如此,不过hazelcast在3.5的版本上做了很多的修改和提升。此外这样的基准测试最好参考hazelcast在github下的hazelcast-jmh工程,里面得到的数据(包括方式)要更准确一些。作为我个人,我在公司...
谁用过Hazelcast?集群下性能跟ehcache相比如何?(10台以上服务器的缓存共享模式)
回答了问题:
hz3.4中map-reduce能够提供大部分简单的处理,比起hadoop的笨重安装要方便很多
在网站下了一段实现CastMapR的代码(https://github.com/noctarius/castmaprd):发现一些包没有被引入,查看官方最新的接口文档(www.hazelcast.com ),没有查到相应的包,使用的是Hazelcast 3.1.3或3.1.5 后么有...
还可以输入5字
共 9 张,还能上传 9 张
[选择编程语言]
Apple Swift
Objective-C
JavaScript
Delphi/Pascal
Flash/ActionScript/Flex
WPF/SilverLight
Shell/批处理
设置备注名:
用户尚未登录,点击登录博客分类:
一般情况下WEB应用集群的会话复制都是通过容器实现的,shiro权限框架中可以定义SessionDAO直接将session持久化到缓存中,这样只需要对缓存做集群就可以代替session的复制。
实现思路
1、用SessionDAO将session保存到ehcache缓存
2、配置ehcache的jgroups集群复制,如果集群服务器比较多,可升级到缓存服务器
思路很简单,但实现过程遇到不少问题,现在把过程及配置文件记录下来,避免忘记。
第一步将SessionDAO保存到ehcache缓存,这个步骤很简单,也没出什么问题,按照网上的例子很容易,下面是配置文件主要片段:
&!-- 主要是为了注入SessionDAO --&
&bean id="sessionManager" class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager"&
&property name="sessionDAO" ref="sessionDAO"/&
&!-- SessionDAO用shiro提供的默认实现 --&
&bean id="sessionDAO" class="org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO"&
&!-- &property name="activeSessionsCacheName" value="shiro-activeSessionCache"/& --&
&property name="cacheManager" ref="shiroCacheManager" /&
&!-- 为了实现自己的用户权限 --&
&bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager"&
&property name="realm" ref="userRealm"/&
&property name="sessionManager" ref="sessionManager"/&
&!-- By default the servlet container sessions will be used.
Uncomment this line
to use shiro's native sessions (see the JavaDoc for more): --&
&!-- &property name="sessionMode" value="native"/& --&
&!-- 自定义的用户权限,这里也需要用缓存,避免从数据库加载权限 --&
&bean id="userRealm" class="cn.ys.security.UserRealm"&
&property name="cacheManager" ref="shiroCacheManager"/&
&property name="userService" ref="securityService" /&
&property name="credentialsMatcher" ref="credentialsMatcher"&&/property&
&!-- 与spring ehcache集成 --&
&bean id="shiroCacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager"&
&property name="cacheManager" ref="ehcache"/&
&property name="cacheManagerConfigFile" value="classpath:ehcache.xml"/&
第二步遇到很多问题,网上资料比较少,对jgroups又不熟,下面是配置文件及我遇到的问题:
ehcache.xml
&!-- 缓存同步jgroup配置 --&
&cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"
properties="file=jgroups_tcp.xml"
&diskStore path="java.io.tmpdir/ehcache"/&
&defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
maxElementsOnDisk=""
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
&cache name="shiro-activeSessionCache"
maxElementsInMemory="1000"
overflowToDisk="true"
timeToLiveSeconds="0"
timeToIdleSeconds="0"
diskPersistent="true"
diskExpiryThreadIntervalSeconds="600"&
&cacheEventListenerFactory
class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true,
replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=true" /&
&cache name="cn.ys.security.UserRealm.authorizationCache"
maxElementsInMemory="1000"
eternal="true"
overflowToDisk="true"&
&cacheEventListenerFactory
class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true,
replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=true" /&
&cache name="org.apache.shiro.realm.text.PropertiesRealm-0-accounts"
maxElementsInMemory="1000"
eternal="true"
overflowToDisk="true"&
&cacheEventListenerFactory
class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true,
replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=true" /&
jgroups_tcp.xml
&TCP bind_port="7800" bind_addr="localhost"
loopback="false"
recv_buf_size="${tcp.recv_buf_size:20M}"
send_buf_size="${tcp.send_buf_size:1M}"
discard_incompatible_packets="true"
max_bundle_size="2M"
max_bundle_timeout="30"
enable_bundling="true"
use_send_queues="true"
sock_conn_timeout="300"
timer_type="new"
timer.min_threads="4"
timer.max_threads="10"
timer.keep_alive_time="3000"
timer.queue_max_size="500"
thread_pool.enabled="true"
thread_pool.min_threads="1"
thread_pool.max_threads="10"
thread_pool.keep_alive_time="5000"
thread_pool.queue_enabled="false"
thread_pool.queue_max_size="100"
thread_pool.rejection_policy="discard"
oob_thread_pool.enabled="true"
oob_thread_pool.min_threads="1"
oob_thread_pool.max_threads="8"
oob_thread_pool.keep_alive_time="5000"
oob_thread_pool.queue_enabled="false"
oob_thread_pool.queue_max_size="100"
oob_thread_pool.rejection_policy="discard"
&TCPPING timeout="3000"
initial_hosts="localhost[7800]"
port_range="5"
num_initial_members="5"/&
min_interval="10000"
max_interval="30000"/&
&FD_SOCK/&
&FD timeout="3000" max_tries="3" /&
&VERIFY_SUSPECT timeout="1500"
&BARRIER /&
&pbcast.NAKACK use_mcast_xmit="false"
retransmit_timeout="300,600,00"
discard_delivered_msgs="true"/&
&pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000" max_bytes="400000"/&
&pbcast.GMS print_local_addr="true" join_timeout="5000" view_bundling="true"/&
在网上查找的例子jgroups版本可能比较老,ehcache中的例子也一样,有些属性新的jgroups已经不认了,如start_port已经改成了bind_port,另外新版本jgroups增加了bind_addr,这样就可以直接指定ip地址绑定了,不需要在jvm上增加ipv4参数。
配置jgroups的几个需要理解的地方
1、jgroups的TCP的端口是自动分配自动发现的,同一台服务器上的多个实例不需要都配置到initial_hosts中,一个IP在initial_hosts中只需要定义一次,端口与bind_port保持一致
2、port_range是用于端口自动分配和自动发现用的,例如bind_port值为7800,当同服务上的第一个实例启动是使用7800端口,第二个实现启动时使用的是7801,最多只到7804
3、max_bundle_size不要太小,例子上该值只有64K,结果有时会现在无法复制的情况
4、当实例关闭再启动时,jgroups会认为是另一个host,原来的host如果不设置超时会一直存在,所以要注意设置keep_alive_time
浏览 18254
cn.ys.security.ehcache.EhCacheManager是什么呢?可以直接使用Shiro提供的Manager:
&bean id="shiroCacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager"&
&property name="cacheManager" ref="ehcache"/&
&property name="cacheManagerConfigFile" value="classpath:ehcache.xml"/&
唉,我就想看看 这个sessionDAO在代码中是怎么用的,这个sessionDAO很多方法都是空,难道需要自己实现吗?我用的是apache shiro提供的org.apache.shiro.web.session.mgt.DefaultWebSessionManager,不需要自己写代码
浏览: 26601 次
来自: 武汉
&div class=&quote_title ...
cn.ys.security.ehcache.EhCacheM ...
&div class=&quote_title ...
唉,我就想看看 这个sessionDAO在代码中是怎么用的,这 ...
有源码吗?
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'谁用过Hazelcast?集群下性能跟ehcache相比如何-百谷歌博客分类:
Hazelcast是一个Java的开源分布式内存实现,它具有以下特性:
Distributed implementations of java.util.{Queue, Set, List, Map}02
Distributed implementation of java.util.concurrent.ExecutorService03
Distributed implementation of java.util.concurrency.locks.Lock04
Distributed Topic for publish/subscribe messaging05
Transaction support and J2EE container integration via JCA06
Distributed listeners and events07
Support for cluster info and membership events08
Dynamic HTTP session clustering09
Dynamic clustering10
Dynamic scaling to hundreds of servers11
Dynamic partitioning with backups12
Dynamic fail-over13
S include a single jar14
S thousands of operations per sec.15
S less than a MB16
S very nice to CPU and RAM
安装也非常方便:
Download hazelcast-version.zip from www.hazelcast.com2
Unzip hazelcast-version.zip file3
Add hazelcast.jar file into your classpath
要使用分布式的Map,只需要以下代码即可实现:
import com.hazelcast.core.H
import java.util.M
import java.util.C
Map&String, Customer& mapCustomers = Hazelcast.getMap("customers");
mapCustomers.put("1", new Customer("Joe", "Smith"));
mapCustomers.put("2", new Customer("Ali", "Selam"));
mapCustomers.put("3", new Customer("Avi", "Noyan"));
Collection&Customer& colCustomers = mapCustomers.values();
for (Customer customer : colCustomers) {
Hazelcast的官网上面有一个非常直观的视频:http://www.hazelcast.com/screencast.jsp,建议有兴趣的朋友花10分钟时间看看。
还有一份PDF可以参考:http://roma.javaday.it/javaday2010/sites/default/files/ClusteringHazelcast-javaday.pdf。
Hazelcast作为一款与ZooKeeper类似的开源实现,我在网上找了一篇相关的文章:http://blog.armstrongconsulting.com/?p=132 在这篇文章中有一段这样写道:
I had occasional hangs with Hazelcast 1.8.4 which caused me to switch to Zookeeper. As expected, Zookeeper was a lot harder to use than Hazelcast – you need Zookeeper installed on 3 servers. There’s no official java client, just some recipes and I found an implementation of Zookeeper locks called Cages on google code. For a java developer, Hazelcast is obviously way easier to use.
另外,在Hazelcast的官方文档中,提到了Hazelcast的集群机制:
If there is no existing node, then the node will be the first member of the cluster. If multicast is enabled then it will start a multicast listener so that it can respond to incoming join requests. Otherwise it will listen for join request coming via TCP/IP.
If there is an existing cluster already, then the oldest member in the cluster will receive the join request and check if the request is for the right group. If so, the oldest member in the cluster will start the join process.
In the join process, the oldest member will:
send the new member list to all members
tell members to sync data in order to balance the data load
Every member in the cluster has the same member list in the same order. First member is the oldest member so if the oldest member dies, second member in the list becomes the first member in the list and the new oldest member.
从这点可以看出,虽然Hazelcast没有所谓的“Master”,但是仍然有一个Leader节点(the oldest member),这个概念与ZooKeeper中的Leader类似,但是实现原理却完全不同。同时,Hazelcast中的数据是分布式的,每一个member持有部分数据和相应的backup数据,这点也与ZooKeeper不同。虽然Hazelcast应用便捷,但是要将其实际应用于生产环境,还是具有一定的风险的,这个需要大量的实际应用来验证。
是面向Java的缓存、集群及数据分发解决方案。最近,它的2.0版本发布了。作为新版本的一部分,该产品提供了商用企业版和免费的开源社区版。
其中,社区版在下发布,并托管于中。2.0版本包含了一个分布式备份功能,用以确保每个结点都能均匀地被所有其他结点备份。Hazelcast创始人Talip Ozturk告诉InfoQ说,“我相信我们的备份分发是一个全新的解决方案”。
采用分布式数据备份,结点在丢失时仅会对集群造成很小的影响。这点在内存中有大数据时尤为重要。
Hazelcast解决方案的工作原理是将差不多大小的数据分布到集群中的每个结点上。例如,在一个50个结点的结点集群中,每个结点存储20GB的基本数据以及20GB的备份数据。结点1数据会分成1/49大小的若干份,并由剩余49个结点中的每一个进行备份。如果结点1下线,那么任何迁移都不用就可以让集群保持均衡。随着新节点加入到系统中,Hazelcast会慢慢地将数据迁移到新结点来让所有结点上的数据保持均衡。
新版2.0中的其他特性包括:
并行IO,它将对内(In)和对外(Out)通信联合到单个线程中(在1.0版本中,每个成员会拥有对内和对外线程各一个,用作处理与其他使用NIO信道的成员进行通信)。
改善连接管理,Hazelcast在破损连接被宣布死亡之前会尝试进行修复。
为Queue、List、Set和Topic提供新的事件容器。
另外,企业版增加了堆外(off-heap)存储(注:Hazelcast中将其称作弹性内存(Elastic Memory))、附加的安全能力和一个原生的C#客户端。
出于安全考虑,该产品包含了一份基于的实现,用作验证集群成员及客户端,并对客户端操作进行访问控制检查。访问控制可根据终端点委托或代码进行管理,而安全性可以通过使用XML或API启用和配置。
弹性内存本质上是一种解决过长GC中断时间(pause time)的变通方案。是一个例外,它消除了所有的GC中断。借助它,商业JVM中的垃圾收集中断时间会随内置堆的大小明显增长。弹性内存可以减少JVM堆的大小,从而降低垃圾收集的中断时间。关于这点,Ozturk给出了一个大致的建议:
如果你的每个JVM都拥有10GB以上的数据,或者有超过1KB的值对,那么可以使用弹性内存。而如果你的每个JVM数据在4GB左右,或者少于a KB,那么我们不建议使用弹性内存。
Hazelcast的弹性内存采用直接字节缓存区(direct byte buffer)实现,其中每个缓存区分为若干块,每块默认大小为1KB。这个特性类似于Oracle的、Terracotta的以及一些其他提供商的缓冲方案。
企业版许可模型基于每个订阅和结点,相关价格信息可通过查询。另外,Hazelcast还为社区版提供了两个不同级别的支持,参考价格公布在了上。
浏览: 303571 次
来自: 上海
很实用,一直关注
你好,最近在解决redis数据同步的问题,找到了tedis,但 ...
楼主接下来要考虑页面静态化与细节上面的东西了
jovinlee 写道
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'技术成就梦想
发表了新话题:
http://backlogtool.com/git-guide/cn/intro/intro1_1.html 具体看链接,图文并茂。
发表了新话题:
在开源中国里面找了半天,没有发现什么好的向导插件,最后还是自己百度Google去搜了下,发现这个插件还不错。
插件的官网:http://www.jquery-steps.com/
在讨论区提问:
目前大家Android应用真机测试都需要采购哪些机型? 想节省成本,不知道采购哪些机型能覆盖大部分的测试?
发表了新话题:
请问移动WEB游戏开发有什么好的教材?谢谢
发表了新话题:
做单一的app产品,一般需要的团队规模如何?
发表了新话题:
https://modao.io 个人觉得还不错,国人开发的;线上编辑,能直接编辑界面或者使用自己做的草图,可实现联动,支持打包网页和APK格式。 追求简单快速原型设计的话可以考虑用下。
发表了新话题:
JAVA GC的原理和机制,这个关于javaGC的系列讲的很好很到位: http://www.importnew.com/13504.html JAVA 线程模型,做了几年服务器开发了,竟然对这块都不了解,看了这个文章才有所有掌握: http://blog.csdn.n...
在讨论区提问:
谁用过Hazelcast?集群下性能跟ehcache相比如何?(10台以上服务器的缓存共享模式)
发表了新话题:
我在公司干了很多年,手头上的项目和产品比较多;不知道辞职要多久?现在想早点离开,到时候如果公司不放人,不给离职证明,不结清工资什么的,要怎么弄? 各位都是咋处理的?
发表了新话题:
主要是担心服务器宕机硬盘损坏之类的,Git上的数据会不会丢失掉? 另外还想知道具体是如何做的?
还可以输入5字
共 9 张,还能上传 9 张
[选择编程语言]
Apple Swift
Objective-C
JavaScript
Delphi/Pascal
Flash/ActionScript/Flex
WPF/SilverLight
Shell/批处理
设置备注名:
用户尚未登录,点击登录

我要回帖

更多关于 ehcache3 集群 的文章

 

随机推荐