Infinispan and Enterprise Data Grid

  • 5,703 views
Uploaded on

Tristan Tarrant - JBug Milano - January 2012

Tristan Tarrant - JBug Milano - January 2012

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
5,703
On Slideshare
0
From Embeds
0
Number of Embeds
12

Actions

Shares
Downloads
154
Comments
0
Likes
10

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

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