0
Infinispan and Enterprise Data Grid Tristan Tarrant Principal Software Engineer [email_address]  /  https://twitter.com/tr...
Infinispan: What is it ? <ul><li>In-memory key/value data grid
Built around java.util.ConcurrentMap interface
Easy to set-up and use </li></ul>Cache<String, String> cache = new DefaultCacheManager().getCache(); cache.put(“ash”, “naz...
Infinispan: Clustering/1 <ul><li>Replication </li><ul><li>All nodes contain a copy of every entry
Good for small clusters
Maximum size is constrained by node with least memory </li></ul><li>Invalidation </li><ul><li>Values are kept locally
Updates to a key invalidate all the other nodes </li></ul><li>Distribution </li><ul><li>Entries are placed on redundant no...
Scales to larger clusters
Size scales linearly with the number of servers </li></ul></ul>
Infinispan: Clustering/2 <ul><li>Consistent Hash </li><ul><li>Calculated from the key
Location of data in the cluster is deterministic
Keeps RPCs low </li></ul><li>L1 Cache </li><ul><li>Remote data is proxied locally
Multiple retrievals of the same entry don't have to do RPC </li></ul><li>Grouping </li><ul><li>Uses “key group” to determi...
Keeps related keys together </li></ul></ul>
Infinispan: Configuration <ul><li>Programmatic via builder-style API
Declarative via XML </li></ul>CacheManager manager = new DefaultCacheManager(&quot;my-config-file.xml&quot;); Cache<String...
Infinispan: Asynchronous API <ul><li>Normally put() and get() and remove() are synchronous </li><ul><li>They wait for RPC ...
Infinispan: Expiration & Eviction <ul><li>Entries in the cache are immortal by default
Expiration (lifespan or idle time) </li><ul><li>Per cache (via configuration)
Per key (programmatically) </li></ul><li>Eviction </li><ul><li>Maximum entry cap per cache
Various strategies (FIFO, LRU, LIRS) </li></ul></ul>cache.put(“ash”, “nazg”, 5, SECONDS); cache.put(“krul”, “uruk”, 5, MIN...
Infinispan: Listeners <ul><li>Clients can register listeners for two classes of events </li><ul><li>CacheManager </li><ul>...
Cache started/stopped </li></ul><li>Cache </li><ul><li>CRUD
Eviction / Passivation
Rehashing / Transaction completion </li></ul></ul><li>Listeners are annotated POJOs  </li></ul>@Listener public class MyCa...
Infinispan: Transactions <ul><li>Perform “atomic” operations on multiple keys
Upcoming SlideShare
Loading in...5
×

Infinispan and Enterprise Data Grid

6,105

Published on

Tristan Tarrant - JBug Milano - January 2012

Published in: Technology
0 Comments
10 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,105
On Slideshare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
Downloads
170
Comments
0
Likes
10
Embeds 0
No embeds

No notes for slide

Transcript of "Infinispan and Enterprise Data Grid"

  1. 1. Infinispan and Enterprise Data Grid Tristan Tarrant Principal Software Engineer [email_address] / https://twitter.com/tristantarrant/
  2. 2. Infinispan: What is it ? <ul><li>In-memory key/value data grid
  3. 3. Built around java.util.ConcurrentMap interface
  4. 4. Easy to set-up and use </li></ul>Cache<String, String> cache = new DefaultCacheManager().getCache(); cache.put(“ash”, “nazg”); String v = cache.get(“ash”);
  5. 5. Infinispan: Clustering/1 <ul><li>Replication </li><ul><li>All nodes contain a copy of every entry
  6. 6. Good for small clusters
  7. 7. Maximum size is constrained by node with least memory </li></ul><li>Invalidation </li><ul><li>Values are kept locally
  8. 8. Updates to a key invalidate all the other nodes </li></ul><li>Distribution </li><ul><li>Entries are placed on redundant nodes in the grid
  9. 9. Scales to larger clusters
  10. 10. Size scales linearly with the number of servers </li></ul></ul>
  11. 11. Infinispan: Clustering/2 <ul><li>Consistent Hash </li><ul><li>Calculated from the key
  12. 12. Location of data in the cluster is deterministic
  13. 13. Keeps RPCs low </li></ul><li>L1 Cache </li><ul><li>Remote data is proxied locally
  14. 14. Multiple retrievals of the same entry don't have to do RPC </li></ul><li>Grouping </li><ul><li>Uses “key group” to determine entry location
  15. 15. Keeps related keys together </li></ul></ul>
  16. 16. Infinispan: Configuration <ul><li>Programmatic via builder-style API
  17. 17. Declarative via XML </li></ul>CacheManager manager = new DefaultCacheManager(&quot;my-config-file.xml&quot;); Cache<String, String> myCache = manager.getCache(&quot;myCache&quot;); Configuration c1 = new ConfigurationBuilder() .clustering() .l1().disable() .mode(DIST_SYNC) .hash().numOwners(2) .build(); <infinispan> <global> <transport clusterName=&quot;infinispan-cluster /> </global> <namedCache name=&quot;myCache&quot;> <clustering mode=&quot;dist&quot;> <sync/> <hash numOwners=&quot;2&quot; /> <l1 enabled=&quot;false&quot;/> </clustering> </namedCache> </infinispan>
  18. 18. Infinispan: Asynchronous API <ul><li>Normally put() and get() and remove() are synchronous </li><ul><li>They wait for RPC and Locks (and maybe cache stores) </li></ul><li>The asynchronous API returns NotifyingFutures for the above operations </li><ul><li>Events are fired on completion of the operation </li></ul></ul>FutureListener nineteenEightyFive = new FutureListener() { public void futureDone(Future future) { try { future.get(); } catch (Exception e) { System.out.println(&quot;The DeLorean is still in 1955&quot;); } } }; cache.putAsync(&quot;mph&quot;, &quot;88&quot;).attachListener(nineteenEightyFive);
  19. 19. Infinispan: Expiration & Eviction <ul><li>Entries in the cache are immortal by default
  20. 20. Expiration (lifespan or idle time) </li><ul><li>Per cache (via configuration)
  21. 21. Per key (programmatically) </li></ul><li>Eviction </li><ul><li>Maximum entry cap per cache
  22. 22. Various strategies (FIFO, LRU, LIRS) </li></ul></ul>cache.put(“ash”, “nazg”, 5, SECONDS); cache.put(“krul”, “uruk”, 5, MINUTES, 1, MINUTE);
  23. 23. Infinispan: Listeners <ul><li>Clients can register listeners for two classes of events </li><ul><li>CacheManager </li><ul><li>Node join/leave
  24. 24. Cache started/stopped </li></ul><li>Cache </li><ul><li>CRUD
  25. 25. Eviction / Passivation
  26. 26. Rehashing / Transaction completion </li></ul></ul><li>Listeners are annotated POJOs </li></ul>@Listener public class MyCacheListener { @CacheEntryModified public void print(CacheEntryModifiedEvent event) { System.out.println(“Something has changed in the Matrix”); } }
  27. 27. Infinispan: Transactions <ul><li>Perform “atomic” operations on multiple keys
  28. 28. Caches are transactional or non-transactional (5.1)
  29. 29. MVCC </li><ul><li>Readers don't acquire locks
  30. 30. Writers work on a copy until commit </li></ul><li>Locking modes </li><ul><li>Optimistic: locks acquired during prepare
  31. 31. Pessimistic: locks acquired during writes </li></ul></ul>TransactionManager tm = cache.getAdvancedCache().getTransactionManager(); tm.begin(); cache.put(“ash”, “nazg”); cache.remove(“krul”); tm.commit();
  32. 32. Infinispan: Batching <ul><li>Simpler and less expensive than transactions
  33. 33. Multiple operations are grouped and executed “atomically”
  34. 34. Integrates with JTA
  35. 35. Cannot participate in 2PC transactions </li></ul>cache.startBatch(); cache.put(&quot;ash&quot;, &quot;nazg&quot;); cache.put(&quot;krul&quot;, &quot;uruk&quot;); cache.put(&quot;gakh&quot;, &quot;olog&quot;); cache.endBatch(true); // commit cache.startBatch(); cache.put(&quot;krith&quot;, &quot;nazgu&quot;); cache.put(&quot;udu&quot;, &quot;gaathz&quot;); cache.endBatch(false); // rollback
  36. 36. Infinispan: Cache Stores <ul><li>Persistent storage for the data in the grid
  37. 37. Pluggable stores </li><ul><li>File, JDBC, BerkeleyDB, Cassandra, Remote </li></ul><li>Support for passivation of evicted entries
  38. 38. Store chaining
  39. 39. Shared stores </li></ul>
  40. 40. Infinispan: Client Server <ul><li>HotRod </li><ul><li>Custom Infinispan protocol
  41. 41. Java, Python, .NET clients
  42. 42. Topology aware </li></ul><li>Memcached </li><ul><li>With all the features that memcached doesn't have :) </li></ul><li>REST </li><ul><li>Deployable WAR
  43. 43. Optimistic locking (via the ETag HTTP header) </li></ul></ul>
  44. 44. Infinispan: Marshalling <ul><li>Faster than standard Java serialization
  45. 45. Used for </li><ul><li>Intra-node communication (replication, distribution)
  46. 46. Client-server communication (HotRod)
  47. 47. Persistence to a cache store </li></ul><li>Support for custom marshallers
  48. 48. Support for non-serializable classes (via externalizer)
  49. 49. Lazy deserialization </li><ul><li>Values are unmarshalled only when accessed </li></ul></ul>
  50. 50. Infinispan: JGroups <ul><li>Provides the communication trasport
  51. 51. Multiple protocol support </li><ul><li>UDP </li><ul><li>Multicast for automatic node discovery, datagrams for node to node, scales to many nodes </li></ul><li>TCP </li><ul><li>Static list of initial (stable), hosts, unicast for node to node, useful where multicast is disabled or across routers </li></ul><li>Alternative discovery protocols (S3, JDBC, File, etc) </li></ul><li>Advanced applications can use the underlying transport for their purposes (must use a MuxChannel)
  52. 52. Topology aware support (Site, Rack, Machine) </li></ul>
  53. 53. Infinispan: Query <ul><li>Query on values
  54. 54. Uses Hibernate Search as Engine
  55. 55. Entry values are indexed via Lucene
  56. 56. Indexes may be </li><ul><li>Local (each node keeps index of local entries, queries only return local data)
  57. 57. Replicated (all nodes have a copy of the full index, queries can be performed on the whole dataset)
  58. 58. Distributed (the index is stored in Infinispan, queries can be performed on the whole dataset) </li></ul><li>Distributed queries (local index, query is executed on all nodes and aggregated) </li></ul>
  59. 59. Infinispan: Distributed Executors <ul><li>A way to run code on all nodes </li><ul><li>Modelled on Executor/Callable </li></ul><li>Base for Map/Reduce </li><ul><li>The entries in the cache are the input data
  60. 60. Map phase </li><ul><li>A mapper method is called with each local entry as input
  61. 61. The mapper emits transformed keys/values to a collector </li></ul><li>Reduce phase </li><ul><li>A reducer method is called with all transformed values for every key </li></ul><li>Collation phase </li><ul><li>The transformed keys/values are aggregated from all nodes to the initiator </li></ul></ul></ul>
  62. 62. Infinispan: Monitoring <ul><li>MBeans for CacheManagers and Caches
  63. 63. Statistics collection </li><ul><li>Hits, Misses, Average R/W times
  64. 64. Transaction commits, rollbacks, deadlocks
  65. 65. Cluster members, replication timings </li></ul><li>Operations </li><ul><li>Cache start / stop </li></ul><li>RHQ plugin </li><ul><li>Monitor all metrics
  66. 66. Receive notifications on events
  67. 67. Aggregate information from multiple servers </li></ul></ul>
  68. 68. Infinispan: JPA 2nd level cache <ul><li>Query caching </li><ul><li>Keyed by query-name and parameters hash
  69. 69. Cache can be local or replicated (only if it makes sense) </li></ul><li>Entity caching </li><ul><li>Keyed by the entity's primary key
  70. 70. Cache is local to each node
  71. 71. Invalidation is used to force other nodes to re-read from DB </li></ul><li>Integrates with the JTA manager </li><ul><li>Caches participate in transactions and support semantics
  72. 72. Strongly recommended </li></ul><li>NB: Benchmark your application before enabling </li></ul>
  73. 73. Infinispan: CDI <ul><li>Provides CDI support for </li><ul><li>Cache configuration
  74. 74. Cache injection
  75. 75. JCache (JSR-107) annotations
  76. 76. Injection of caches from the AS7 Infinispan subsystem </li></ul></ul>@Qualifier @Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface MyCache { } @ConfigureCache(&quot;myCache&quot;) @MyCache @Produces public Configuration myCacheConfiguration; @MyCache Cache<String,String> myCache;
  77. 77. Infinispan: Spring <ul><li>Infinispan provider for Spring 3.1's cache abstraction
  78. 78. Integration with Spring's DI for constructing cache managers and caches
  79. 79. Declarative caching annotation
  80. 80. Declarative eviction annotation </li></ul><bean id=&quot;cacheManager&quot; class=&quot;org.infinispan.spring.provider.SpringEmbeddedCacheManagerFactoryBean&quot; p:configurationFileLocation=&quot;classpath:infinispan-config.xml&quot; /> @Cacheable(&quot;items&quot;) public Item findItems(ItemPK itempk) {...} @CacheEvict(value = &quot;items&quot;, allEntries=true) public void readItems(ItemSource source) {...}
  81. 81. Infinispan: Continuous Query w/Drools <ul><li>Distributed Complex Event Processing
  82. 82. Built on Drools Live Queries
  83. 83. Local and Clustered queries (replicated only for now)
  84. 84. Fault tolerant </li></ul>ContinuousQueryManager cqm = new ContinuousQueryManager(cacheManager); QueryDefinition qd = new QueryDefinition(queryName, query, outputEntries); cqm.defineQuery(qd); ContinuousQuery cq = cqm.executeContinuousQuery(qd.getQueryName(), true, params); cq.addQueryListener(new ResultSetListener() { public void entryAdded(MatchingEntry row) { // ... } public void entryRemoved(MatchingEntry row) { // ... } public void entryUpdated(MatchingEntry row) { // ... } });
  85. 85. Infinispan: 5.1 out TODAY!!! <ul><li>Asymmetric clusters
  86. 86. Overhauled Transaction support
  87. 87. Single lock owner
  88. 88. Distributed Queries
  89. 89. Fine-Grained Atomic Maps
  90. 90. Uses JGroups 3.0 (with a lot of performance improvements)
  91. 91. New configuration based on builders
  92. 92. Many many performance optimizations and bugfixes </li></ul>
  93. 93. Infinispan: 5.2 ??? <ul><li>HotRod v2 </li><ul><li>Query
  94. 94. Map/Reduce (REST too)
  95. 95. Transactions
  96. 96. Events </li></ul><li>Versioned entries </li><ul><li>Will support eventual consistency </li></ul><li>More work on optimizing the following areas: </li><ul><li>Transactions
  97. 97. Locking
  98. 98. RPCs </li></ul></ul>
  99. 99. JBoss AS7.x and Infinispan <ul><li>AS7.x uses Infinispan for clustering </li><ul><li>Web Sessions
  100. 100. Stateful Session EJB
  101. 101. JPA 2nd level cache
  102. 102. Session EJB failover
  103. 103. HA singleton </li></ul><li>Configured via standalone.xml / domain.xml </li><ul><li>Cache managers and caches injected via @Resource
  104. 104. User applications need to import the APIs </li></ul></ul>META-INF/MANIFEST.MF Dependencies: org.infinispan export
  105. 105. Enterprise Data Grid: What is it ? <ul><li>Productized Infinispan
  106. 106. Part of the Enterprise Platform 6 family of products
  107. 107. Three variants </li><ul><li>Standalone (Infinispan Core)
  108. 108. Server (HotRod, Memcached, REST)
  109. 109. Embedded (Use of Infinispan within EAP 6) </li></ul></ul>
  110. 110. Miscellanea <ul><li>Come and help us ! </li><ul><li>Code http://github.com/infinispan/infinispan
  111. 111. Docs https://docs.jboss.org/author/display/ISPN/Home
  112. 112. Bug reporting https://issues.jboss.org/browse/ISPN
  113. 113. Community https://community.jboss.org/community/infinispan?view=discussions </li></ul><li>Q & A </li></ul>
  114. 114. That's all folks [email_address] http://jboss.org/infinispan
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×