Upload
hariharan-anantharaman
View
174
Download
1
Embed Size (px)
DESCRIPTION
This presentation mentions about key concepts of Java side caching and things to consider. It also mentions about popular tools and caching in AWS and Google App Engine.
Citation preview
Caching-Hariharan Anantharaman
Architect,Cognizant Technology SolutionsFounder, Hobbyshopindia.com
JUG-Chennai 2
Get/Access the resource or Data once, use multiple times
Frequently used strategy to improve performance
Approach is language independent Architecture and Design decision. Multiple options available at multiple layers
Need for Speed-Caching
JUG-Chennai 3
Regular N-Tier JEE Architecture
JUG-Chennai 4
Serializable Java Objects Stored In-Memory or File based Key – Value Pairs Scale of the Application determines the
solution
Caching in Java – Basics
JUG-Chennai 5
Static Data◦ State List◦ Countries List
Pseudo Static Data◦ Catalog Data◦ Exchange Rate
Context Specific Data◦ User Profile Data◦ Session Specific Data◦ Data From external Systems
Different Needs, Different Solutions
Use Cases
Determining Factors• TTL (Time to Live)• Frequency of Access• Frequency of Update• Deployment Architecture• Scalability of the systems• Object Size• Heap Memory Availability
JUG-Chennai 6
Cache Solution Overview
JUG-Chennai 7
HashMaps Session Objects Localized On-Memory Cache Intra cluster Distributed Cache (Replicated Cache) Global Distributed Cache JSR 107 has been conceptualized and released on 18 March
2014 replicated cache
Different Approaches
Things to be Considered• Clustered Environments• Session Replication• Distributed Servers• Failover Scenarios• Object Replication, Garbage Collection• Effective Memory Utilization
JUG-Chennai 8
ICacheManager CaCheManagerImpl put(Key ,Value) get(Key ) replace(Key ,Value) delete(Key )
General Implementation Approach
JUG-Chennai 9
Number of parallel sessions Available Heap memory Average Session Duration Number of Global objects to be stored in
Cache Number of transaction specific objects to be
stored in Cache Size of objects to be stored in Cache
Server Memory Cache
JUG-Chennai 10
Profiler Tool Java.lang.instrument.Instrumentation
Cache Population Strategies Eager Fetch Lazy Load
Finding Object Size
JUG-Chennai 11
Open Source/Free EhCache JCS JBossCache MemaCache
Popular Solutions
Commercial/Properiatery Solutions• TerraCotta BigMemorys• IBM Dynacache(Shipped with Websphere)• IBM Extreme Scale
JUG-Chennai 12
Maximum Memory Purge Strategy Reload Scheduled Cache Expiry Algorithm for removing item from
Cache(LRU,FIFO),MRU,Last Access Time etc Object size based cache Removal
Critical Cache Configuration
JUG-Chennai 13
High performance Distributed memory object caching system
Memacache consists of two parts◦ Memacache Server. Separate process running in same
machine as server or running in different machine◦ Memacache Client. Used by Client applications.
Langauage specific client jars are available to work with Memacache
Memacache
JUG-Chennai 14
IBM Extreme Scale
JUG-Chennai 15
Predominantly based on Memacache Available with all major cloud providers Provides easy scalability, recovery etc
Caching in Cloud
JUG-Chennai 16
Based Upon Memache or Redis
Cache clusters consists of multiple cache nodes.
Configured from AWS mgmt console or tools
Redis-◦ A popular open-source in-
memory key-value store that supports data structures such as sorted sets and lists.
◦ ElastiCache supports Redis master / slave replication which can be used to achieve cross AZ redundancy.
Amazon Elastic Cache
JUG-Chennai 17
Provides Two Types of Cache◦ In-Context Cache
Available only for the duration of single HTTP Request Data is present in memory
◦ Memacache Default and Enabled for All applications Faster than datastore, slower than In-context cache By default, a nontransactional context caches all
entities in memcache. Memcache does not support transactions When DB is updated, it needs to be updated explicitly
in Memacache
Google App Engine