ehcache在同一主机上的2个实例之间自动发现(通过多播) [英] ehcache auto-discovery (via multicast) between 2 instances on the same host

查看:335
本文介绍了ehcache在同一主机上的2个实例之间自动发现(通过多播)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一台主机上运行了2个tomcat实例。每个实例都运行相同的Web应用程序,该应用程序尝试通过RMI复制来传递一些ehcache缓存。我在ehcache中使用自动发现配置,因此我不必明确定义哪些是主机,哪些是我想要复制的高速缓存。 ehcache实例无法找到彼此并进行通信:

I run 2 tomcat instances on the same host. Each instance runs the same web application which tries to communicate some ehcache caches via RMI replication. I use the autodiscovery configuration in ehcache so I don't have to explicitly define which are the hosts and which are the caches I want to replicate. The ehcache instances do not manage to find each other and communicate:

DEBUG (RMIBootstrapCacheLoader.java:211) - cache peers: []
DEBUG (RMIBootstrapCacheLoader.java:133) - Empty list of cache peers for cache org.hibernate.cache.UpdateTimestampsCache. No cache peer to bootstrap from.

如果我尝试相同的事情,但这次在单独的主机(盒子)上运行每个tomcat实例然后一切都像魅力一样。

If I try the same thing but this time run each tomcat instance on a separate host (box) then everything works like a charm.

我做错了什么,或者当实例在同一主机上时,不能通过多播进行自动发现?

Am I doing something wrong, or isn't autodiscovery via multicast possible when the instances are on the same host?

我的配置使用 RMI分布式缓存文档中提供的默认值:

My configuration uses the defaults presented in the RMI Distributed Caching documentation:

<cacheManagerPeerProviderFactory
        class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
        properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, 
                    multicastGroupPort=4446, timeToLive=32"/>
<cacheManagerPeerListenerFactory
        class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
        properties="port=40001, socketTimeoutMillis=2000"/>

在我要复制的每个缓存区域内,我有:

And inside each cache region I want to replicate I have:

<cacheEventListenerFactory
        class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" 
        properties="asynchronousReplicationIntervalMillis=500 " />
<bootstrapCacheLoaderFactory 
        class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" />

谢谢

推荐答案


我做错了什么,或者当实例在同一个
主机上时,不是
通过组播自动发现

Am I doing something wrong, or isn't autodiscovery via multicast possible when the instances are on the same host?

虽然我对ehcache并不熟悉,但我认为这是可能的,事实上他们提供的例子至少可以做类似的事情(每个主机有多个节点,但只有一个实例):请参阅完整示例部分您提到的caching.htmlrel =nofollow noreferrer> RMI分布式缓存文档。

While I'm not really familiar with ehcache I'd think this to be possible and they are in fact providing an example doing something similar at least (multiple nodes per host, though one instance only): see section Full Example in the RMI Distributed Caching documentation you mentioned.

通常您无法打开相同的TCP端口(此处为40001)但是每个主机不止一次,它被绑定到第一个分配它的应用程序/服务(确实存在像 TCP Por例如,在Windows上共享,但你必须具体说明这一点。)

Usually you cannot open the same TCP port (40001 here) more than once per host though, it is bound to the first application/service allocating it (there do exist things like TCP Port Sharing on Windows for example, but you'd have to specifically account for that).

因此,如果你真的使用相同的默认配置,尝试分配TCP端口40001的第二个Tomcat实例将无法执行此操作。当然,这应该在Tomcat日志的早期某个地方表现出来,你已经看过了吗?

Consequently, if you are really using their identical default configurations, the second Tomcat instance trying to allocate TCP port 40001 will fail to do so. Of course, this should manifest itself somewhere earlier in the Tomcat logs, have you had a thorough look already?

为一个Tomcat实例使用另一个空闲端口应该可以解决问题;你可以在 ehcache中看到这一点。上面提到的完整示例的.xml :端口号从40001逐个增加到每个节点40006。

Just using another free port for one Tomcat instance should solve the issue; you can see this in action within the ehcache.xml's for the Full Example mentioned above: the port number is increased one by one from 40001 up to 40006 per node.

这篇关于ehcache在同一主机上的2个实例之间自动发现(通过多播)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆