About Caching

  • View

  • Download

Embed Size (px)

Text of About Caching

  • About CachingWeng Wei, Dec 2014

  • Purpose of Caching

    Different accessing speed of different medium

    In-Process > Memory > Network > Disk

    Cache for Performance Optimization

  • Web Page Cache

    Browser Cache

    etag / lastmodified / max-age

    Server Cache

    memcached: Full page/pagelet cache

    Donut Cache: Layout cache

  • memcached

  • Cache within Request

  • Read-Through Cache

  • memcached issues Deployment

    modifying nodes in cluster

    Duplicated call to backend when cache miss on multiple client


    Network latency

    Memory slot

    CAS: check and save

    Mainly used for Read-through cache

  • GroupCache https://github.com/golang/groupcache

    No separated deployment required

    singleflight builtin: avoid duplicated call to backend

    Better performance

    No network IO

    No CAS

    Go 1.4 Continuous Stack: fix memslot issue

  • Write Though

  • Ideally

    ZERO read to backend

    Only write

    Data warm up + complete write-through cache

  • Complete Write-Through

    Available API for application

    Can support SQL

    select * from users where sex = f order by createAt limit 10, 10

  • Implementation Examples



  • GroupCache + Write-Throughhttps://github.com/Wuvist/groupcache/commits/group_delete

  • Phil Karlton

    There are only two hard things in Computer Science: cache invalidation and naming things.

  • Easy to implementeventual consistency

    AtomicDistributed transaction is difficult


    System provision is more difficult


  • Which is faster?

  • proper stress test to confirm!

  • Connection Pool

    Pool is also a kind of cache

    Database connection pool

    Application connection pool

    php FPM / rails unicorn

  • How to release connection MRU or LRU

  • Multiple Facebook teams spent two years


  • Q & A