Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ehcache auto-discovery (via multicast) between 2 instances on the same host

Tags:

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.

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?

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" />

thanks

like image 442
cherouvim Avatar asked Aug 21 '09 18:08

cherouvim


1 Answers

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

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.

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).

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?

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.

like image 123
Steffen Opel Avatar answered Oct 12 '22 21:10

Steffen Opel