2. Why
are
you
(and
I)
here?
•
•
•
•
+
Happy marriage since CF9 (2009)
= Open-Source, De-Facto Java Caching API
+ +
Seamless, Powerful Distributed In-Memory Caching
with Free Open-Source Software
=
= Open-Source, Distributed In-Memory Store
In-Memory Caching = Not new, but still making the difference every day!
+ Seamless Integration!
Simple Config Change
Why re-inventing the wheel?
3. Terracotta
(Inc.
and
products)
at
a
Glance
• Founded
in
2003
• Lead
open-‐source
maintainer
for:
• Terracotta
Commercial
Offerings:
BigMemory Go/Max,
Universal
Messaging
• Deployed
by
80%
of
the
Global
1000
• Over
2.5
million
enterprise
deployments
in
over
190
countries
• Used
by
2.1
million
developers
• Acquired
by
Software
AG
in
2011
• Software
AG
Government
Solutions
serves
U.S.
Federal
Government
9. The
De-‐Facto
Java
“Caching”
API
• Open-source (more at www.ehcache.org)
• Current in 2.x: Ehcache 2.10.1
• Ehcache 3.x (complete overall with lots of improvements !)
• Full JSR 107 compliant (Java Caching specification)
• Seamless integration with many popular frameworks/applications:
Tomcat WebSphere
weblogic
16. Ehcache Standalone:
Simple
and
quick
fix
Web
services
EhcacheEhcacheEhcache
Limitations:
§ Limited Memory Storage (JVM Heap only)
§ Larger Heap = Unpredictable Latencies (GC pauses)
§ Standalone = Duplicate cache data = more DB / disks
calls
Advantages:
§ Easy to implement
§ Highly concurrent
§ Linear performance gains
§ Extend storage to disk
17. Ehcache Replication:
Improved
caching
but
some
caveats
Web
services
EhcacheEhcacheEhcache
Ehcache
replication
Ehcache
replication
Advantages:
§ Replications on ALL
inserts/updates/deletes
§ Add once, request many
§ More efficient
Same ehcache limitations +
§ Complex (Jgroup, RMI, MultiCasting)
§ Possible Cache Discrepencies
§ Bootstrapping issues
18. Terracotta
Distributed
Ehcache:
High
Scalability
Caching
Web
services
EhcacheEhcacheEhcache
Advantages:
§ Simple to setup (1 config change in ehcache)
§ Unlimited in-memory storage capacity
(offheap)
§ Completely open-source (4.3 and up)
TerracottaOpen-Source(4.3)
Advantages (cont’d):
§ Flexible consistencies
§ High Availability
§ Monitoring options
20. Terracotta
4.x
Open
Source
Offering
/
Architecture
Active
Server
SCALE OUT
1 JVM – X gb Heap
CF App Server
1 JVM – X gb Heap 1 JVM – X gb Heap
Ehcache 2.x
CF App Server CF App Server
Unlimited
In-Memory
Storage
(Offheap)
Passive
Server
CF internals
Active
replication
Unlimited
In-Memory
Storage
(Offheap)
Ehcache 2.x
CF internals
Ehcache 2.x
CF internals
Heap
TC internals
2 GB
e.g.
100 GB
2 GB
e.g.
100 GB
tcp sockets / nio / unicast
Heap
TC internals
SCALEUP
2
1
3
21. Easy
scalability:
New
clients
can
access
all
cached
data
Active
Server
Unlimited
In-Memory
Storage
(Offheap)
Passive
Server
Active
replication
Unlimited
In-Memory
Storage
(Offheap)
Heap
TC internals
2 GB
e.g.
100 GB
2 GB
e.g.
100 GB
tcp sockets / nio / unicast
Heap
TC internals
SCALEUP
1 JVM – X gb Heap
CF App Server
1 JVM – X gb Heap 1 JVM – X gb Heap
Ehcache
CF App Server CF App Server
CF internals
Ehcache
CF internals
Ehcache
CF internals
1 JVM – X gb Heap
CF App Server
Ehcache
CF internals
1 JVM – X gb Heap
CF App Server
Ehcache
CF internals
22. Powerful
H/A
=
Automatic
failover
/
no
cache
data
loss
Active
Server
Unlimited
In-Memory
Storage
(Offheap)
New Active
Server
Active
replication
Unlimited
In-Memory
Storage
(Offheap)
Heap
TC internals
2 GB
e.g.
100 GB
2 GB
e.g.
100 GB
tcp sockets / nio / unicast
Heap
TC internals
SCALEUP
1 JVM – X gb Heap
CF App Server
1 JVM – X gb Heap 1 JVM – X gb Heap
Ehcache
CF App Server CF App Server
CF internals
Ehcache
CF internals
Ehcache
CF internals
1 JVM – X gb Heap
CF App Server
Ehcache
CF internals
1 JVM – X gb Heap
CF App Server
Ehcache
CF internals
23. Tiered Storage
JVM Managed
Memory
New
Tiered
Storage
Approach
with
Unlimited
Storage
into
Terracotta
(up
to
RAM
available
of
course!)
Local Disk Store
(Re-startable)
Heap
Store
Direct Access
RAM Store
a.k.a Offheap
2,000,000+
1,000,000
100,000
2
1,000
10,000+
Speed (TPS)
1,000s
Size (GB)
External Data Source
(e.g., Database)
24. Offheap with
JAVA
=
Unrestricted
In-‐Memory
Storage
• Standard
Java
• Proven
TBs
scale
capacity
• Not
managed
by
the
JVM
=
No
Garbage
Collections
=
Predictable
latencies
• No
specialized
appliance
needed
25. Seamless
configuration
on
same
ehcache.xml
<ehcache>
<terracottaConfigurl=“server1:9510,server2:9510"/>
<cache name=“UserPreferencesCache”
timeToIdleSeconds=”300”
maxEntriesLocalHeap=“1000” />
<cache name=”ShoppingCartCache”
timeToLiveSeconds=”6000”
maxEntriesLocalHeap=“1000”>
maxEntriesInCache=“10000000”>
<terracotta />
</cache>
</ehcache>
25
Ehcache 2.x Example Configuration
Amount of objects
allowed in
Terracotta for that
Cache region
Terracotta url
Enable
Terracotta for
that cache
26. Example Configuration
Flexible
data
access
consistency
Strongly
Consistent
Fully
Transactional
Eventually
Consistent
More Consistency More Performance
<cache name=”UserPreferencesCache"
maxElementsInMemory="10000"
timeToLiveSeconds="300”>
<terracotta consistency=”eventual"/>
</cache>
<cache name=”ShoppingCartCache"
maxElementsInMemory=”5000"
timeToIdleSeconds=”6000”>
<terracotta consistency=”strong"/>
</cache>
Example Configuration
27. Some
extra
“Terracotta”
pointers...
1. No
limitations
on
what
you
can
store
in
cache,
BUT
Cached
Keys
/
Values
MUST
be
“Serializable”
(implement
java.io.Serializable)
2. New
Terracotta
jar
needed
+
Ehcache JAR
must
match
Terracotta
version.
So
new
Jars
needed
in
CF:
1. ehcache-‐2.10.1.jar
2. terracotta-‐toolkit-‐runtime-‐4.3.1.jar
3. Cache
by
reference
(standalone
Ehcache)
/
Cache
by
serialization
(Terracotta)
4. For
resiliency
to
clients-‐terracotta
disconnections,
there’s
nonstop
mode.
But
Ehcache client
must
specify
appropriate
“behavior”
(noop,
exception,
localReads)
5. Explicit
locks
apply
to
the
full
“Terracotta
cache
cluster”
(Read
/
Write
Locks)
1. Useful
for
special
data
consistency
needs
6. Ehcache +
Terracotta
=
Full
compliant
XA
resource
(XA
transactions)
7. CAS
operations
apply
to
the
full
“Terracotta
cache
cluster”
1. Cache.putIfAbsent(Element
element),
Cache.replace(Element
oldOne,
Element
newOne)
Key (Serializable) Value Serializable (byte[])
28. Monitoring
and
Management:
Simple
REST
API
Terracotta Server Array
App Server
Heap
Ehcache
/BigMemory
Cache Runtime
Endpoint
JMX bridge TSA Rest Agent
App Server
Heap
Ehcache
/BigMemory
CF App Server
Heap
Ehcache
Tcp
9510
Tcp
JMX
9520
Http/REST
9540
CURL
Monitoring
App
http/rest
http://www.terracotta.org/documentation/4.1/tms/tms-rest-api
29. A
monitoring
example:
Terracotta
NewRelic Plugin
Terracotta Server Array
App Server
Heap
Ehcache
/BigMemory
Cache Runtime
Endpoint
JMX bridge TSA Rest Agent
App Server
Heap
Ehcache
/BigMemory
CF App Server
Heap
Ehcache
Tcp
9510
Tcp
JMX
9520
Http/REST
9540
CURL
NewRelic
Plugin
http/rest
NewRelic Cloud
Rest HTML
Https
REST
Http
HTML
Proxy
https://github.com/Terracotta-OSS/terracotta-newrelic-plugin
31. Terracotta
Initial
Setup
in
just
a
few
steps…
1. Download
Terracotta
OSS
(latest
4.3.1
-‐-‐ terracotta-‐4.3.1.tar.gz)
1. http://www.terracotta.org/downloads/open-‐source/catalog
2. Extract
to
location
of
choice
3. Ensure
JAVA_HOME
is
set
4. Navigate
to
<TERRACOTTA_INSTALL>/server/bin
5. Start
with
default
single
node
config by
executing:
1. start-‐tc-‐server.sh (or
.bat)
6. Terracotta
process
is
now
accessible
at
IP:9510
Note:
if
setting
up
Terracotta
in
active/mirror
setup,
tc-‐config.xml must
be
created
and
referenced
at
startup:
• start-‐tc-‐server.sh (or
.bat)
-‐f
<path-‐to-‐config>/tc-‐config.xml –n
<server-‐name-‐to-‐start>
32. Connecting
CF
11
to
Terracotta
in
just
a
few
steps
1. Copy
Ehcache +
Terracotta
libs
to
<CF_HOME>/cfusion/lib
1. <TERRACOTTA_INSTALL>/apis/ehcache/lib/ehcache-‐2.10.1.jar
2. <TERRACOTTA_INSTALL>/apis/toolkit/lib/terracotta-‐toolkit-‐runtime-‐4.3.1.jar
2. Add
terracotta-‐specifics
configurations
in
CF
ehcache configs:
1. <CF_HOME>/cfusion/lib/ehcache.xml
2. <CF_HOME>/cfusion/lib/auth-‐ehcache.xml
3. Restart
CF
4. Notice
Terracotta
connection
in
CF
logs
33. All
these
features
are
now
cached
on
Terracotta!
• CF
Authentication:
• auth-‐ehcache.xml:
authcache,
authtokenmappingcache
• Internal
Caching
(CF
templates,
component
paths)
• <cfcache> -‐ Cache
fragments
of
html
• <cfquery>
-‐ Cache
DB
calls
• <cfquery name="myPortfolio"
cachedwithin=#createTimeSpan(
0,
1,
0,
0
)#>
• ORM
with
Ehcache 2nd level
caching:
Caching Hibernate
queries
• Entityload('BlogPost',{},{cacheable=true})
• CF
Cache
functions:
Direct
Ehcache calls
• CacheGet /
CachePut /
CacheRemove /
CacheGetAllIds
• CacheGetMetadata
• CacheGetProperties /
CacheSetProperties
• Custom
CF
JAVA
components
using
Ehcache library
directly
+
+
34. And now just wait to see your CF website
absorb the next usage spikes!!