views:

793

answers:

1

Hello

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

+2  A: 

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.

Steffen Opel
That was it. There was a port collision but no WARN or ERROR on logs (and I have everything set to level ALL). Thanks a lot!!!
cherouvim