Clustering EHCACHE With ColdFusion - Step by Step
Posted by Mike Brunt at 3:41 PM
8 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.
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.