Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Implementing ARC: For Fun, Not Profit

Implementing ARC: For Fun, Not Profit

This is a talk about implementing an adaptive replacement cache (ARC)
in haskell. This talk was presented at FP-Syd, July 2015.

Mark Hibberd

July 22, 2015
Tweet

More Decks by Mark Hibberd

Other Decks in Programming

Transcript

  1. “Yea, from the table of my memory, I'll wipe away

    all trivial fond records” William Shakespeare - Hamlet, Act I, Scene IV
  2. “We are therefore forced to recognize the possibility of constructing

    a hierarchy of memories, each of which has greater capacity than the preceding but which is less quickly accessible.” A. W. Burks, H. H. Goldstine, J. von Neumann: - Preliminary Discussion of the Logical Design of Electronic Computing Instrument, Part I, Vol. I, Report prepared for the U.S. Army Ord. Dept.
  3. Hybrid LRU + LFU Lots of attempts Most have logarithmic

    time complexity *very bad* for general purpose (tuning)
  4. ARC Combines frequency and recency in the most optimal way

    for routing money from your pocket to
  5. L1 L2 MRU LRU LRU MRU T1 B1 T2 T2:

    Cached keys in L2 ARC
  6. B2: Tracked (but not cached) keys in L2 L1 L2

    MRU LRU LRU MRU T1 B1 T2 B2 ARC
  7. 1. If we get a hit in T1 or T2

    do nothing L1 L2 MRU LRU LRU MRU T1 B1 T2 B2 ARC
  8. 2. If we get a hit in B1 increase size

    of T1 L1 L2 MRU LRU LRU MRU T1 B1 T2 B2 ARC
  9. 2. If we get a hit in B1 increase size

    of T1 L1 L2 MRU LRU LRU MRU T1 B1 T2 B2 ARC
  10. 3. If we get a hit in B2 decrease size

    of T1 L1 L2 MRU LRU LRU MRU T1 B1 T2 B2 ARC
  11. 3. If we get a hit in B2 decrease size

    of T1 L1 L2 MRU LRU LRU MRU T1 B1 T2 B2 ARC
  12. ARC This is interesting because… It is relatively easy to

    understand Basically LRU with an extra directory Easy to adapt LRU like algorithms ( https://dl.dropboxusercontent.com/u/91714474/Papers/oneup.pdf )
  13. L2 ARC ARC L2 ARC GET /user/1 L2 ARC NETWORK

    ARC Miss L2 ARC Miss Respond & Update L2 ARC
  14. L2 ARC ARC L2 ARC GET /user/1 L2 ARC NETWORK

    ARC Miss L2 ARC Miss Respond & Update L2 ARC Respond & Update ARC
  15. L2 ARC ARC L2 ARC GET /user/1 L2 ARC NETWORK

    ARC Miss L2 ARC Miss Respond & Update L2 ARC Respond & Update ARC
  16. L2 ARC: Challenges This doesn’t work If not careful about

    updating L2 ARC can bottleneck reads everywhere
  17. L2 ARC ARC L2 ARC GET /user/1 L2 ARC NETWORK

    ARC Miss L2 ARC Miss Respond & Update L2 ARC Respond & Update ARC
  18. L2 ARC ARC L2 ARC GET /user/1 L2 ARC NETWORK

    ARC Miss L2 ARC Miss Respond Respond & Update ARC
  19. L2 ARC ARC L2 ARC GET /user/1 L2 ARC NETWORK

    ARC Miss L2 ARC Miss Respond & Queue Respond & Update ARC WRITE
  20. L2 ARC ARC L2 ARC GET /user/1 L2 ARC NETWORK

    ARC Miss L2 ARC Miss Respond & Queue Respond & Update ARC WRITE Async L2 ARC update
  21. L2 ARC ARC L2 ARC GET /user/1 L2 ARC NETWORK

    ARC Miss L2 ARC Miss Respond & Queue Respond & Update ARC WRITE Async L2 ARC update Very prepared to drop L2 updates on the floor