Caching fundamentals by Shrikant Vashishtha


Published on

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Caching fundamentals by Shrikant Vashishtha

  1. 1. ShriKant Vashishtha, April 28, 2008 Caching In Enterprise JEE Applications
  2. 2. Why Caching? <ul><li>Performance </li></ul><ul><li>Scalability – Avoid single point of bottleneck </li></ul><ul><li>Reduce network traffic. Do we really need to care about bandwidth? </li></ul><ul><li>CPU processing </li></ul><ul><li>Throughput </li></ul>
  3. 3. Caching in Web Layer <ul><li>Web cache – sits between one or more web servers (known as origin servers) and a/many client(s). For another request for the same URL, Reuses the response that it has, instead of asking the origin server for it again. </li></ul><ul><ul><li>Why? </li></ul></ul><ul><ul><ul><li>Reduces latency </li></ul></ul></ul><ul><ul><ul><li>Reduces network traffic </li></ul></ul></ul><ul><ul><li>Types? </li></ul></ul><ul><ul><ul><li>Browser caching – use HTTP headers to specify the time to refresh </li></ul></ul></ul><ul><ul><ul><li>Proxy caches – large scale caching </li></ul></ul></ul><ul><ul><ul><li>Gateway Caches – deployed by webmasters themselves, to make their sites more scalable, reliable and better performing - Content delivery networks (CDNs) </li></ul></ul></ul>
  4. 4. Caching in Web Layer (contd.) <ul><li>Web page caching at server side (OSCache (graceful error tolerance (eg if an error occurs like your db goes down, you can serve the cached content so people can still surf the site almost without knowing) ) and JSP tags) </li></ul><ul><li>Pure HTML </li></ul><ul><li>Usage of mirror server </li></ul>
  5. 5. Where to cache and when? <ul><li>Memory – frequent usage – low memory consumption </li></ul><ul><li>Disk – lower usage – high memory requirement </li></ul><ul><li>Memory mixed with disk – frequent usage – high memory requirements </li></ul><ul><li>Local database </li></ul><ul><li>HTTP Session – state management in Web applications - Issues in cluster environment - Terracotta </li></ul><ul><li>Caching is not replacement of database. </li></ul>
  6. 6. Caching from solution perspective? <ul><li>Inter-transaction cache </li></ul><ul><li>Intra-transaction cache (to be cleaned-up at the end of every transaction) </li></ul><ul><li>Pre-load the data </li></ul><ul><li>Function Cache – “Function caching is the technique of remembering previous function calls and avoiding the cost of recomputing them. Function caching provides a simple way of implementing dynamic programming algorithms and can provide a facility for incremental computation”. </li></ul>
  7. 7. Challenges of Enterprise Application Caching? <ul><li>Cache refresh in distributed cache </li></ul><ul><ul><li>JGroups </li></ul></ul><ul><ul><li>JMS </li></ul></ul><ul><ul><li>TCP/IP </li></ul></ul><ul><ul><li>RPC </li></ul></ul><ul><ul><li>Grid Computing </li></ul></ul>
  8. 8. Challenges of Enterprise Application Caching? <ul><li>Caching Eviction </li></ul><ul><ul><li>Why do we need it? </li></ul></ul><ul><ul><li>How do we do this? </li></ul></ul><ul><ul><ul><li>Implementing eviction policies </li></ul></ul></ul><ul><ul><ul><ul><li>Least Frequently Used (LFU) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Least Recently Used (LRU) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Adaptive Replacement Cache (ARC) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>First in First Out (FIFO) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Time based eviction </li></ul></ul></ul></ul><ul><ul><ul><li>Which one to chose from? </li></ul></ul></ul><ul><ul><li>Larger heap size? </li></ul></ul><ul><li>The need of standardization – JSR 107 (JCS, FKache etc) </li></ul>
  9. 9. Challenges of Enterprise Application Caching? <ul><li>Caching Monitoring </li></ul><ul><ul><li>Using JSPs </li></ul></ul><ul><ul><li>Using JMX </li></ul></ul>
  10. 10. Useful Statistics
  11. 11. References <ul><li>Modeling the Function Cache for Worst-Case Execution Time Analysis ( ) </li></ul><ul><li>Adaptive replacement cache ( ) </li></ul><ul><li>Evaluation of a group communication middleware for clustered J2EE application servers ( ) </li></ul><ul><li>Web cache reference ( ) </li></ul><ul><li>Caching dynamic content with JSP 2.0 ( ) </li></ul>