JPA Caching and Application clustering

Source: Internet
Author: User
JPA Caching and Clustering

Reprint please retain the author information:
Author: 88250
Date: April 25, 2011 ToC

Summary

JPA Cache

JPA and application cluster

Policy 1: Disable L2 caching

Policy 2:L2 Cache Synchronization

Strategy 3: Consistent data tier

Conclusion

Reflection

Reference

Summary

This paper mainly introduces the JPA cache architecture and the problems and countermeasures of JPA two level caching in cluster environment. JPA Cache

The JPA cache is divided into first-level caching (L1) and level two caching (L2).

The first-level cache is the Entity Manager (Entitymanager), which is mainly responsible for entity state management.
The secondary cache is the Entitymanagerfactory cache, which is primarily responsible for caching entities or rows of data (such as Eclipselink cache entities, Hibernate cache entity IDs and data rows).

At the time of the query, level two caching can effectively mitigate database pressure and facilitate initialization of the collection entity.

JPA and application cluster

The JPA cache is not problematic when the application is running in a JVM. However, if the application cluster is applied, then the L2 update mechanism will have a consistency problem.

Here are two common policies and a product-related strategy to address this issue. Policy 1: Disable L2 caching

If the level two cache is disabled, the data view of all nodes is always guaranteed to be consistent
Data is always consistent every time a transaction query is taken from the database, the data construction entity does not exist between nodes the message application occupies an increase in memory, because each transaction needs to construct the entity each transaction requires less efficiency because the entity performance bottleneck needs to be constructed--database policy 2:L2 cache synchronization

If you are L2 cache synchronization, the data view of all nodes can always guarantee consistent
Data is always consistent transactional queries need to synchronize all other nodes when creating/updating/deleting entities using L2 cached entities (N2)--network traffic and synchronization overhead may outweigh the benefits of caching

(Orz) L2 cache size Limited by single node JVM memory heap Size

Mainstream JPA implementations typically provide JMS, RMI, and jgroups for cache synchronization. Strategy 3: Consistent data tier

The so-called "consistent data layer" here refers to the use of a service that ensures data consistency in distributed time, and is used to replace L2.

For example, the combination uses Oracle coherence and TopLink Grid. Conclusion

For a JPA Web application, we must pay attention to the JPA two cache in the cluster problem, which is one of the scalable basic points.

To address the problem of JPA two cache inconsistencies, we must sacrifice certain application performance or use commercial products. Rethinking

ORM is convenient, but I think it brings more problems than the problem solved, based on the application of relational database or JDBC direct.

Framework is to simplify the code, unified management. But at the same time the restrictions can not be ignored.

Individuals prefer to build their own wheels, preferring to write more code than to be bound by the framework. Reference Shaun Smith, TopLink grid:scaling JPA application with coherence, Tom Pfaeffle, Oracle Fusion middleware Integratio n Guide for Oracle toplink with coherence Grid, 11g Release 1 (11.1.1) e16596-02, 2011-02 Doug Clarke, Persistence strat Egies for Java EE and WebLogic eclipselink Sandesh, TopLink Cache and WebLogic Cluster


This article is the use of B3log Solo from the simple design of the art of the synchronization of the release of the original address: http://88250.b3log.org/jpa-cache-cluster.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.