Caching Strategies for an Erlang Based Web Stack

1,166 views

Published on

Summary of the different caching techniques in a high traffic web architecture, including pros, cons and use cases for each solution. Representative issues spotted in some of the caching approaches will be shared as well.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,166
On SlideShare
0
From Embeds
0
Number of Embeds
76
Actions
Shares
0
Downloads
10
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Caching Strategies for an Erlang Based Web Stack

  1. 1. Caching in an Erlang HTTP stack Enrique Paz @quiquepaz 1/33
  2. 2. Introduction About Me • Software Architect • Passionate Erlang developer • Testing enthusiast • Love beautiful code! 2/33
  3. 3. Introduction What I won’t talk about Not Covered: • Client Side Caching • Caching Proxies • CDN Acceleration 3/33
  4. 4. Introduction About Spilgames 4/33
  5. 5. Introduction About Spilgames 5/33
  6. 6. Introduction About Spilgames 6/33
  7. 7. Why Caching? 7/33
  8. 8. Why Caching? For Performance • To avoid disk/DB access • To avoid calculations • To avoid resource bottlenecks 8/33
  9. 9. Why Caching? For Safety • To reduce backend load • To mitigate outages impact 9/33
  10. 10. Careful! Do Not Depend On Cache! 10/33
  11. 11. Careful! Do Not Depend On Cache! Common pitfalls • Caching layers • Deployments and cold start misses • Server maintenance (on caching pools) • Cache flushing for debugging 11/33
  12. 12. Choosing Your Caching System Considerations • Dataset & Entry size • Should it survive restart? Distribution VS replication 12/33
  13. 13. Choosing Your Caching System Considerations • Amount of different keys • Request & Update Frequency Validity & eviction strategies 13/33
  14. 14. Choosing Your Caching System Considerations • Caching Error Values If done, how to recover quickly? If not done, what about overload? 14/33
  15. 15. Choosing Your Caching System Two Proposals 15/33
  16. 16. Memcached + erl-memcache Good For • Not reinventing the wheel • Distributed caching • Caching outside the node • System Administrators 16/33
  17. 17. Memcached + erl-memcache How does it work? erl-memcache • Memcached • Pool of tcp connections • Memcached binary protocol • Detailed memory management • If local, memcached can be supervised 17/33
  18. 18. Memcached + erl-memcache How does it work? 18/33
  19. 19. Memcached + erl-memcache Used At Spilgames For • Minimizing disk/DB access in Spilgames Storage Platform • https://github.com/spilgames/erl-memcache 19/33
  20. 20. erl-cache Good For erl-cache • In node caching (small datasets) • Concurrency + long lived data • Per key caching strategies • Error awareness • Non intrusive memoization 20/33
  21. 21. erl-cache How does it work? • gen_servers with protected ETSs • Per cache server stats • Periodic eviction • Auto refresh overdue entries 21/33
  22. 22. erl-cache How does it work? • start_cache(Cache, DefaultOpts) • set(Cache, Key, Value, Opts) • stop_cache(Cache) • evict(Cache, Key) • get(Cache, Key, Opts) • get_stats(Cache) ?CACHE( s1 , [ { w a i t _ f o r _ r e f r e s h , f a l s e } ] ) . o p e r a t e ( I n p u t ) −> { ok , Output } = extra_complex_op ( I n p u t ) , Output . 22/33
  23. 23. erl-cache Flexibility Configuration per server: • validity & eviction times • refresh_callback • wait_for_refresh • sync or async set & evict • is_error_callback • error_validity 23/33
  24. 24. erl-cache Flexibility 24/33
  25. 25. erl-cache Used At Spilgames For • Avoiding inline expensive calculations • Protecting the app running the bussiness logic • https://github.com/spilgames/erl-cache 25/33
  26. 26. erl-cache Used At Spilgames For 26/33
  27. 27. erl-cache Used At Spilgames For 27/33
  28. 28. erl-cache Used At Spilgames For 28/33
  29. 29. Summing Up 29/33
  30. 30. Summing Up 30/33
  31. 31. Summing Up What We’ve Used • Poolboy for worker pools • Lager for logging 31/33
  32. 32. Summing Up What We’ve Contributed • http://github.com/spilgames/erl-memcache • http://github.com/spilgames/erl-cache • http://github.com/spilgames/erl-decorator-pt 32/33
  33. 33. Summing Up Questions? 33/33

×