6. In-Memory Data Grid
Evolution of distributed caches
Clustered by nature
Scalability (with cost)
– Horizontal scalability
– Design for elasticity
High Availability
– No Single Point of Failure
– Redundancy + Load Balance
Querying
Task Execution (Map/Reduce)
8. For What
Sharing data (session, app state)
Toolkit for clustering
Performance (caching, in-memory processing)
Scalability
Database on cloud
10. Cache vs. Data Grid
JSR 107 - Temporary Caching for the Java Platform
–
–
–
–
–
Basic interaction(read, write, expiry)
Transactions with JTA compatibility
Listener
Persistence: write-through, write-behind
Annotations
JSR 347 - Data Grids for the Java Platform
–
–
–
–
–
–
–
–
Asynchronous, non-blocking API
Distributed code execution and map/reduce API
Group API for co-location
Annotations (CDI)
Eventually Consistent API
Querying
Configuration
javax.datagrid.*
12. Infinispan
Distributed In-memory key/value Data Grid/ Cache
org.infinispan.Cache Interface
Distributed as Library and Server (from 5.3)
High availability
Elasticity
Manageable
– RHQ, JON
Open source
– Apache v2 License
DefaultCacheManager manager = new DefaultCacheManager();
// Cache<Integer, Ticket> cache = manager.getCache();
Cache<Integer, Ticket> cache = manager.getCache(“myCache”);
13. Architecture: Library
Infinispan as Library - Standalone
Infinispan
App
JVM
JCP-107 Style Cache
just cache with advantages: expiry, j2ee transaction
14. Architecture: (Clustered) Library
Infinispan as Library - Clustered
Infinispan
App
Cluster
JVM
Infinispan
Easy deployment
More features
Richer APIs
Programmatic/
Declarative
configuration
– Extendable/
embeddable
– Faster (API call)
–
–
–
–
App
JVM
Infinispan
Use as library
App
JVM
Application doesn’t know it’s on cluster
15. Architecture: Server
Infinispan as Server - Clustered
Use as server
Infinispan
JVM
App
App
Good Isolation
Infinispan
– App doesn’t
affect cluster
Cluster
JVM
Infinispan
App
– Protocols: Memc
ached, REST, Hot
Rod, WebSocket
JVM
Data tier shared
by multi-apps
– Non-java client:
C++, .NET, Ruby,
Python, Java
Remote or embedded? – amount of data, etcs
16. Architecture: Durability
An Example of Durability
Durability
Infinispan
JVM
Cluster
Infinispan
JVM
Infinispan
JVM
Infinispan
JVM
Cluster
persistence
– By replication
– By persistence
– By replication to
other cluster
(topology aware)
23. Distributed Execution
Executes codes on distributed nodes
Through a standard JDK ExecutorService interface
Use DistributedCallable extends
java.util.concurrent.Callable
24. Key Features: Map/Reduce
Based on Distributed Execution Framework
Mapper, Reducer, Collator, MapReduceTask
public interface Mapper<KIn, VIn, KOut, VOut> extends Serializable {
void map(KIn key, VIn value, Collector<KOut, VOut> collector);
}
public interface Reducer<KOut, VOut> extends Serializable {
VOut reduce(KOut reducedKey, Iterator<VOut> iter);
}
public interface Callator<KOut, VOut, R> {
R collate(Map<KOut, VOut>);
}
28. Case Study: Session Clustering
Store session information into cache
in Spring MVC Interceptor
29. Case Study: Session Clustering
Store session information into cache
in Spring Security Filter
-
SecurityContextRepository를 구현한
CacheSecurityContextRepository 작성
loadContext, saveContext를 오버라이드하여
인피니스팬 사용
Spring cache abstraction 사용