JBoss Cache
Cache
A place to temporarily store data that is expensive or difficult to compute or retrieve. Caches should be fast to access.
May or may not exhibit “enterprise” features such as transactions
JBoss Cache
Cluster
A collection of homogenous services, grouped such that characteristics of high availability and load balancing can be achieved.
Distributed cache?
Similar to a cache, except that stores could be distributed across multiple physical or virtual machines.
May or may not mirror contents.
JBoss Cache
Why cache?
Benefits:
Removal of data retrieval or calculation bottlenecks
Concerns/pitfalls:
Cached data validity
Cluster-wide coherence
“Over-caching”
Don’t cache unless you know you have a bottleneck
“Measure. Don’t guess.”
JBoss Cache
Why cluster?
HA - Fault tolerance is critical
24/7 world
Global user base
SLAs
Scaling horizontally
Need to deal with predicted and unpredicted spikes
Planned increase of capacity
Coherence of state and performance of maintaining
JBoss CacheData grids and clustering
Hardware is cheap.
Both CPUs and memory
Grid computing is becoming easier to implement
Compute grid frameworks like GridGain
Clouds - Amazon EC2
Work stealing patterns
Data availability becomes important
Data retrieval bottleneck impact increases drastically with grid size
Cost of keeping caches coherent increases with cluster size
Not as much as data retrieval bottlenecks though
JBoss CacheJBoss Cache
Simple API for caching data
Either local, replicated or distributed
Support for eviction of unused elements
Cache loading/storing to disk to free up memory
Chaining caches, remote caches using TcpCacheLoader
Support for JTA transactions
Listeners and notifications, JMX manageability
Multiple locking schemes (optimistic,pessimistic)
JBoss Cache
Flavors Core cache - for caching simple objects, primitives
POJO cache - Optimised for caching large and complex objects with relationships
Object relationships maintained, even after replication or persistence
Fine-grained replication
Minimal API
JBoss Cache Searchable cache
Adds efficient querying capabilities to the core cache
−
Uses Lucene to maintain indexes
−
In-memory distributed object database, anyone?
JBoss CacheWho uses JBoss Cache?
JBoss Application Server - Clustering HTTP and EJB sessions, JPA entities Hibernate - entity caching SEAM - clustering contexts and caching JSF generated content JBoss Portal Lucene/Hibernate Search - cluster-wide indexes
JBoss CacheBenchmarks
Just because we’re a distributed cache doesn’t mean we cannot be used as a standalone in-memory cache as well. Tracking JSR 107 - the JCACHE spec. Fast − Highly concurrent − Rich eviction and cacheloading strategies − Queryable −
JBoss Cache
JBoss Cache
Architecture
Implementing JBoss/Tomcat Fine-
Configuration
Http Session Replication
• Http session clustering with Tomcat
Configuration
JBoss Cache
Goal
What is JBoss Cache?
TreeCache
TreeCacheAOP requires JBossAOP
Stores and replicates values from a treestructure (hence the name)Each value is associated with a path and key
Stores and replicates values from a treestructure (hence the name)Each value is associated with a path and key
JBoss Cache
What is JBoss Cache? Uses JGroups as underlying transport stack
Available as stand-alone or
embeddable (MBean)
TreeCacheAOP requires JbossAOP runtime Can be used with other app servers as well Can manage caching and replication on full Java objects (POJOs) Object oriented cache
JBoss Cache
.
JBoss Cache Key Feature Local and Replication mode
Synchronous and Asychronous
Fine grained field-level replication using TreeCacheAOP component.
No need to declare POJO Serializable
JBoss Cache
• Local and Replication mode
Each node has a name and
Can be navigated recursively from node to
node or using a fully qualified name (/a/d/g)
Multiple roots per cache allowed
Locking Isolation level per node
TreeCache Architecture
JBoss Cache
Aop is a modular way of defining and
applying cross-cutting concerns
• Current release 1.1
• Definition: Advice, Aspect, Jointpoint,
Interceptor, and Pointcut
• Define a rich set of metadata
language as pointcut
• Supports dynamic Aop
JBoss Aop Features
JBoss Cache
Use JBossAop’s dynamic aop feature
• A subclass of TreeCache all the features of TreeCache
• Eviction policy and replication pojo
TreeCacheAop
JBoss Cache
Fine-grained field-level caching with
POJO style
Object graph
Polymorphism
Inheritance
Automatic Collections class support
List, Map, and Set
A proxy is generated for the Collections
.
TreeCacheAop
JBoss CacheTreeCacheAop API
Plain cache API
put(FQN name, Object key, Object value)
Object get(FQN name, Object key)
remove(FQN name, Object key)
JBoss Cache TreeCacheAop Mapping
JBoss Cache Configuration
• Object relationship management has replySync-service.xml
reference counting
Object instance that is referenced more than once is moved to an internal area.
JBoss Cache Replication Granularity Level:
New Http Session Replication Goal
Session
Replication is on per http sessionobject. It is a blob of hash map.
Replication mode - Synchronous or Asynchronous
User can define whether a getAttribute is dirty or not.
Provide persistency and memory usage control
JBoss CacheImplemented using TreeCache API
Pojo pojo = (Pojo)session.getAttribute(“pojo”);
Pojo pojo = (Pojo)session.getAttribute(“pojo”);
pojo.setName(“Ben”);
pojo.setName(“Ben”);
Session.setAttribute(“pojo”, pojo); // Need to do this manually and replicates the session