infinispan data grid platform
DESCRIPTION
JBUG 2013 10th Anniversary ConferenceTRANSCRIPT
![Page 1: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/1.jpg)
Data Grid Platform
인피니스팬 소개와 사용 사례
전 재 홍 / Jaehong Cheon
9 Nov 2013
![Page 2: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/2.jpg)
![Page 3: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/3.jpg)
Agenda
Data Grid
Infinispan
Case Study
References
![Page 4: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/4.jpg)
Data Grid
![Page 5: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/5.jpg)
Data Grid
Distributed Cache with persistence – Performance Boost
– Dynamic provisioning
– Fast access to data (in memory) - optionally write-through
– Elasticity
– Fault tolerance
Data Grid – Evolution of distributed caches
– Well-known pattern to boost data access performance and scalability
– Clustered by nature
![Page 6: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/6.jpg)
Cache vs. Data Grid
JSR 107 - Temporary Caching for the Java Platform – read, write, expiry, write-through, distributed-manner
– JBoss Cache
JSR 347 - Data Grids for the Java Platform – query, consistency, map-reducing standard way
– Infinispan
![Page 7: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/7.jpg)
Infinispan
![Page 8: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/8.jpg)
Infinispan
Distributed In-memory key/value Data Grid/ Cache
org.infinispan.Cache Interface
Distributed as Library and Server (from 5.3)
High availability
Elastic
Manageable
Open source
DefaultCacheManager manager = new DefaultCacheManager(); // Cache<Integer, Ticket> cache = manager.getCache(); Cache<Integer, Ticket> cache = manager.getCache(“myCache”);
![Page 9: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/9.jpg)
Architecture: Library
JCP-107 Style Cache just cache with advantages: expiry, j2ee transaction
Library Mode - standalone
Infinispan
JVM
App
![Page 10: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/10.jpg)
Architecture: Library (Clustered)
Library Mode - clustered
Cluster
Infinispan
JVM
App
Infinispan
JVM
App
Infinispan
JVM
App
Application doesn’t know it’s on cluster
Use as library – More features
– Richer APIs
– Programmatic/ Declarative configuration
– Extendable/ embeddable
– Faster (API call)
![Page 11: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/11.jpg)
Architecture: Server
Use as server – Remote
Memcached, REST, Hot Rod, WebSocket
– Data tier shared by multi-apps
– App doesn’t affect cluster
– Non-java clients
C++, .NET, Ruby, Python, Java
Server Mode - clustered
Cluster
Infinispan
JVM
Infinispan
JVM
Infinispan
JVM
App
App
App
![Page 12: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/12.jpg)
Architecture: Durability
Durability – By replication
– By persistence
– By replication to other cluster (topology aware)
Durability
Cluster
Infinispan
JVM
Infinispan
JVM
Cluster
Infinispan
JVM
Infinispan
JVM
persistence
![Page 13: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/13.jpg)
Infinispan: Key Features
Transactions
Persistence
Querying
Map/Reduce
![Page 14: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/14.jpg)
Clustering
Peer-to-Peer – No central master, no single point of failure, no single bottle
neck
JGroups – Reliable multicast communication library, nodes discovery,
sharing data, performing cluster scaling
Consistent Hash – Hash based data distribution
– How it finds where data locates
Linear in nature: throughput, capacity
Cluster Mode
![Page 15: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/15.jpg)
Cluster Mode: Replication(복제)
Replication Mode
Cache on Server 1 K,V
Cache on Server 2 K,V
Cache on Server 4 K,V
Cache on Server 3 K,V
cache.put(K,V)
![Page 16: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/16.jpg)
Cluster Mode: Distribution(분산)
Distribution Mode(numOwners=2)
Cache on Server 1 K,V
Cache on Server 2 K,V
Cache on Server 4
Cache on Server 3
cache.put(K,V)
cache.get(K,V)
![Page 17: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/17.jpg)
Cluster Mode: Invalidation(무효화)
Invalidation Mode
Cache on Server 1 K,V2
Cache on Server 2 K,V
Cache on Server 4
Cache on Server 3
cache.put(K,V2)
DB
![Page 18: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/18.jpg)
Configuration: Declarative
Eviction(제거)
Expiration(만료) – on cache
– on key
<global> <transport clusterName="OperationsCacheCluster"> <properties> <property name="configurationFile“ value="jgroups-tcp.xml" /> </properties> </transport> <globalJmxStatistics enabled="true" /> </global> <default> <clustering mode="replication"> <sync /> </clustering> </default> <namedCache name="secureLayerContextCache"> <eviction strategy="LIRS" maxEntries="2000" /> <expiration lifespan="600000" /> <loaders passivation="true" shared="false" preload="false"> <fileStore fetchPersistentState="true" purgerThreads="3" purgeSynchronously="true" ignoreModifications="false" purgeOnStartup="false" location="${java.io.tmpdir}"> <async /> </fileStore> </loaders> </namedCache>
![Page 19: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/19.jpg)
Configuration: Programmatic Configuration Based on XML DefaultCacheManager manager = new DefaultCacheManager("infinispan-config.xml"); Configuration baseConf = manager.getDefaultCacheConfiguration(); Configuration config =new ConfigurationBuilder(). read(baseConf).expiration().lifespan(50000).build(); manager.defineConfiguration(programmaticCache, config); Cache<String, String> cache = manager.getCache("secureLayerContextCache");
DefaultCacheManager manager = new DefaultCacheManager(); Configuration config = new ConfigurationBuilder() .loaders() .shared(false).passivation(false).preload(false) .addCacheLoader() .cacheLoader(new JdbcStringBasedCacheStore()) .addProperty("connectionFactoryClass","org.infinispan.loaders.jdbc .connectionfactory.ManagedConnectionFactory") .addProperty("datasourceJndiLocation", "java:jboss/datasources/MySQLDS") .addProperty("userName", "root") .addProperty("password", "admin") .async().threadPoolSize(10).build(); manager.defineConfiguration(programmaticCache, config); Cache<String, String> cache = manager.getCache("secureLayerContextCache");
Programmatic configuration
![Page 20: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/20.jpg)
Listener
Listener on CacheManager – Node join/ leave, Cache start/ stop
Cache – CRUD, Eviction/ Passivation
– Rehashing/ Transaction completion @Listener public class SimpleListener { @CacheEntryCreated public void dataAdded(CacheEntryCreatedEvent event) { if (event.isPre()) { System.out.println("Before creating the entry:" + event.getKey()); } else { System.out.println("After creating the entry:" + event.getKey()); } … } DefaultCacheManager manager = new DefaultCacheManager(); manager.addListener(listener); Cache<Integer, Ticket> cache = manager.getCache(); cache.addListener(listener);
![Page 21: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/21.jpg)
Asynchronous APIs
put() and get() and remove() are synchronous – They wait for RPC and Locks (and maybe cache stores)
The asynchronous API returns NotifyingFuture – Events are fired on completion of the operation
NotifyingFuture<String> future = c.removeAsync(key); future.attachListener(new FutureListener<String>() { @Override public void futureDone(Future<String> future) { try { future.get(); System.out.printf ("The entry stored under key %s has been removed.", key); } catch (ExecutionException e) { System.out.printf("Failed to remove %s!", key); } } });
![Page 22: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/22.jpg)
Key Features: Persistence
Used for durability
Cache Store - Persistence Storage – File System, Cloud, Remote, JDBC, JPA, LevelDB, Cassandra,
– HBase, MongoDB, BerkeleyDB, JDBM, REST
CacheLoader, CacheStore(CacheWriter from 6.0)
Write-through, write-behind
Passivation, activation
Store chain
Shared store
![Page 23: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/23.jpg)
Persistence: Passivation/Activation
Passivation – write to persistence when evicted from memory (default)
Activation – read to memory and remove from persistence
![Page 24: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/24.jpg)
Key Features: Transactons
JTA Transaction Support
Support MVCC (Multi-Versioned Concurrency Control)
Isolation Level – READ_COMMITTED (default)
– REPEATABLE_READ
Locking Mode – Optimistic Lock (default)
– Pessimistic Lock
![Page 25: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/25.jpg)
Key Features: Query
JBoss Hibernate Search + Apache Lucene
Query on values
Index Directory – Lucene Directory: in-memory, file system, JDBC
– Infinispan Directory
Distributed queries
![Page 26: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/26.jpg)
Distributed Execution
Executes codes on distributed nodes
Through a standard JDK ExecutorService interface
Use DistributedCallable extends java.util.concurrent.Callable
![Page 27: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/27.jpg)
Key Features: Map/Reduce
Based on Distributed Execution Framework
Mapper, Reducer, Collator, MapReduceTask
public interface Callator<KOut, Vout, R> { R collate(Map<KOut, VOut>); }
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); }
![Page 28: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/28.jpg)
Client
![Page 29: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/29.jpg)
Monitoring/Management
Mbeans on CacheManager, Cache
RHQ (JON, JBoss Operations Network)
![Page 30: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/30.jpg)
Spring Integration
Infinispan provider for Spring cache abstraction
infinispan-spring.jar
<cache:annotation-driven cache-manager="operationCacheManager"/> <bean id="operationCacheManager" class="org.infinispan.spring.provider.SpringEmbeddedCacheManagerFactoryBean" p:configurationFileLocation="classpath:infinispan-config.xml" />
@Cacheable(value = "secureLayerContextCache", key="#contextId") public SecureLayerContext getSecureLayerContext(String contextId) { return null; } @CachePut(value = "secureLayerContextCache", key="#contextId") public SecureLayerContext setSecureLayerContext(String contextId, SecureLayerContext secureLayerContext) { return secureLayerContext; } @CacheEvict(value = "secureLayerContextCache", key="#contextId") public void removeSecureLayerContext(String contextId) { // Intentionally blank }
![Page 31: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/31.jpg)
Infinispan on Jboss AS 7
Used for session clustering, Hibernate L2 cache
Application gets cache with JNDI name using @Resource
XML Configuration in server configuration file
<cache-container name="web" aliases="standard-session-cache" default-cache="repl"> <transport lock-timeout="60000" /> <replicated-cache name="repl" mode="ASYNC" batching="true"> <file-store /> </replicated-cache> </cache-container>
![Page 32: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/32.jpg)
JDG
Red Hat JBoss Data Grid
Infinispan-based
JON
All the benefits of subscription, including Red Hat world class support and services
![Page 33: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/33.jpg)
Radar Gun
Data grid and distributed cache benchmarking framework
Built to test Infinispan and other distributed data grid platforms
https://github.com/radargun/radargun
![Page 34: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/34.jpg)
Case Study
![Page 35: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/35.jpg)
Case Study: Session Clustering
Store session information into cache
in Spring MVC Interceptor
![Page 36: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/36.jpg)
Case Study: Session Clustering
- SecurityContextRepository를 구현한
CacheSecurityContextRepository 작성 - loadContext, saveContext를 오버라이드하여
인피니스팬 사용 - Spring cache abstraction 사용
Store session information into cache in Spring Security Filter
![Page 37: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/37.jpg)
Use Cases: Storm Processing State Store
Infinispan Data Grid
![Page 38: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/38.jpg)
References
www.acornpub.co.kr/book/infinispan
infinispan.org
blog.infinispan.org
infinispan-ko.blogspot.com
facebook.com/groups/infinispan
red.ht/data-grid
tedwon.com/display
/dev/Infinispan+Data+Grid
cbcpascal.blogspot.kr
![Page 39: Infinispan Data Grid Platform](https://reader033.vdocuments.pub/reader033/viewer/2022042700/55865fd4d8b42aa9308b46e5/html5/thumbnails/39.jpg)
jbugkorea.org