Difference between revisions of "EclipseLink/UserGuide/JPA/Basic JPA Development/Caching/Coordination"

From Eclipsepedia

Jump to: navigation, search
(Cache Coordination)
(Clustering Cache Coordination)
Line 14: Line 14:
 
An application cluster is a set of middle tier server machines or VMs servicing requests for a single application, or set of applications.  Multiple servers are used to increase the scalability of the application and/or to provide fault tolerance and high availability.  Typically the same application will be deployed to all of the servers in the cluster and application requests will be load balanced across the set of servers.  The application cluster will access a single database, or a database cluster.  An application cluster may allow new servers to be added to increase scalability, and for servers to be removed such as updates and servicing.
 
An application cluster is a set of middle tier server machines or VMs servicing requests for a single application, or set of applications.  Multiple servers are used to increase the scalability of the application and/or to provide fault tolerance and high availability.  Typically the same application will be deployed to all of the servers in the cluster and application requests will be load balanced across the set of servers.  The application cluster will access a single database, or a database cluster.  An application cluster may allow new servers to be added to increase scalability, and for servers to be removed such as updates and servicing.
  
EclipseLink can function in any clustered environment.
+
Application clusters can consist of Java EE servers, web containers, or Java server applications.
  
 +
EclipseLink can function in any clustered environment.  The main issue in a clustered environment is utilizing a shared persistence unit (L2) cache.  If you are using a shared cache (enabled by default in EclipseLink), then each server will maintain its own cache, and each caches data can get out of sync with the other servers and the database.
  
There are many solutions to caching in a clustered environment, including:
+
EclipseLink provides cache coordination in a clustered environment to ensure the servers caches are is sync.
* disable the shared cache
+
* only cache read-only objects
+
* set a cache invalidation timeout
+
* use refreshing on objects/queries when fresh data is required
+
* use optimistic locking (writes on stale data will fail, and will automatically invalidate the cache)
+
* using a distributed cache (such as Oracle TopLink Grid with Oracle Coherence)
+
* using database events to invalidate changed data
+
* using cache coordination (synchronizing the caches, as discussed in this example)
+
  
This example gives an overview of the <i>cache coordination</i> option.
+
There are also many other solutions to caching in a clustered environment, including:
 +
* Disable the shared cache (through setting <code>@Cacheable(false)</code>, or <code>@Cache(isolation=ISOLATED)</code>).
 +
* Only cache read-only objects.
 +
* Set a cache invalidation timeout to reduce stale data.
 +
* Use refreshing on objects/queries when fresh data is required.
 +
* Use optimistic locking to ensure write consistency (writes on stale data will fail, and will automatically invalidate the cache).
 +
* Use a distributed cache (such as Oracle TopLink Grid's integration of EclipseLink with Oracle Coherence).
 +
* Use database events to invalidate changed data in the cache (such as EclipseLink' support for Oracle DCN/QCN).
 +
* Use cache coordination in EclipseLink (discussed in this section.
  
EclipseLink provides a cache coordination feature that enables a set of EclipseLink sessions to synchronize their changes in a distributed network such as an application server cluster.  Cache coordination works by each EclipseLink session (ServerSession/persistence unit) on each server in the cluster being able to broadcast notification of transactional object changes to the other EclipseLink sessions in the cluster.  EclipseLink supports cache coordination over RMI and JMS.  The cache coordination framework is also extensible so other options could be developed.
+
Cache coordination enables a set of persistence units deployed to different servers in the cluster (or on the same server) to synchronize their changes.  Cache coordination works by each persistence unit on each server in the cluster being able to broadcast notification of transactional object changes to the other persistence units in the cluster.  EclipseLink supports cache coordination over RMI and JMS.  The cache coordination framework is also extensible so other options could be developed.
  
The need to maintain up-to-date data for all applications is a key design challenge for building a distributed application. The difficulty of this increases as the number of servers within an environment increases. EclipseLink provides a distributed cache coordination feature that ensures data in distributed applications remains current.
+
We recommend that you use cache coordination with an [[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Locking/Optimistic_Locking|optimistic locking policy]].
 
+
Cache coordination reduces the number of optimistic lock exceptions encountered in a distributed architecture, and decreases the number of failed or repeated transactions in an application. However, cache coordination in no way eliminates the need for an effective locking policy. To effectively ensure working with up-to-date data, cache coordination must be used with optimistic or pessimistic locking. We recommend that you use cache coordination with an [[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Locking/Optimistic_Locking|optimistic locking policy]].
+
  
 
You can use [[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Caching/Expiration|cache invalidation]] to improve cache coordination efficiency.
 
You can use [[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Caching/Expiration|cache invalidation]] to improve cache coordination efficiency.
 
  
  

Revision as of 15:29, 17 May 2012

EclipseLink JPA

Clustering Cache Coordination

An application cluster is a set of middle tier server machines or VMs servicing requests for a single application, or set of applications. Multiple servers are used to increase the scalability of the application and/or to provide fault tolerance and high availability. Typically the same application will be deployed to all of the servers in the cluster and application requests will be load balanced across the set of servers. The application cluster will access a single database, or a database cluster. An application cluster may allow new servers to be added to increase scalability, and for servers to be removed such as updates and servicing.

Application clusters can consist of Java EE servers, web containers, or Java server applications.

EclipseLink can function in any clustered environment. The main issue in a clustered environment is utilizing a shared persistence unit (L2) cache. If you are using a shared cache (enabled by default in EclipseLink), then each server will maintain its own cache, and each caches data can get out of sync with the other servers and the database.

EclipseLink provides cache coordination in a clustered environment to ensure the servers caches are is sync.

There are also many other solutions to caching in a clustered environment, including:

  • Disable the shared cache (through setting @Cacheable(false), or @Cache(isolation=ISOLATED)).
  • Only cache read-only objects.
  • Set a cache invalidation timeout to reduce stale data.
  • Use refreshing on objects/queries when fresh data is required.
  • Use optimistic locking to ensure write consistency (writes on stale data will fail, and will automatically invalidate the cache).
  • Use a distributed cache (such as Oracle TopLink Grid's integration of EclipseLink with Oracle Coherence).
  • Use database events to invalidate changed data in the cache (such as EclipseLink' support for Oracle DCN/QCN).
  • Use cache coordination in EclipseLink (discussed in this section.

Cache coordination enables a set of persistence units deployed to different servers in the cluster (or on the same server) to synchronize their changes. Cache coordination works by each persistence unit on each server in the cluster being able to broadcast notification of transactional object changes to the other persistence units in the cluster. EclipseLink supports cache coordination over RMI and JMS. The cache coordination framework is also extensible so other options could be developed.

We recommend that you use cache coordination with an optimistic locking policy.

You can use cache invalidation to improve cache coordination efficiency.


Eclipselink-logo.gif
Version: 2.4 DRAFT
Other versions...