Tagged: clustering Toggle Comment Threads | Keyboard Shortcuts

  • Subinkrishna Gopi 4:51 pm on June 23, 2010 Permalink |
    Tags: cache, clustering, distributed cache, ehcache,   

    Distributed Ehcache – RMI replication (configuration) 

    I am having some fun with Ehcache esp. in distributed caching. Distributed caching is really important in a clustered environment. Read more about distributed caching here – http://ehcache.org/documentation/distributed_caching.html.

    I have downloaded Ehcache 2.1 from http://sourceforge.net/projects/ehcache/files/ (ehcache-2.1.0-distribution.tar.gz, 48 mb approx.) which contains Ehcache core and the Terracotta libraries. Once if we have these libraries, we can configure the caches, peers and listeners. I have created a basic cache – MyCache – and my configuration file looks like this:

    <?xml version="1.0" encoding="UTF-8"?>
    
    <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:noNamespaceSchemaLocation="ehcache.xsd"
             updateCheck="true" monitoring="autodetect"
             dynamicConfig="true" >
    
        <diskStore path="java.io.tmpdir"/>
        <cacheManagerEventListenerFactory class="" properties=""/>
    
        <defaultCache
               maxElementsInMemory="0"
               eternal="false"
               timeToIdleSeconds="1200"
               timeToLiveSeconds="1200">
        </defaultCache>
    
            <!-- For RMI replication (Setting the peer provider factory) -->
    	<cacheManagerPeerProviderFactory
    		class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
    		properties="peerDiscovery=manual, rmiUrls=//remoteHostIpAddress:40000/MyCache"
    		propertySeparator="," />
    
    	<!-- For RMI replication (Setting the peer listener factory) -->
    	<cacheManagerPeerListenerFactory
                class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
                properties="hostName=localMachineIpAddress, port=40000, socketTimeoutMillis=120000"
                propertySeparator=","/>
    
    	<cache name="MyCache"
    		maxElementsInMemory="1000"
    		eternal="false"
    		overflowToDisk="true"
    		diskSpoolBufferSizeMB="20"
    		timeToLiveSeconds="3000"
    		timeToIdleSeconds="3000"
    		memoryStoreEvictionPolicy="LFU">
    
    		<!-- Cache event listener -->
    		<cacheEventListenerFactory
    			class="subin.cache.listener.factory.CacheEventListenerFactoryImpl"
    			properties="" />
    
    		<!-- RMI replication listener -->
    		<cacheEventListenerFactory
            	class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
            	properties="replicateAsynchronously=true,
    		         replicatePuts=true,
    		         replicatePutsViaCopy=true,
    		         replicateUpdates=true,
    		         replicateUpdatesViaCopy=true,
    		         replicateRemovals=true" />
    
    		<!-- RMI Cache bootstrap -->
    		<bootstrapCacheLoaderFactory
    			class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"
    			properties="bootstrapAsynchronously=true, maximumChunkSizeBytes=5000000"
    			propertySeparator="," />
    
    	</cache>
    
    </ehcache>
    

    Initializing the CacheManager & Accessing the cache

    // Testing the cache creation in ver 2.1
    CacheManager manager = new CacheManager("/path/to/config/file.xml");
    
    // Get the instance of "MyCache"
    Cache myCache = manager.getCache("MyCache");
    
    // Add an element to "MyCache". Its preferred to have both key and value
    // serializable
    Element aCacheElement = new Element(key, value);
    myCache.put(aCacheElement);
    

    Useful Links

    RMI replication: http://ehcache.org/documentation/distributed_caching_with_rmi.html
    Configuration: http://ehcache.org/documentation/configuration.html

     
  • Subinkrishna Gopi 10:10 am on February 5, 2009 Permalink |
    Tags: clustering, farming, , , , , ,   

    Farming service & JBoss 5 

    jbosscorp_logo

    First of all, I would like to thank whitelassiblog for bringing this to my notice. You can see his comment here on my post.

    As I never did any JBoss clustering in my life, I searched (in fact “Googled“) for it. And I found a small & nice article on it.

    What is the farm service ?

    That is hot-deploying the application archive file (e.g., the EAR, WAR or SAR file) in the all/farm/ directory of any of the cluster members, will cause the application to be automatically duplicated across all nodes in the same cluster.

    If node joins the cluster later, it will pull in all farm deployed applications in the cluster and deploy them locally at start-up time. If you delete the application from one of the running cluster server node’s farm/ folder, the application will be undeployed locally and then removed from all other cluster server nodes farm folder (triggers undeployment.) You should manually delete the application from the farm folder of any server node not currently connected to the cluster.

    Read this article here: http://www.mastertheboss.com/en/jboss-application-server/146-jboss-farming-service.html

    But in JBoss 5 this feature is not available.

    Unfortunately this replacement for farming is not ready available for AS 5.0.0.GA. The Farm Service’s function of replicating deployment archives between file systems will not be maintained.

    At the moment the easiest solution to deploy a JBoss application on JBoss AS 5 is creating a script which copies the file on all the “deploy” folder of your Nodes.

    Hope this helps.

     
    • whitelassiblog 4:06 pm on February 5, 2009 Permalink

      Thanks for the credit. Very kind of you ๐Ÿ™‚
      Farm service is a very cool feature that jboss has. It makes me sad why they removed it. Moreover, with no replacement, it is likely to break production grade applications who want to attain cluster wide fault tolerance and migrate to Jboss 5.

    • Subinkrishna G 4:16 pm on February 5, 2009 Permalink

      Hmm. After reading the mastertheboss.com article and your comment even I think so. Anyways thanks again.

    • whitelassiblog 8:08 pm on May 21, 2009 Permalink

      A quick update. The farming service has been restored in JBOSS 5.1.0 CR1.

    • Subinkrishna G 8:24 am on May 31, 2009 Permalink

      Thank you for this update.

c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel