advanced caching techniques with ehcache, big memory, terracotta, and coldfusion

Download Advanced caching techniques with ehcache, big memory, terracotta, and coldfusion

Post on 26-Aug-2014




1 download

Embed Size (px)




  • Rob Brooks-Bilson | @styggiti | cf.Objective() 2014
  • About Me Sr. Director at Amkor Technology Involved with ColdFusion for 18 years Author of the OReillys books: Programming ColdFusion Programming ColdFusion MX Adobe Community Professional for ColdFusion Food Geek Bed Jumper Photographer
  • More ColdFusion Goodness
  • Agenda What Well Cover And What We Wont What is caching? Whats 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
  • Legal Mumbo Jumbo: The Disclaimer Much of what youre 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 youre about to see
  • Ehcache Implementation : Caching Evolution Core cache Ehcache 1.6 9.0 Page caching Fragment caching Caching objects and data ORM caching Improved Hibernate plug-in, management, XA transactions, write-behind, bulk load, Snap-in support for distributed caching, via easy upgrade to Enterprise Ehcache Ehcache 2.0 9.1 New and enhanced functions: cacheGetSession, cacheGetMetadata Support for new configuration properties User-defined caches copyOnRead &copyOnWrite, Explicit locking API, Nonstop Cache, Cache Search New consistency modes: Strong and Eventual Automatic Resource Control Ehcache 2.5.1 10.0 Application level caching Enhanced query cache Six New functions Cache region attribute in all functions
  • 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
  • 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
  • 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
  • Caching Architectures Out-of-Process (L2 Cache) Operates in its own process, outside of the application servers 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
  • 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
  • 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
  • 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)
  • 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
  • Cache Replication
  • 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
  • Potential Replication Gotchas Synchronous vs. Asynchronous delivery Asynchronous replication is the fastest method Because its 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 dont care about inconsistent data across cache nodes
  • Replicated Cache Config Per Node Step 1 Stop your ColdFusion Server /lib/{servername}/ehcache.xml Uncomment:
  • Replicated Cache Config Per Node Step 2 Replicated Cache Its Really That Easy! *Dont forget to restart ColdFusion
  • BigMemory Go
  • 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!
  • 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 its 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
  • GC Tuning Need I Say More?
  • 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 doesnt have to search for garbage because we already know when a cache item needs to be thrown out (cache expiry)
  • Tiered Memory Store and BigMemory Architecture
  • Upgrade Ehcache and Install BigMemory Go BigMemory Go requires a newer version of Ehcache Adobe doesnt officially support upgrading. Do so at your own risk! Theres currently a bug you need to be aware of in CF 10 (as of updater 11): 3339491: After upgrading Ehcache, ehcache.xml is ignored. Youll n