High performance JPA with Oracle Coherence
Upcoming SlideShare
Loading in...5
×
 

High performance JPA with Oracle Coherence

on

  • 5,797 views

My little Doag2011 slide deck about how to integrate Oracle Coherence with JPA

My little Doag2011 slide deck about how to integrate Oracle Coherence with JPA

Statistics

Views

Total Views
5,797
Slideshare-icon Views on SlideShare
4,913
Embed Views
884

Actions

Likes
0
Downloads
98
Comments
0

6 Embeds 884

http://blog.eisele.net 842
http://feeds.feedburner.com 37
http://rss.feed-index.de 2
http://blog.eisele.net&_=1322147119474 HTTP 1
http://translate.googleusercontent.com 1
http://www.slashdocs.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    High performance JPA with Oracle Coherence High performance JPA with Oracle Coherence Presentation Transcript

    • 1 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • Agenda 1. What is JPA? 2. How does JPA work? 3. What is Coherence? 4. How does Coherence work? 5. Why Coherence with JPA? 6. „JOTG“ - JPA On The Grid 1. JPA Backed Caches 2. JPA 2nd Level Cache 3. JPA 2nd Level Cache with JPA Backed Cache 7. Summary2 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • http://blog.eisele.nethttp://twitter.com/myfearmarkus.eisele@msg-systems.com3 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • What is JPA? • The Java Persistence API (JPA) is a Java programming language framework managing relational data in applications • The Java Persistence API originated as part of the work of the JSR 220 Expert Group. JPA 2.0 is the work of the JSR 317 Expert Group. • Persistence in this context covers three areas:  the API itself, defined in the javax.persistence package  the Java Persistence Query Language (JPQL)  object/relational metadata4 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • Typical Providers5 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • How does JPA work? http://glassfish.java.net/javaee5/persistence/persistence-example.html6 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • JPA Entities @Entity @Table(name="ORDER_TABLE") public class Order { private int id; @Entity private String address; public class Customer { private Customer customer; private int id; private String name; @Id private Collection<Order> orders; @Column(name="ORDER_ID") public int getId() { @Id return id; public int getId() { return id; } } public void setId(int id) { public void setId(int id) { this.id = id; this.id = id; } } public String getName() { @Column(name="SHIPPING_ADDRESS") return name; public String getAddress() { } return address; public void setName(String name) { } this.name = name; } public void setAddress(String address) { @OneToMany(cascade=ALL, mappedBy="customer") this.address = address; public Collection<Order> getOrders() { } return orders; } @ManyToOne() public void setOrders(Collection<Order> newValue) { @JoinColumn(name="CUSTOMER_ID") this.orders = newValue; public Customer getCustomer() { } return customer; } } public void setCustomer(Customer customer) { this.customer = customer; } }7 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • Working with the Entity Manager // Create new customer Customer customer0 = new Customer(); customer0.setId(1); customer0.setName("Joe Smith"); // Persist the customer em.persist(customer0); // Associate orders with the customer. customer0.getOrders().add(order1); order1.setCustomer(customer0); // Persist the customer em.persist(customer0);8 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • What is Coherence?9 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • How Coherence works10 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • How Coherence works11 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • How Coherence works12 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • How Coherence works • Members have logical access to all Entities  At most 2 network operations per access  At most 4 network operations per update  Regardless of cluster size  Deterministic access and update behaviour13 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • What is TopLink Grid? • TopLink Grid is a component of Oracle TopLink • TopLink Grid allows Java developers to transparently leverage the power of the Coherence data grid • TopLink Grid combines:  the simplicity of application development using the Java standard Java Persistence API (JPA) with  the scalability and distributed processing power of Oracle’s Coherence Data Grid.14 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • What is TopLink Grid? • Supports JPA on the Grid Architecture  EclipseLink JPA applications using Coherence as a shared (L2) cache replacement along with configuration for more advanced usage  TopLink Grid integrates EclipseLink JPA and Coherence  Base configuration uses Coherence data grid as distributed shared cache  Updates to Coherence cache immediately available to all cluster nodes  Advanced configurations uses data grid to process queries to avoid database access and decrease database load15 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • Why Coherence with JPA? • Historical approach to scaling a JPA application  Adding nodes to a cluster  Tuning database performance to reduce query time • Both of these approaches will support scalability but only to a point16 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • Why Coherence with JPA? • Historical approach to scaling EclipseLink JPA applications into a cluster:  Disable Shared Cache  Each transaction retrieves all required data from the database. Increased database load limits overall scalability but ensures all nodes have latest data.  Memory footprint of application increases as each transaction has a copy of each required Entity  Every transaction pays object construction cost for queried Entities.  Database becomes bottleneck  Cache Coordination  When Entity is modified in one node, other cluster nodes messaged to replicate/invalidate shared cached Entities.  Creation and/or modification of Entity results in message to all other nodes  Messaging latency means that nodes may have stale data for a short period.  Shared cache size limited by heap of each node  Objects shared across transactions to reduce memory footprint17 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • Strategies for JPA on the grid18 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • JPA Backed Caches – Traditional Approach • Coherence API with caches backed by a database mapped through JPA. • The grid accesses relational data through JPA CacheLoader and CacheStore implementations. • TopLink Grid provides CacheLoader and CacheStore implementations that are optimized for EclipseLink JPA. (EclipseLinkJPACacheLoader and EclipseLinkJPACacheStore) • Using the standard JPA run-time configuration file persistence.xml and the JPA mapping file orm.xml. • The Coherence cache configuration file coherence-cache-config.xml must be specified to override the default Coherence settings and define the CacheStore caching scheme.19 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • Using the Traditional Approach // Get the configured Cache NamedCache cache = CacheFactory.getCache("Customer"); //Create a new Customer Customer cust = new Customer(); cust.setFirstName("Markus"); cust.setLastName("Eisele"); cust.setId(1); //Put the Employee into the cache cache.put(1, cust);20 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • JPA Second Level Cache – Grid Cache • Ensures all nodes have coherent view of data.  Database is always right  Shared Cache is always right—Entities read, modified, or created are available to all cluster members. • Communication is to primary and backup nodes. • Coherence cache size is the sum of the available heap of all members—larger cache size enables longer tenure and better cache hit rate • Can be used with existing applications and all EclipseLink performance features without altering application results21 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • Using the 2nd Level Cache ... import oracle.eclipselink.coherence.integrated.cache.Coherenc eInterceptor; import org.eclipse.persistence.annotations.CacheInterceptor; ... @Entity @CacheInterceptor(value = CoherenceInterceptor.class) public class Customer implements Serializable { ... }22 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • Configuring Optimizations • Grid Read (@Customizer(CoherenceReadCustomizer.class)) )  In the Grid Cache configuration, all reads (both pk and non-pk) are executed against the grid (by default).  For Entities that typically:  Need to be highly available  Must have updates written synchronously to the database; database is system of record • Grid Entity (@Customizer(CoherenceReadWriteCustomizer.class))  The Grid Entity configuration is the same as the Grid Read configuration except that all writes are executed against the grid, not the database.  For Entities that typically:  May have updates written asynchronously to the database (if CacheStore configured)23 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • JPA 2nd Level Cache with JPA Backed Cache • Combining both approaches is possible with some combinations • Grid Entity  Can be optionally used with CacheStore to update the database. • Grid Read  Can be optionally used with CacheLoader.24 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • Relationship Support • Coherence does not provide support for the serialization of complex graphs across caches.  Coherence serializes objects/object graphs and places the results in to a single cache under a key. • TopLink Grid 11gR1 does support storage of complex graphs of Entities with each Entity type stored in a corresponding Coherence cache.  Relationship information is stored into Coherence  Relationships are reconstituted upon retrieval from Coherence  Lazy and eager relationships are supported  Relationships between Coherence cached and database persisted objects is supported. • TopLink Grid wraps Entities with relationships with a byte code generated Wrapper class when put()ing into Coherence  Wrapper encodes relationship details  Wrapper is stripped off when Entity retrieved from Coherence and relationships are reconstituted  Eager relationships will result is retrieval (from either Coherence or database depending on configuration) of target Entity/Entities • Non-TopLink Grid applications can query Entities from Coherence with Filters and get() wrapped Entities  TopLink Grid serializer must be configured on Cache  Coherence clients can configure auto-unwrapping  Relationships will be null when retrieved by Coherence clients25 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • Summary • TopLink supports a range of strategies for scaling JPA applications • TopLink Grid integrates EclipseLink JPA with Oracle Coherence to provide:  JPA on the Grid functionality to support scaling JPA applications with Coherence  Support for caching Entities with relationships in Coherence • Both TopLink and Coherence are a part of WebLogic Application Grid26 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • ActiveCache !!! • Watch out for Oracle Active Cache  Combination of Coherence with either WebLogic Server or Oracle GlassFish Server.  Session State Persistence and Management  Accessing Java Persistence API (JPA) Entities in the Data Cache27 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • Links and Readings http://blog.eisele.net http://www.oracle.com/technetwork/middleware/coherence/overview/index .html http://www.oracle.com/technetwork/middleware/toplink/overview/index.ht ml http://www.oracle.com/technetwork/middleware/toplink/tl-grid-097210.html http://www.eclipselink.org/ http://java.sys-con.com/node/95111728 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011
    • Disclaimer The thoughts expressed here are the personal opinions of the author and no official statement of the msg systems ag.29 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011
    • Thank you for your attention! Markus Eisele markus.eisele@msg-systems.com www.msg-systems.com www.msg-systems.com30 Markus Eisele, Insurance - Strategic IT-Architecture msg systems ag, 17.10.2011