Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Infinispan and Enterprise Data Grid

7.519 visualizaciones

Publicado el

Tristan Tarrant - JBug Milano - January 2012

Publicado en: Tecnología
  • Inicia sesión para ver los comentarios

Infinispan and Enterprise Data Grid

  1. 1. Infinispan and Enterprise Data Grid Tristan Tarrant Principal Software Engineer [email_address] /
  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
  111. 111. Docs
  112. 112. Bug reporting
  113. 113. Community </li></ul><li>Q & A </li></ul>
  114. 114. That's all folks [email_address]