2. About Me
ď§ Sr. Director at Amkor Technology
ď§ Involved with ColdFusion for 18
years
ď§ Author of the OâReillyâs books:
Programming ColdFusion
Programming ColdFusion MX
ď§ Adobe Community Professional
for ColdFusion
ď§ Food Geek
ď§ Bed Jumper
ď§ Photographer
4. Agenda
What Weâll Cover And What We WontâŚ
ď§ What is caching?
ď§ Whatâs Ehcache?
ď§ Caching tags and functions
ď§ Any questions from Dan Wilson
ď§ Disclaimer
ď§ Caching Evolution in ColdFusion
ď§ Scale Up vs. Scale Out
ď§ Caching Architecture Review
ď§ Replicated Cache
ď§ BigMemory Go
ď§ Distributed Cache
ď§ Terracotta Management Console
5. Legal Mumbo Jumbo: The Disclaimer
ď§ Much of what youâre about to see makes use of third-party libraries and
applications
ď§ Some of it requires you to upgrade versions of libraries that ship with
ColdFusion
ď§ There are bugs
ď§ There are workarounds
ď§ There is no official support from Adobe for much of what youâre about to
see
7. Ehcache Implementation : Caching Evolution
ď§ Fast restartability
ď§ Terracotta Management
Console
Ehcache 2.6.6
11.0
ď§ Bug fixes
ď§ cacheRemove now takes an
array for ID
Ehcache 2.8.2
Current Version
8. Scale Up vs. Scale Out
ScaleUp
Scale Out
What about cost?
⢠Hardware
⢠Data center space
⢠Power
⢠Redundancy
⢠Software Licensing*
⢠Operations & Sysadmin
How does this change in the cloud?
More CPU
More RAM
More Machines
9. Caching Architectures
In-Process (L1 Cache)
ď§ Operates in the same process
(JVM) as the application server
ď§ Limited scalability for 32-bit
systems
ď§ Must consider possible number of
cache variants
ď§ Max JVM heap size
ď§ Can fail-over to disk storage
ď§ Fast
ď§ Data/object serialization is not
required for memory based in-process
cache
JVM
ColdFusion
Cache
In-Process Cache
10. Caching Architectures
Out-of-Process (L2 Cache)
ď§ Operates in its own process,
outside of the application
serverâs JVM
ď§ Highly scalable on both 32-bit
and 64-bit platforms
ď§ Scale out
ď§ Utilize spare memory throughout
the network
ď§ Slower than in-process caching
ď§ Data/objects must be
serialized/deserialized
JVM
ColdFusion
Cache
JVM
Cache
Out-of-Process Cache
10
11. Technology
Ehcache
ď§ Java caching API
ď§ In-process
ď§ Open Source /
Commercial
ď§ Built-in to
ColdFusion
BigMemory Go
ď§ Off-heap memory
storage for the JVM
ď§ Stand Alone
ď§ Terracotta
Management
Console
ď§ Commercial
Terracotta
ď§ Distributed in-
memory caching
array
ď§ Out-of-process
ď§ Open Source no
longer supported
as of version 3.7.7
(Pairs with
Ehcache 2.6.8)
ď§ Commercial: Part
of BigMemory
Max
BigMemory Max
ď§ Off-heap memory
storage for the JVM
ď§ Distributed
ď§ Terracotta
Management
Console
ď§ Commercial
12. Caching Architecture
Ehcache can be configured to run:
ď§ Local: In-process (Ehcache [+
BigMemory Go])
ď§ Replicated: In-process (Ehcache [+
BigMemory Go])
ď§ Distributed: In-process and Out-of-
process (Ehcache + BigMemory Max)
ColdFusion
Server
Ehcache
ColdFusion
Server
Ehcache
JVM
JVM
ColdFusion
Server
Ehcache
ColdFusion
Server
Ehcache
JVM
JVM
RMI, JMS,
JGroups,
Terracotta
In-Process Cache
Replication
JVM
ColdFusion
Cache
In-Process Cache
JVM
ColdFusion
Cache
JVM
Cache
Out-of-Process Cache
13. To Help Avoid ConfusionâŚ
ď§ Terracotta recently retired the Terracotta
Server and discontinued the free versions of
BigMemory Go and BigMemory Max
ď§ To avoid confusion, keep this in mind:
ď§ Ehcache = In-Process Java Caching API â Comes
built-in with ColdFusion
ď§ BigMemory Go = Enterprise Ehcache + Off-Heap
Memory Storage for the JVM on a single server -
Commercial (90 day trial)
ď§ BigMemory Max = Enterprise Ehcache + Off-Heap
Memory Storage for the JVM + Distributed In-
Memory Caching via the Terracotta Server Array â
Commercial (90 day trial)
14. Still Confused?
BigMemory Go BigMemory Max
Distributed in-memory data store No (standalone JVM) Yes
In-memory capacity Unlimited (limit based on license) Unlimited (limit based on license)
Number of BigMemory mirrored stripes supported N/A Unlimited (limit based on license)
Number of application clients supported N/A Unlimited (limit based on license)
Fast search Yes Yes
Configurable data consistency guarantees N/A Yes
Terracotta Management Console⢠Yes Yes
Fast Restartable Store⢠Yes Yes
BigMemory-Hadoop Connector support Yes
In-process off-heap storage Yes Yes
Advanced security (authentication/authorization) N/A Yes
Enterprise support Yes Yes
16. Scalability: Cache Replication (Clustering)
ď§ All supported cache types can be
replicated
ď§ Each CF server in the cluster
maintains its own in-process cache
ď§ Data is replicated among L1 caches
ď§ Replication via RMI, JMS, JGroups
or Terracotta
ď§ Synchronous or asynchronous
ď§ Still hit JVM GC issues/limits
ď§ Simple configuration via
ehcache.xml file
ColdFusion
Server
Ehcache
ColdFusion
Server
Ehcache
JVM
JVM
ColdFusion
Server
Ehcache
ColdFusion
Server
Ehcache
JVM
JVM
RMI, JMS,
JGroups,
Terracotta
In-Process Cache
Replication
20
17. Potential Replication Gotchas
ď§ Synchronous vs. Asynchronous delivery
ď§ Asynchronous replication is the fastest method
ď§ Because itâs asynchronous the caller returns immediately
ď§ Messages are placed in a queue and batched via RMI as they are processed
ď§ Potential for data inconsistency exists
ď§ Synchronous
ď§ Removes potential for data inconsistency
ď§ Slower operation as caller waits for replication to complete before returning
ď§ Time To Idle
ď§ Inconsistent with replicated caching
ď§ Data on some nodes will live longer than on others due to cache usage patterns
ď§ Do not use unless you donât care about inconsistent data across cache nodes
18. Replicated Cache Config Per Node â Step 1
ď§ Stop your ColdFusion Server
ď§ /lib/{servername}/ehcache.xml
ď§ Uncomment:
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=automatic,
multicastGroupAddress=230.0.0.1,
multicastGroupPort=4446, timeToLive=1"
propertySeparator=","
/>
22. Problems with Application Scalability on the JVM
ď§ Slow Applications lead to caching
ď§ Large caches lead to latency from Garbage
Collection pauses
ď§ GC pauses necessitate JVM tuning
ď§ Application usage and data grows
ď§ More caching is needed
ď§ More JVM tuning is needed
ď§ As cache size increases, more heap memory is used
ď§ More heap memory usage results in unpredictable
and longer GC pauses
ď§ Eventually you hit a wall
ď§ Add more JVMs
ď§ Increased deployment and management
complexity
ď§ Tune! Tune! Tune!
23. The Problem with Memory and the JVM
ď§ RAM is outpacing the JVM
ď§ 32GB is now fairly standard on most servers
ď§ Amazon EC2 allows for up to 68.4GB
ď§ Most of that memory is used inefficiently if itâs used at all
ď§ Cached data ages differently than standard business objects
which can confuse the Java garbage collector
ď§ The cache expiration determines when the data becomes garbage
ď§ And then there's tuningâŚ
25. BigMemory to the Rescue
ď§ Cache huge amounts of data with no GC pauses
ď§ Easy to implement
ď§ Pure Java implementation
ď§ Works with all JVMs
ď§ Works with both standalone and distributed caches
ď§ No application code changes necessary to implement
ď§ Avoid GC because of pauses
ď§ Off heap store on direct memory buffers
ď§ Use all available memory on your server (if you want to)
ď§ 1 million puts per second
ď§ 1 line of config to use it
ď§ JVM doesnât have to search for garbage because we already know when a cache item
needs to be thrown out (cache expiry)
27. Upgrade Ehcache and Install BigMemory Go
ď§ BigMemory Go requires a newer
version of Ehcache
ď§ Adobe doesnât officially support
upgrading. Do so at your own risk!
ď§ Thereâs currently a bug you need to
be aware of in CF 10 (as of updater
11):
ď§ 3339491: After upgrading Ehcache,
ehcache.xml is ignored. Youâll need to use
auth-ehcache.xml for now. (Marked as Fixed,
but not yet deployed in a hotfix)
60
28. Upgrade Ehcache and Install Big Memory: Step 1
ď§ Stop your ColdFusion server
ď§ Rename the following files in your servername/lib directory:
ď§ ehcache-core-2.5.1.jar ď ehcache-core-2.5.1.jar.original
ď§ slf4j-api-1.5.6.jar ď slf4j-api-1.5.6.jar.original
ď§ slf4j-log4j12-1.5.6.jar ď slf4j-log4j12-1.5.6.jar.old
29. Upgrade Ehcache and Install Big Memory: Step 2
ď§ Download BigMemory Trial (It will give you Max even if you select Go):
ď§ http://terracotta.org/products/bigmemorygo
ď§ Extract the following files into your servername/lib directory:
From /apis/ehcache/lib
ehcache-ee-<version>.jar
slf4j-api-<version>.jar
From /common/lib
bigmemory-<version>.jar
ď§ Copy the terracotta-license.key file you received by email after downloading
BigMemory into your servername/lib directory
30. Upgrade Ehcache and Install Big Memory: Step 3
ď§ Download the Slf4j version bundle that matches the version in your
BigMemory download from http://www.slf4j.org/dist/
ď§ Extract the slf4j-log4j12-<version>.jar into your servername/lib directory
31. Upgrade Ehcache and Install Big Memory: Step 4
ehcache.xml (auth-cache.xml):
<cache name="sample-offheap-cache"
maxElementsInMemory="100000"
eternal="true"
memoryStoreEvictionPolicy="LRU"
overflowToOffHeap="true"
maxMemoryOffHeap="2G"/>
Start your ColdFusion server
JVM Config in ColdFusion Admin:
-XX:MaxDirectMemorySize=3G
Restart your ColdFusion server
36. Scalability: Distributed Caching (Commercial)
ď§ Commercial license
ď§ Runs out-of-process
ď§ Tiered caching
ď§ Hottest data in L1 (< 1 Îźs access)
ď§ Everything in L2 (< 2 ms access)
ď§ "Snap-in scale"
ď§ Works with single node Ehcache or
replicated Ehcache
ď§ Simple config via ehcache.xml
ď§ High data capacity: 2TB+
ď§ Highly available
Enterprise
Ehcache
Terracotta
Server
Array
Terracotta
Server Array
ColdFusion
Enterprise
Ehcache
ColdFusion
âŚ
Terracotta
Server
Array
Terracotta
Server Array
37. ⢠Stop your ColdFusion server
⢠Rename the following files in your
servername/lib directory:
ehcache-core-2.5.1.jar ď ehcache-core-
2.5.1.jar.original
slf4j-api-1.5.6.jar ď slf4j-api-1.5.6.jar.old
slf4j-log4j12-1.5.6.jar ď slf4j-log4j12-1.5.6.jar.old
⢠Add the following jar files:
From apis/ehcache/lib
ehcache-ee-<version>.jar
slf4j-api-<version>.jar
From apis/toolkit/lib
terracotta-toolkit-runtime-ee-<version>.jar
Ehcache
Terracotta
Server
ColdFusion
Ehcache
ColdFusion
âŚ
Distributed Cache Configuration: Step 1/3
39. Start ColdFusion
JVM Config in ColdFusion Admin:
-X:MaxDirectMemorySize=3G
Stop ColdFusion
Start the Terracotta server, then restart
ColdFusion
bin/start-tc-server.sh
bin/start-tc-server.bat
Ehcache
Terracotta
Server
ColdFusion
Ehcache
ColdFusion
âŚ
Distributed Cache Configuration: Step 3/3
40. Terracotta Gotchas
ď§ The Terracotta server must be running before you bring up your ColdFusion
server, otherwise your page request (that tries to do a cache operation) will
spin until the connection times out and an error is returned
ď§ Terracotta can only be used with ColdFusion Enterprise. Thereâs a bug if you
try to use it with the Developer Edition where ColdFusion will return an error
telling you itâs an Enterprise Only feature.
42. Installing the Terracotta Management Console
1. Ensure JAVA_HOME is set
2. Extract the BigMemory go files
3. Start the monitor server: /management-console/lib/start-tmc.bat
4. Configure ehcache (auth_cache.xml) and add monitoring line:
<managementRESTService enabled="true" bind="0.0.0.0:9888" />
5. Open the web browser to http://localhost:9889/tmc