ARender HMI : Synchronizing caches using ehcache

Context

Both the HMI server (presentation) and the Rendition server uses ehcache to handle currently opened documents.

The default configuration performs well for stand-alone environments, but as soon as clustering is concerned, some extra thinking is required.

For the HMI Server, 3 strategies can be considered :

  • user per-session affinity : using J2EE features, it is granted that each user request is sent to the same HMI server node. This may be the simplest way to build the solution, with the well-known drawback of non high-availability : if the node crashes, the opened documents are lost and the users must re-open them.
  • using reversible IDs : Arender 2.1 brought the reversible IDs API, which allows ARender to re-identify the document source (upstream) using the volatile Id used within ARender. The cache is still used for performance reasons, but when the document expires, ARender can refill the document cache seamlessly. This performs very well when the document can be identified by another Id (for example, an URL, or an ECM unique id). And it has the side-effect of allowing easy clustering, because each HMI node can identify the document without any kind of synchronization or session affinity.
  • cache synchronization : the last mechanism is to use ehcache features to synchronize HMI caches.

Synchronizing remote caches

ehcache calls cache sync ‘Replication’. See here for further details.

For each HMI deployed war (or ear), we must configure the ehcache.xml file (in the WEB-INF/classes folder) :

  • Add the synchronization features :

These lines shall be added under the ‘ehcache’ markup :

<cacheManagerPeerListenerFactory class=”net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory”

properties=”hostName=localhost,port=40000,socketTimeoutMillis=120000″ propertySeparator=”,”/>

<cacheManagerPeerProviderFactory class=”net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory”

properties=”peerDiscovery=manual,rmiUrls=//target-host:40000/com.arondor.viewer.common.javarmi.ClientDocumentService.documentAccessorMap”

propertySeparator=”,” />

The ‘target-host‘ is to be replaced by the other HMI’s IP address.The port ‘40000‘ is used here ; there is no default port for ehcache, but 40000 may be a good choice because it is rarely used…

  • Adding synchronization to each cache

Now the nodes know how to talk to each other, but sync must also be setup per-cache.

Here we will only setup the cache for the ‘documentAccessorMap’, which contains all currently opened documents.

<cache name=”com.arondor.viewer.common.javarmi.ClientDocumentService.documentAccessorMap”

maxElementsInMemory=”65536″

timeToIdleSeconds=”3600″

timeToLiveSeconds=”86400″

eternal=”false”

overflowToDisk=”false”

memoryStoreEvictionPolicy=”FIFO”>

        <cacheEventListenerFactory class=”net.sf.ehcache.distribution.RMICacheReplicatorFactory” properties=”replicateAsynchronously=false”/>

</cache>

 

Share This:

Leave a Reply

Your email address will not be published. Required fields are marked *