Dec 14 2010

Clustering EHCACHE With ColdFusion - Step by Step

Posted by Mike Brunt at 3:41 PM
14 comments
- Categories: Web Servers | DataBase | Default | Caching | ColdFusion | JRun-J2EE

 

Effective caching is one of the most cost-effective ways to improve performance, the likes of FaceBook, Twitter, Google and MySpace use distributed, redundant caches to support huge amounts of traffic.  This capability is now easily available to us in the ColdFusion world with the integration of EHCACHE into ColdFusion 9 and 9.0.1.

In concert with the good people at EHCACHE we have been evolving a good way to use distributed-clustered caching with ColdFusion and this work continues.  Through CFUNITED and cf.Objective we evolved a demonstration showing a ColdFusion application under load in an uncached and cached mode with EHCACHE in a clustered-distributed, out-of-process mode.  One important point that we observed is that if EHCACHE is out of process (that is not running in the same JVM as ColdFusion) and if EHCACHE then becomes unavailable, ColdFusion immediately hangs with nothing in any of the logs.  For this reason, we strongly advise that if EHCACHE will be used out of process, it is very important that it is set up with a minimum of two EHCHACHE instances set up in a clustered-distributed mode, which is exactly what we have done.  We are working with EHCACHE to test a new version, with ColdFusion, which should get us around this CF hanging issue, more information on that soon.

We just released a video showing the test we evolved to demonstrate clustered-distributed caching with ColdFusion and EHCACHE and this blog post will put more detail to the video which is located here.  These are the parts needed to make clustered-distributed caching work.

COLDFUSION:

ColdFusion Standard 9.0.1: Installed in {drive}:\ColdFusion9\lib (ehcache.xml is where all the settings are).

ColdFusion Enterprise Multiple Instance 9.0.1: Installed in {drive}:\JRun4\servers\{instance}\cfusion.ear\cfusion.war\WEB-INF\cfusion\lib (ehcache.xml is where all the settings are).

ehcache.jar, ehcache-web.jar, ehcache.xml

EHCACHE:

The basic needs are as shown in the ColdFusion details above and this what you have after installing ColdFusion.  In order to enable clustered-distributed caching in ColdFusion we need to add another jar file - 

ehcache-terracotta-2.0.0.jar into the same directory, so them we have...

ehcache.jar, ehcache-terracotta-2.0.0.jar, ehcache-web.jar, ehcache.xml

In the ehcache.xml file we enter/edit the following; the two IP Addresses and ports are pointing to the clustered instances on each server and with multiple ColdFusion instances we need this in each ehcache.xml file...

      

      

         maxElementsInMemory="10000"

         eternal="false"

         timeToIdleSeconds="86400"

         timeToLiveSeconds="86400"

         overflowToDisk="false"

         diskSpoolBufferSizeMB="30"

         maxElementsOnDisk="10000000"

         diskPersistent="false"

         diskExpiryThreadIntervalSeconds="3600"

         memoryStoreEvictionPolicy="LRU"

clearOnFlush="true">

         

On the two servers we install Terraccotta (on a Windows server here {drive}:\etc\terracotta-3.2.1) in the {drive}:\etc\terracotta-3.2.1\ehcache\ehcache.xml for each server we enter/edit the following code...  

 

         maxElementsInMemory="500"

         eternal="false"

         timeToIdleSeconds="300"

         timeToLiveSeconds="600"

         overflowToDisk="false"

         diskPersistent="false"

         diskExpiryThreadIntervalSeconds="1"

         transactionalMode="xa">

      

  

We also make sure the following is in the {drive}:\etc\terracotta-3.2.1\ehcache\ehcache.xml file (server 1) (server 2).

We also edit the {drive}\etc\terracotta-3.2.1\bin\config.xml file on both servers as follows...

  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-5.xsd">

  

  

     9510

     9520

     terracotta/demo-server/server-data

     terracotta/demo-server/server-logs

     terracotta/demo-server/server-statistics

     9510

     9520

     terracotta/demo-server/server-data

     terracotta/demo-server/server-logs

     terracotta/demo-server/server-statistics

networked-active-passive

5

  

We created a simple batch file to start the clustered-distributed cache (this is from server 2)...

@echo off

cd \etc\terracotta-3.2.1\bin

start "" start-tc-server.bat -n Cache2 -f .\config.xml

Once the first instance starts up and if all goes OK we will see this message in the terminal (note the "ACTIVE-COORDINATOR" status)...

2010-12-13 15:09:15,281 INFO - Terracotta 3.2.1, as of 20100302-130324 (Revision

 14673 by cruise@su10mo5 from 3.2)

2010-12-13 15:09:16,984 INFO - Configuration loaded from the file at 'C:\etc\ter

racotta-3.2.1\bin\.\config.xml'.

2010-12-13 15:09:17,609 INFO - Log file: 'C:\etc\terracotta-3.2.1\bin\.\terracot

ta\demo-server\server-logs\terracotta-server.log'.

2010-12-13 15:09:21,484 INFO - Available Max Runtime Memory: 494MB

2010-12-13 15:09:26,781 INFO - JMX Server started. Available at URL[service:jmx:

jmxmp://0.0.0.0:9520]

2010-12-13 15:09:38,625 INFO - Becoming State[ ACTIVE-COORDINATOR ]

2010-12-13 15:09:38,750 INFO - Terracotta Server instance has started up as ACTIVE node on 0.0.0.0:9510 successfully, and is now ready for work.

Next we start up EHCACHE on a second server (note Moved to State[ PASSIVE-STANDBY ])...

2010-12-13 15:14:30,421 INFO - Terracotta 3.2.1, as of 20100302-130324 (Revision

 14673 by cruise@su10mo5 from 3.2)

2010-12-13 15:14:37,421 INFO - Configuration loaded from the file at 'C:\etc\ter

racotta-3.2.1\bin\.\config.xml'.

2010-12-13 15:14:40,453 INFO - Log file: 'C:\etc\terracotta-3.2.1\bin\.\terracot

ta\demo-server\server-logs\terracotta-server.log'.

2010-12-13 15:14:47,843 INFO - Available Max Runtime Memory: 494MB

2010-12-13 15:14:56,250 INFO - JMX Server started. Available at URL[service:jmx:

jmxmp://0.0.0.0:9520]

2010-12-13 15:15:12,500 INFO - NodeID[192.168.1.15:9510] joined the cluster

2010-12-13 15:15:12,515 INFO - Moved to State[ PASSIVE-UNINITIALIZED ]

2010-12-13 15:15:12,781 INFO - Moved to State[ PASSIVE-STANDBY ]

So we now have two EHCACHE external instances which are clustered, distributed and replicating in an active/passive mode.


 

Comments

Mike Brunt

Mike Brunt wrote on 12/18/10 5:31 PM

My apologies for the malformed configuration file extracts above, I will find a way to put good examples here.
Aaron West

Aaron West wrote on 12/22/10 3:26 PM

Thanks for posting this Mike. It seems mostly straightforward, with the exception of some tasks / configuration changes that aren't clear due to the formatting in the blog post. But, if you clear that up this will be a great resource for folks trying to do out of process caching.
ColbyA

ColbyA wrote on 01/12/11 4:29 PM

Something like the code below could be useful for making sure you don't lock up your server with the " block until connectivity is restored" behavior of Ehcache in CF9:

//Run cacheGet in a seperate thread in case it blocks (e.g. terracotta cluster down)
THREAD name="cacheThread" cacheKey=cacheKey {
Thread.cachedObject = cacheGet(cacheKey);
}
threadJoin("cacheThread", 1500);

if (cacheThread.status == 'RUNNING' || cacheThread.status == 'NOT_STARTED') {
threadTerminate("cacheThread");
}

if (IsDefined("cacheThread.cachedObject") ) {
return cacheThread.cachedObject;
}

//not in cache, create/fetch object
pakhot

pakhot wrote on 01/19/11 9:57 AM

thanks for sharing this post, i am going to bookmark this share with my fellows
Custom flag

Custom flag wrote on 07/12/11 3:04 AM

ohh man this is awesome post.i think they should usebanner to get more flow in look.
you know this is great working by the writer.The writer has done a great job in speniding his time in
research about this article. can i subscribe all his posts ?
I am really happy to read this. i was searching this from last two months and atlast i got it. hurrah..!!
superdry uk

superdry uk wrote on 11/18/11 6:13 PM

Every superdry sale fans convinced superdry will be next huge designer. The colors of superdry uk are just amazing because they are universally flattering! It is a great alternative for people who are tired of buying out the entire superdry outlet line and are finished shopping at Our Superdry uk sale store.
Cold Fusion

Cold Fusion wrote on 03/07/12 2:00 PM

Cold Fusion is a great program, i don't know what else to say.
mutuelle obligatoire

mutuelle obligatoire wrote on 04/12/13 12:38 PM

Encore merci. J'ai vraiment apprecié de lire cette article. Bonne journée
afaghc

afaghc wrote on 10/21/13 9:15 AM

Good!Your blog ended up being quality when i feel as though mcdougal offers comprehensive knowledge on this area. Developments within bio-acceleration technology get resulted in the design of condensed sports activities shirts in which reduce muscle exhaustion of sportsmen along with boost muscles functionality. Inside cheap nike football boots football planet, developments inside http://www.cleatsboots.com boots in the last several years have the entire world by simply surprise Nike Hypervenom .These kinds of soccer footwear would also provide steel studs or tacks killed straight into the crooks to boost terrain grip which can be eye-catching, light-weight along with able to attaining a number of feats Nike HyperVenom Phantom although providing maximum speed, comfort and ease, grasp, control and also defense. To top it all http://www.sellmercurial.com , amazing promotional initiatives as well as recognition by simply professional football superstars add to the nonsense involving shoes or boots. The usage of the right http://www.crmercurial.com spikes according to the terrain how the sport is going to be played is really a key factor to stop blistering and also accidents that could be severe.Little league people should arranged cr nike mercurial an illustration and make use of the best kind of little league cleats as well as the suppliers need to advise your client for the far better technique football cleats. The boots have got nike mercurial vapor 9 directionally placed blades that increase cutting and invite for rapid modifications involving direction, and also secondary foot http://www.nikeacc.com grip which offers additional feet away electrical power.
chaussure foot mercurial

chaussure foot mercurial wrote on 10/28/13 2:21 AM

Ce blog contient des articles merveilleux .
f50 chaussure de foot

f50 chaussure de foot wrote on 10/28/13 5:31 AM

great blog,thanks for your revealing so competent write-up.
darrendemers12

darrendemers12 wrote on 11/20/13 2:30 AM

Wonderful subject and fair ... you simply have to do more study to come to be many more specific. Yet it's not that bad, it's amazing
http://www.lesbonscasinos.com/
http://www.leveedefonds-casino.com/
http://www.platinumplay-casino.com/
http://www.whitelablecasino.com/
http://www.gambling-casino-game.com/
sparxx rx

sparxx rx wrote on 10/16/14 8:52 AM

All of our products come in a discreet package so that no one will even know what is on your front doorstep.

Write your comment



(it will not be displayed)



Leave this field empty: