Caching In Java- Best Practises and Pitfalls

4,306 views

Published on

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.

Published in: Technology, Education
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,306
On SlideShare
0
From Embeds
0
Number of Embeds
26
Actions
Shares
0
Downloads
113
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Caching In Java- Best Practises and Pitfalls

  1. 1. -Hariharan Anantharaman Architect,Cognizant Technology Solutions Founder, Hobbyshopindia.com Hariharan.anantharaman@gmail.com
  2. 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 JUG-Chennai 2
  3. 3. JUG-Chennai 3
  4. 4.  Serializable Java Objects  Stored In-Memory or File based  Key – Value Pairs  Scale of the Application determines the solution JUG-Chennai 4
  5. 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 JUG-Chennai 5 Determining Factors • TTL (Time to Live) • Frequency of Access • Frequency of Update • Deployment Architecture • Scalability of the systems • Object Size • Heap Memory Availability
  6. 6. JUG-Chennai 6
  7. 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 JUG-Chennai 7 Things to be Considered • Clustered Environments • Session Replication • Distributed Servers • Failover Scenarios • Object Replication, Garbage Collection • Effective Memory Utilization
  8. 8.  ICacheManager  CaCheManagerImpl  put(Key ,Value)  get(Key )  replace(Key ,Value)  delete(Key ) JUG-Chennai 8
  9. 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 JUG-Chennai 9
  10. 10.  Profiler Tool  Java.lang.instrument.Instrumentation Cache Population Strategies  Eager Fetch  Lazy Load JUG-Chennai 10
  11. 11. Open Source/Free  EhCache  JCS  JBossCache  MemaCache JUG-Chennai 11 Commercial/Properiatery Solutions • TerraCotta BigMemorys • IBM Dynacache(Shipped with Websphere) • IBM Extreme Scale
  12. 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 JUG-Chennai 12
  13. 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 JUG-Chennai 13
  14. 14. JUG-Chennai 14
  15. 15.  Predominantly based on Memacache  Available with all major cloud providers  Provides easy scalability, recovery etc JUG-Chennai 15
  16. 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. JUG-Chennai 16
  17. 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 JUG-Chennai 17

×