Infinispan - NoSQL für den Enterprise Java Alltag...Infinispan - NoSQL für den Enterprise Java...
Transcript of Infinispan - NoSQL für den Enterprise Java Alltag...Infinispan - NoSQL für den Enterprise Java...
26.07.2013
1
Orientation in Objects GmbH
Weinheimer Str. 6868309 Mannheim
Infinispan - NoSQL für den Enterprise Java
Alltag
Wer schnell und einfach in bestehende Enterprise Java Anwendungen eine NoSQL-Datastore integrieren möchte dem bietet JBoss mit dem Projekt
Infinispan eine Lösung an.Die Session zeigt wie man mit NoSQL als komplementärem Denkansatz und
Infinispan als elegantem Werkzeug auch im "relational dominierten JEE-Umfeld" Performanz und Verfügbarkeit von Anwendungen verbessern kann.Infinispan ist das NoSQL-Datastore-Projekt aus dem Hause JBoss und als
distributed transactional Cache gemäß JSR-107 umgesetzt.
1.1
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Gliederung
• NoSQL und Java EE
• Infinispan
• Integrationsszenarien
• Zusammenfassung
2
26.07.2013
2
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Gliederung
• NoSQL und Java EE
• Infinispan
• Integrationsszenarien
• Zusammenfassung
3
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
NoSQL vs. Java EE
• NoSQL– Datenspeicher ohne festgelegte Tabellenschemata– skalieren horizontal– keine strenge Spezifikation( viele gut diskutierte/erprobte Konzepte)– viele Implementierungen auf verschiedenen Konzepten basierend
• Java EE– strenge Spezifikation einer Softwarearchitektur – transaktionsbasierte Ausführung von Java-Komponenten– auf transkaktionsbasiertem Konzept beruhende Teilstandards
• JTA/JCA/JPA/JMS/JDBC
– Horizontale Skalierung als Konzept für High Availability• Antwortzeiten• Ausfall von Knoten
– (insbesondere gedacht für Web-Anwendungen)
4
26.07.2013
3
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
NoSQL
• Dokumentenorientierte Datenbanken
• Graphendatenbanken
• Key-Value-Stores– Diskbasiert– RAM-Cache– Sortierte Key-Value-Stores
• Eventually Consistent Stores
• MultivalueDatenbanken
• Objektdatenbanken
• Spaltenorientierte Datenbank
5
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
CAP-Theorem ( nach E. Brewer PODC Symposium 2000)
• Consistency – roughly meaning that all clients of a data store get responses to
requests that ‘make sense’. For example, if Client A writes 1 then 2 to location X, Client B cannot read 2 followed by 1.
• Availability– all operations on a data store eventually return successfully. We say
that a data store is ‘available’ for, e.g. write operations.
• Partition tolerance– “The network will be allowed to lose arbitrarily many messages sent
from one node to another”– if the network stops delivering messages between two sets of servers,
will the system continue to work correctly?
6
26.07.2013
4
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
CA vs. PA
7
ConsistencyConsistency
AvailabilityAvailabilityPartion
TolerancePartion
Tolerance
n.a.
BASE
JTA JTA
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Data Grid vs. Distributed DBMS
8
ConsistencyConsistency
AvailabilityAvailabilityPartion
TolerancePartion
Tolerance
n.a.
BASE
Data Grid
DistributedDBMS
26.07.2013
5
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
CA va. CP – Partitionswahrscheinlichkeit
9
Datenm
enge
Durchsatz/Verfügbarkeit
BASE
Java EEVertikaleSkalierung
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Elastic Data Grid für Java EE
• Niedrige Latenzzeit – RAM 100fach schneller als Disk
• Horizontal skalierbar
• Elastisch– Knoten können kontrolliert ein/ausgeschaltet werden
• optionaler ACID Support– Read Commited/Repeatable Read
• Standardisiertes API –JSR 107(347)
10
Servlet
Node 1
JSF
Node 3
EJB
Node 2
AppserverAppserverJSR 107
Node 1
JSR 107
Node 3
JSR 107
Node 2
Data GridData Grid
Secondary Store
26.07.2013
6
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Java Distributed HashTable Standard –JSR 107
• javax.cache.CacheManager
• javax.cache.Cache– ähnlich java.util.ConcurrentMap– javax.cache.CacheLoader– javax.cache.CacheWriter
• javax.cache..CacheListener
• Annotationen z.B.– @CacheResult– @CacheKeyParam– @CacheRemoveEntry– @CacheRemoveAll– @CacheDefaults..
11
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Distributed HashTable – nicht in JSR 107
• Standardisierte Konfiguration
• Asychrone Bearbeitung mit Futures– Nonblocking add/remove
• Clustering Details der Zustandsverteilung– Replikation– Synchron/Asychron
12
26.07.2013
7
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
CacheLoader
13
JEEApplication
CacheCache
1. Get
• Secondary Store
CacheLoaderCacheLoader
2. load
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
CacheWriter
14
JEEApplication
CacheCache
1. Put
• Secondary Store
CacheWriterCacheWriter
2. store
26.07.2013
8
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Expiration
15
CacheCache
I
Y
XM
F
D
put
get
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Gliederung
• NoSQL und Java EE
• Infinispan
• Integrationsszenarien
• Zusammenfassung
16
26.07.2013
9
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Infinispan
• Key-Value-Store– Distributed HashTable(JSR 107/347)– Transactional (JTA)– Low-latency (RAM)– Optional persist to disk
• Open Source Data Grid Plattform (LGPL)– JBoss/Red Hat
• Java and Scala
• Nicht nur für die JVM gedacht
• in verschiedenen Modi einsetzbar– Embedded– Client/Server(Data Grid)
17
ConsistencyConsistency
AvailabilityAvailabilityPartion
TolerancePartion
Tolerance
n.a.
BASE
Infinispan DistributedDBs
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Local Embedded Mode
18
SecondaryStore
2. Read
JEE
Application
CacheCache
Data Access
UI
1. get4. Read
0./3. Query
26.07.2013
10
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Local Embedded Mode II
• Code in der gleiche VM wie infinispan
• wenig Konfigurationsarbeit
– Mit default EinstellungenDefaultCacheManager cacheManager = new DefaultCacheManager();
Cache<String, String> cache = cacheManager.getCache( );
– Mit eigenen Einstellungen z.B: Clustereinstellungen
DefaultCacheManager cacheManager = new DefaultCacheManager(„oio-infinispan-config.xml");
Cache<String, String> cache = cacheManager.getCache( );
19
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Infinispan und Java EE Clustering
20
JEE
Application
CacheCache
Data Access
UI
1. get5. get
0./4. Query
JEE
Application
CacheCache
Data Access
UI
1.x Store A1 2. Read A
0. Update
• Secondary Store
26.07.2013
11
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Clustered Embedded Mode
21
JEE
Application
CacheCache
Data Access
UI
2. get5. put
0./4. Query
JEE
Application
CacheCache
Data Access
UI
n.
• Secondary Store
JEE
Application
CacheCache
Data Access
UI
n+k.
3./6. load/Store
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
JEEApplication
CacheCache
Data Access
JEEApplication
CacheCache
Data Access
2. Put
0. query
Replication
22
JEEApplication
CacheCache
Data Access
1. Store
• Secondary Store
Replicate Replicate
26.07.2013
12
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
JEEApplication
CacheCache
Data Access
4. get
3. query
Invalidation
23
JEEApplication
CacheCache
Data Access
JEEApplication
CacheCache
Data Access
1. Put
0. query
• Secondary Store
Invalidate Invalidate
2. Store
5. load
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
JEEApplication
CacheCache
Data Access
2. get
0. query
Distribution [numOwner=2]
24
JEEApplication
CacheCache
Data Access
JEEApplication
CacheCache
Data Access
1. Read
• Secondary Store
Copy
26.07.2013
13
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Client/Server Mode
25
Load/Store
Non JavaApplication
Plenty
JVM
CacheCache
• Secondary Store
memcachedJVM
CacheCache
JEEApplication
Data Access
JSEApplication
Data Access
Hotrod
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Client/Server Mode II
• Schneller starten und beenden• Bessere tuning von Hardware und JVM• Data Grid kann von mehreren Applikation benutzt werden• Starten des Servers erfordet die Angabe des Protokolls
– C:\infinispan-5.1.2.FINAL\bin>startServer.bat -r ho trod
• Unterstützte Protokolle– Memcached– Hot Rod– Infinispan REST interface
• org.infinispan.client.hotrod.RemoteCacheManagerRemoteCacheManager rcm = new
RemoteCacheManager("192.168.3.120");RemoteCache remoteCace = rcm.getCache();String key = "hello";remoteCace.put(key, "world");
…
26
26.07.2013
14
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Client/Server Remoting
RemoteEndpoint
Protokoll Smart Routing
LoadBalancing
Memcached Text - VordefinierteListe
ReSTful Text - http Loadbalancer
HotRod Binary + DynamischeTopologie
27
JVM
CacheCache
JEEApplicationApplication
Data Access
GroovyApplicationApplication
Data Access
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
CacheStore
28
JEEApplication
CacheCache
1. Put
• Secondary Store
CacheStoreCacheStore
2. store
26.07.2013
15
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Eviction
29
CacheCache
I
Y
XM FDput
get
MemorymeterStrategiez.B. LRU
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Storage JPA Cache Store
• Implementierung von JPA 2.0
• Speicherung auf eine DB mit definiertem Schema
• Key muss die Id der Entität sein– @Id, @EmbeddedId
• Keine generierten Ids
Cache<String, User> usersCache = cacheManager.getCache("myJPACache"); // configured f or User entity class
usersCache.put("raytsang", new User());
Cache<Integer, Teacher> teachersCache = cacheManager.getCache("myJPACache"); // cannot do th is whenthis cache is configured to use a JPA cache store
teachersCache.put(1, new Teacher());
30
26.07.2013
16
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Storage JPA Cache Store
<namedCache name="vehicleCache">
<loaders passivation="false" shared="true" preload=" true">
<jpaStore
persistenceUnitName="org.infinispan.loaders.jpa.con figurationTest"
entityClassName="org.infinispan.loaders.jpa.entity. User"
/>
</loaders>
</namedCache>
31
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Gliederung
• NoSQL und Java EE
• Infinispan
• Integrationsszenarien
• Zusammenfassung
32
26.07.2013
17
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
DI-Container Integration
33
DI ContainerR
emot
eCon
nect
or
Ser
vice
Tran
sact
ionI
nter
epto
r
Cac
he
DA
O
Cac
heS
tore
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Spring Integration
• seit Spring 3.1 Cache Abstraktion• Infinispan Provider vorhanden• Integration mit Spring DI für cache managers und caches<bean id= "cacheManager"class= "org.infinispan.spring.provider.SpringEmbeddedCacheManagerFactor
yBean"p:configurationFileLocation= "classpath:META-INF/oio-infinispan-
config.xml"></bean>
• Aktive Cache Unterstützung– <cache:annotation-driven />
• Deklarative Cache Annotation@Cacheable("nachrichtenCache")public List<Nachricht> findAlleUngeleseneNachrichten () {… }
34
26.07.2013
18
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Spring Integration
@Cacheable("nachrichtenCache", key=#" projektId ")
public List<Nachricht> findNachrichtenFuerProjekt(Bi gIntegerprojektId) {… }
• Deklarative Eviction@CacheEvict(value = "nachrichtenCache", allEntries = true)
public void nachrichtMarkieren(BigInteger nachrichtId, booleanungelesen) {… }
35
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
CDI
• Konfiguration und Injizierung des Infinispan Cache
• Partielle Unterstützung vom JSR 107 Annotationen
• Cache Injizierung
@Inject
private Cache<String, String> cache;
@Inject
RemoteCache<String, String> remoteCache;
36
26.07.2013
19
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
CDI
• Eigene Cache [email protected]@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})@Retention(RetentionPolicy.RUNTIME)@Documentedpublic @interface NachrichtenCache {}
public class CacheCreator {@ConfigureCache("nachrichtencache") // cache name.@NachrichtenCache // cache qualifier.@Producespublic Configuration specialCacheCfg() {return new ConfigurationBuilder().eviction().strategy(EvictionStrategy.LRU).maxEntries(10).build();}}
37
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
CDI
• Injizierung des eigenen Caches
• public class MyCDIComponent {
• @Inject @NachrichtenCache
• Cache<String, String> nachrichtenCache;
• }
38
26.07.2013
20
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
OR/M Integration
39
Java Virtual Machine
Anwendung
Transient
Transient
TransientTransient
Transient
PersistenceManager
1.Level Cache
Connection
DB
InstanzInstanz
Instanz
2.Level Cache
Entity Cache
InstanzInstanz
InstanzInstanz
QueryFacility
Transaction
QueryCache
TimestampCache
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Hibernate second level cache
• Entity Cache– Key der Primärschlüssel– Cache kann lokal(default) oder repliziert sein– Replizierter Cache ist nicht empfohlen
• Query Cache– Key ist query-name und Parameter Hash– Cache kann lokal(default) oder repliziert sein– Bei repliziertem Cache aufpassen
• Timestamps Cahe– Asynchrone Replikation(default)– Keine eviction/expiration
40
26.07.2013
21
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Hibernate second level cache
• JTA Transaktion Manager– Hibernate soll/muss JTA Manager nutzen.
<property name= "hibernate.cache.use_second_level_cache" value="true"/>
<property name= "hibernate.cache.use_query_cache" value="true"/>
<property name= "hibernate.cache.region.factory_class" value="org.hibernate.cache.infinispan.InfinispanRegionFactory"/>
<property name= "hibernate.cache.infinispan.cfg" value="/oio-infinispan-config.xml"/>
<property name= "hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTSStandaloneTransactionManagerLookup"/>
41
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Gliederung
• NoSQL und Java EE
• Infinispan
• Integrationsszenarien
• Zusammenfassung
42
26.07.2013
22
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
NoSQL-Design Prinzipien
• Schnelles, horizontal skalierendes Speichern und Skalieren von ständig wachsenden Immutable-Data (Fakten)
• Die primäre Schreiboperation ist das Hinzufügen von Fakten
• Vermeidung der Komplexität des CAP Theorems durchNeuberechnung aller Queries aus den Fakten
• Verwendung von inkrementellen Query-Algorithmen um die Antwortzeit zu verringern
43
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Infinispan Ausblick
• Map/Reduce Support
• Versioned Entries
• Support Eventual Consistency (7.0 ?)
• Optimierungen:– Transaktionen– Locking– RPC
44
26.07.2013
23
Orientation in Objects GmbH
Weinheimer Str. 6868309 Mannheim
Vielen Dank für ihre Aufmerksamkeit !
Orientation in Objects GmbH
Weinheimer Str. 6868309 Mannheim
??
? ?
????
Fragen ?
46