WHITE PAPER
J u n e 2 0 1 0
Oracle Coherence cache for a high performance eCommerce Application | June 2010
TABLE OF CONTENTS
Abstract 3
Abbreviations 3
Challenges in Ecommerce Application 4
Caching solution – which one to use? 5
Coherence 6
Cache Topologies 7
Coherence Cache Settings 7
Coherence Extend 11
Coherence Configuration 14
Best Practices 18
Common Issues 18
Conclusion 20
Reference 20
© 2010, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author, all rights reserved.
Oracle Coherence cache for a high performance eCommerce Application | June 2010
Abstract
This document discusses how the in-memory Data-Grid based on
Oracle’s Coherence product can be leveraged to implement a very high
performing and highly-scalable e-commerce application where it provides
the basic knowledge for understanding, planning and setting-up coherence
Data-Grid(s) and then also touches-upon a few critical tasks involved in the
implementation such as setting the appropriate cache size and configuring the
relevant cache parameters. Finally, the document covers typical issues which
can be encountered during implementation and the suggested resolutions
for them.
Abbreviations
This section lists abbreviations required to accurately interpret the details in
this document.
• GC – Garbage Collection
© 2010, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author, all rights reserved.
Oracle Coherence cache for a high performance eCommerce Application | June 2010
Mostly, read only data plays a major role in the e-commerce application
performance. Number of JVM per process and Caching read only data will
reduce the database access bottlenecks and performance impact. By default
ORM supports orthogonal caching. Each caching technique has pros and
cons. Example of OpenJPA, where extremely high frequency of data reads
causes the thread contention and also a different object instance even for the
same entity. Application caching is explicitly having logic in the application
layer for retrieving or populating cache. Content cache is the example for
application caching.
Caching more data in the application memory will impact more GC and
will directly lead to performance degradation. Distributed caching is the best
option for a large amount of cached data. Avoiding unnecessary caching,
optimizing the heap memory size and finding suitable garbage collector will
reduce the frequent GC.
Size of read only data will differ based on the number of countries,
language, vendor and sites used in the application. The example below
explains the predicted growth of the product content data in the ecommerce
application.
© 2010, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author, all rights reserved.
Oracle Coherence cache for a high performance eCommerce Application | June 2010
b) WhirlyCache
Whirlycache is a fast, configurable in-memory object cache for Java. Whirly
cache is open source software. It can be used, to increase the performance of
a website or an application by caching objects.
c) Jofti
Jofti is a simple to use, faster object indexing and searching solution for
Objects in a Caching layer or storage structure that supports the Map
interface.
d) EHCache
A replacement for JCS, EHCache started out as some patches for JCS to
correct threading and memory leak problems. EHCache is faster than JCS
and acts as a pluggable cache for Hibernate 2.1.
e) JBossCache
JBoss Cache is a product designed to cache frequently accessed Java objects
in order to dramatically improve the performance of e-business applications.
By avoiding unnecessary database access, JBoss Cache decreases network
traffic and increases the scalability of applications.
f) OSCache
OSCache is a widely used, high performance J2EE caching solution. Its
features include fast in-memory caching, persistent caching, clustering
support, flexible caching System, comprehensive API, exception handling,
cache flushing, portable caching and i18n aware.
g) OpenJPA
ORM products also have in-built caching solutions. OpenJPA and hibernates
are the best example of this. Apache OpenJPA is a Java persistence framework
that can be used as a stand-alone POJO persistence layer or integrated into
any Java EE compliant container and many other lightweight frameworks.
© 2010, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author, all rights reserved.
Oracle Coherence cache for a high performance eCommerce Application | June 2010
h) Hibernate
Coherence
What is Coherence?
Why Coherence?
© 2010, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author, all rights reserved.
Oracle Coherence cache for a high performance eCommerce Application | June 2010
Cache Topologies
Coherence supports three types of caches. These are Distributed, Near and
Replicated cache. Distributed cache is each node in the server containing a
unique set of application data in the cache. To scale the capacity of cache,
increase the nodes in the cluster. Any type of cache will involve serialization
/de-serialization and network transfers for application data read and write
access in the cache. Distributed cache is best when the application requires
heavy volume of read and write application data.
Near cache is each client node containing small amount of data in the local
cache and larger amount of data in the distributed cache and these caches
are synchronized with each other. There is some overhead involved with
synchronizing the caches.
Replicated cache is each node in the cluster will contains all the application
data in the cache. Replicated cache is best when application requires less
application data and highly read access from cache.
Sizing
When trying to determine how many systems and how many JVMs per
system are required, the coherence cache is a good starting point to determine
how much data need to cache in the application. Once this is calculated all
other factors can be decided later.
Initially find out the cached object size by perform the below stapes:
© 2010, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author, all rights reserved.
Oracle Coherence cache for a high performance eCommerce Application | June 2010
• Once the application is started, connect the coherence grid server JVM
using JConsole and the mbean tab find out grid server cached objects
size and count. Single cached object size can be calculated using this
information.
Serialization
Network is the important factor in the coherence, since over the wire
lots of data will be transferred and all the clustered instances will be
intercommunicated. Serializing the application objects in the cache will
give better performance. POF serializer is the best one, as it consumes less
serialization /deserialization time. Application objects should implement the
PortableObject interface and the PortableObjectSerializer implementation
is used as the PofSerializer.
Invalidating objects in the cache will sync the local cache with grid server
cache. Coherence has pre-defined events for the invalidation strategy. Based
on the invalidation strategy local cache will be updated from back cache.
Invalidation strategies are Listen None, Listen Present, Listen All and
Listen Auto.
• Listen none strategy is not to listen for invalidation objects. Based on the
eviction policy data freshness will be maintained in the cache.
• Listen present strategy is local cache will listen to the back cache only
objects in the local cache.
• Listen all strategy will listen to the back cache for the all the objects.
• Listen auto strategy is local cache automatically use listen present and listen
all based on the cache statistics. This is the default invalidation strategy.
© 2010, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author, all rights reserved.
Oracle Coherence cache for a high performance eCommerce Application | June 2010
Mainly, eviction is used to free the memory in the cache and remove the unused
objects in the cache. Eviction policies are LRU, LFU and HYBRID.
• LRU is where cache will keep the objects those are all least recently
used only.
• LFU is the least frequently used eviction policy that chooses which entries
to evict based on how often they are being accessed, evicting those that are
accessed least first.
• HYBRID is a cache that will keep the objects those are all how often
and recently accessed, evicting those that are accessed least frequently
and were not accessed for the longest period first. This is the default
eviction policy.
TCMP Protocol
a) Multicast
• Cluster heartbeat: The most senior member in the cluster issues a periodic
heartbeat via multi-cast; the rate is configurable and defaults to once per
second.
b) Unicast
• Under some circumstances, a message may be sent via unicast even if the
message is directed to multiple members. This is done to shape traffic flow
and to reduce CPU load in very large clusters.
© 2010, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author, all rights reserved.
Oracle Coherence cache for a high performance eCommerce Application | June 2010
c) TCP
Multicast Vs WKA
Node discovery can be done using multicast or well known address. The
choice is made based on the network topology. If coherence clients and
servers are in the same subnet then multicast is the best, since it will use less
configuration. If clients and servers are located in the different subnet i.e.
datacenters or network didn’t support multicast packets then well known
address is used with predefined configuration. Disadvantage of WKA is to
update the configurations and restart all the servers and clients for adding
new coherence server to the cluster.
The element multicast listener is used to define the address and port that
cluster will use for cluster wide and point to multipoint communications. All
the clients and servers should use the same address and port. This multicast
IP address and port will be used for socket listening or publishing. Sample
configuration file for multicast is as follows:
<multicast-listener>
<address system-property=”tangosol.coherence.clusteraddress”>xx.xx.xx.xx</address>
<port system-property=”tangosol.coherence.clusterport”>9000</port>
<time-to-live system-property=”tangosol.coherence.ttl”>1</time-to-live>
<packet-buffer>
<maximum-packets>64</maximum-packets>
</packet-buffer>
<priority>8</priority>
<join-timeout-milliseconds>30000</join-timeout-milliseconds>
<multicast-threshold-percent>25</multicast-threshold-percent>
</multicast-listener>
© 2010, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author, all rights reserved.
10
Oracle Coherence cache for a high performance eCommerce Application | June 2010
The element socket address is used to define the WKA list IP addresses and
ports. If one or more WKA is specified, for a member to join the cluster it will
either have to be WKA or there will have to be at least one WKA member
running. If this is empty or unspecified then multicast communication will
be used. Sample configuration file for WKA is as follows:
<unicast-listener>
<well-known-addresses>
<socket-address id=”1”>
<address>xx.xx.xx.xx</address>
<port>8088</port>
</socket-address>
</well-known-addresses>
</unicast-listener>
Coherence Extend
Coherence Extend extends the reach of the Coherence TCMP cluster to a
wider ranch of consumers, including desktops, remote servers and machines
located across WAN connections. Typical uses of coherence extend include
providing desktop applications with access to coherence caches and coherence
cluster “bridges” that link together multiple coherence clusters connected
via a high-latency, unreliable WAN.
Transport bindings for these protocols are extend JMS and extend TCP.
Extend JMS use existing JMS infrastructure to connect to the server. Extend
TCP provides high performance and scalable TCP/IP based communication
layer to connect to the server.
© 2010, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author, all rights reserved.
11
Oracle Coherence cache for a high performance eCommerce Application | June 2010
Example
Two data centers have the same application and data. One data center data
is updated through application then other data center data is replicated by
streaming in the backend database. Same functionality may be required in
the application cache level also. This is achieved by coherence extend feature.
Define one data center is a master server and other data center as a replica
server. Here is the example of <remote-cache-scheme> element for master
server configuration file as follows:
<remote-cache-scheme>
<scheme-name>example-remote</scheme-name>
<service-name>RemoteCache</service-name>
<initiator-config>
<tcp-initiator>
<remote-addresses>
<socket-address>
<address>hostname </address>
<port>9099</port>
</socket-address>
</remote-addresses>
</tcp-initiator>
<outgoing-message-handler>
<request-timeout>10s</request-timeout>
</outgoing-message-handler>
</initiator-config>
</remote-cache-scheme>
© 2010, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author, all rights reserved.
12
Oracle Coherence cache for a high performance eCommerce Application | June 2010
<proxy-scheme>
<service-name>Proxy</service-name>
<thread-count>4</thread-count>
<acceptor-config>
<tcp-acceptor>
<local-address>
<address>hostname</address>
<port>9099</port>
<reusable>true</reusable>
</local-address>
</tcp-acceptor>
</acceptor-config>
<autostart>true</autostart>
</proxy-scheme>
© 2010, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author, all rights reserved.
13
Oracle Coherence cache for a high performance eCommerce Application | June 2010
Coherence Configuration
Three configuration files are used in the coherence. Files are tangosol
configuration xml, cache configuration xml and pof configuration xml.
Tangosol configuration xml file will specify the operational and runtime
elements that control clustering, communication and data management
services and override the tangosol configuration xml file in the java argument
by using -Dtangosol.coherence.override. Example xml file as follows:
<?xml version=’1.0’?>
<coherence>
<cluster-config>
<member-identity>
<cluster-name system-property=”tangosol.coherence.cluster”>example-node1</cluster-name>
</member-identity>
<unicast-listener>
<well-known-addresses>
<socket-address id=”1”>
<address>xx.xx.xx.xx</address>
<port>8088</port>
</socket-address>
</well-known-addresses>
</unicast-listener>
<packet-publisher>
<packet-delivery>
<timeout-milliseconds>60000</timeout-milliseconds>
</packet-delivery>
</packet-publisher>
<service-guardian>
<timeout-milliseconds system-property=”tangosol.coherence.guard.timeout”>65000</timeout-milliseconds>
</service-guardian>
</cluster-config>
<logging-config>
<severity-level system-property=”tangosol.coherence.log.level”>5</severity-level>
<character-limit system-property=”tangosol.coherence.log.limit”>1048576</character-limit>
</logging-config>
</coherence>
© 2010, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author, all rights reserved.
14
Oracle Coherence cache for a high performance eCommerce Application | June 2010
Coherence cache attributes and settings are defined in the cache configuration
xml file. Cache attributes are cache type, cache invalidation strategy, cache
policy, type of serialization and objects count of the cache. Specify the cache
configuration xml file in the java argument by using -Dtangosol.coherence.
cacheconfig. Example xml file as follows:
<?xml version=”1.0”?>
<cache-config>
<caching-scheme-mapping>
<cache-mapping>
<cache-name>demoCache</cache-name>
<scheme-name>demo-near-content</scheme-name>
</cache-mapping>
</caching-scheme-mapping>
<caching-schemes>
<distributed-scheme>
<scheme-name>distributed-content</scheme-name>
<service-name>DistributedCache-pof</service-name>
<serializer>
<class-name>com.tangosol.io.pof.ConfigurablePofContext
</class-name>
<init-params>
<init-param>
<param-value>C:/coherence/pof-config.xml</param-value>
<param-type>String</param-type>
</init-param>
</init-params>
</serializer>
<backup-count>1</backup-count>
<thread-count>8</thread-count>
<backing-map-scheme>
<local-scheme>
<scheme-ref>dist-binary-backing-map</scheme-ref>
</local-scheme>
</backing-map-scheme>
<autostart>true</autostart>
</distributed-scheme>
© 2010, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author, all rights reserved.
15
Oracle Coherence cache for a high performance eCommerce Application | June 2010
<local-scheme>
<scheme-name>dist-binary-front-map</scheme-name>
<eviction-policy>HYBRID</eviction-policy>
<high-units>50000</high-units>
<expiry-delay>1h</expiry-delay>
</local-scheme>
<local-scheme>
<scheme-name>dist-binary-backing-map</scheme-name>
<eviction-policy>HYBRID</eviction-policy>
<high-units>1000000</high-units>
<expiry-delay>1h</expiry-delay>
</local-scheme>
<near-scheme>
<scheme-name>demo-near-content</scheme-name>
<front-scheme>
<local-scheme>
<scheme-ref>dist-binary-front-map</scheme-ref>
</local-scheme>
</front-scheme>
<back-scheme>
<distributed-scheme>
<scheme-ref>distributed-content</scheme-ref>
</distributed-scheme>
</back-scheme>
<invalidation-strategy>all</invalidation-strategy>
<autostart>true</autostart>
</near-scheme>
</caching-schemes>
</cache-config>
© 2010, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author, all rights reserved.
16
Oracle Coherence cache for a high performance eCommerce Application | June 2010
This xml file is used to define the objects to serialize and deserialized by
using pof serializer. The name and location of this file can be configured
in the coherence cache configuration xml file or by the system property
tangosol.pof.config. It is recommended that all the nodes within a cluster use
identical POF user type descriptors. Example file as follows:
<?xml version=”1.0”?>
<!DOCTYPE pof-config SYSTEM “pof-config.dtd”>
<pof-config>
<user-type-list>
<include>coherence-pof-config.xml</include>
<user-type>
<type-id>1004</type-id>
<class-name>com.example.test.SampleOneDataImpl</class-name>
</user-type>
<user-type>
<type-id>1005</type-id>
<class-name> com.example.test.SampleTwoDataImpl</class-name>
</user-type>
<user-type>
<type-id>1006</type-id>
<class-name> com.example.test.SampleThreeDataImpl </class-name>
</user-type>
</user-type-list>
</pof-config>
uidPk = reader.readLong(0);
value = reader.readString(1);
writer.writeLong(0, uidPk);
writer.writeString(1, value);
writer.writeObject(2, contentType);
© 2010, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author, all rights reserved.
17
Oracle Coherence cache for a high performance eCommerce Application | June 2010
Best Practices
This section describes the best practices to follow while implementing the
coherence cache in the application.
Cache Warm Up
Preloading all the objects in the coherence cache will give better performance
in the application start up using cache warm up utility. Write a small program
that warms application cache server by causing it to fetch the data directly
from the source which in most cases is the database. This warm up program
should be run in the application start up process.
Common Issues
This section describes the common issues encountered when implementing
coherence. This section guides the reader how to address these issues and
solve them.
If this cluster name is not properly defined, then some other application
which is also using coherence within the network will be participated in the
coherence cluster. This will lead to weird behavior in the application like
optimistic lock issue from the DAO layer or dead lock threads.
© 2010, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author, all rights reserved.
18
Oracle Coherence cache for a high performance eCommerce Application | June 2010
Some switches such as the Cisco 6500 series support configuration the
amount of buffer space available to each ethernet port or ASIC. In high
load applications it may be necessary to increase the default buffer space. On
Cisco this can be accomplished by executing:
fabric buffer-reserve high
Some other switches contact with oracle coherence.
© 2010, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author, all rights reserved.
19
Oracle Coherence cache for a high performance eCommerce Application | June 2010
12. Conclusion
Coherence has extensive features like dynamic high availability, automatic
load balancing, transactional consistency, capacity on demand, grid wide
JMX for management and monitoring and true linear scalability. It is
important to have a matured and comprehensive caching solution to meet
the non-functional requirements (performance & scalability) of a typical e-
commerce application, and if the budget can afford, Coherence is definitely
a reliable proposition to meet the non-functional objectives.
13. Reference
Website:
http://www.oracle.com/technology/products/coherence/index.html
http://www.manageability.org/blog/stuff/distributed-cache-java
http://java-source.net/open-source/cache-solutions
© 2010, HCL Technologies. Reproduction Prohibited. This document is protected under Copyright by the Author, all rights reserved.
20
ENGINEERING AND Hello, I’m from HCL’s Engineering and R&D Services. We enable
R&D SERVICES technology led organizations to go to market with innovative products &
solutions. We partner with our customers in building world class products
& creating the associated solution delivery ecosystem to help build market
CUSTOM APPLICATION leadership. Right now, 13000+ of us are developing engineering products,
SERVICES solutions and platforms across Aerospace and Defense, Automotive,
Consumer Electronics, Industrial Manufacturing, Medical Devices,
ENTERPRISE APPLICATION Networking & Telecom, Office Automation, Semiconductor, Servers &
SERVICES Storage for our customers.
For more details contact eootb@hcl.in
ENTERPRISE Follow us on twitter http://twitter.com/hclers and our blog http://ers.
TRANSFORMATION SERVICES hclblogs.com/
Visit our website http://www.hcltech.com/engineering-services/
IT INFRASTRUCTURE
MANAGEMENT
BUSINESS PROCESS
OUTSOURCING
About HCL
About HCL Technologies