When dynamic becomes static - the next step in web caching techniques

download When dynamic becomes static - the next step in web caching techniques

If you can't read please download the document

description

Although tools like Varnish can improve performance and scalability for static sites, when user-specific content is needed, a hit to the PHP/Ruby/Python/.Net backend is still required, causing scalability issues. We’ll look at a brand-new Nginx module which implements an ultra-fast and scalable solution to this problem, changing the way developers think about designing sites with user-specific content.

Transcript of When dynamic becomes static - the next step in web caching techniques

  • 1. When dynamic becomes static(the next step in web caching techniques)Wim GoddenCu.be Solutions@wimgtr

2. Who am I ?Wim Godden (@wimgtr)Founder of Cu.be Solutions (http://cu.be)Open Source developer since 1997Developer of OpenX, PHPCompatibility, PHPConsistent, ...Speaker at Open Source conferences 3. Who are you ?Developers ?System/network engineers ?Managers ? 4. Quick noteWhenever you seefeel free to think 5. To understand the presentUnderstand the past 6. The Stone AgeNew blog post by : caveman003 7. Pre-dynamic : draw it and make html 8. The Egyptian Era 9. Old-school dynamic : 'rebuild-every-time' 10. The Industrial Revolution 11. Dynamic : let's cache 12. Dynamic : let's cache 13. Dynamic : let's cache 14. Extra ! Extra ! 15. Dynamic content in static content 16. Dynamic content in static content 17. Dynamic content in static content 18. The Modern Era 19. More load, more webservers 20. More load, more webservers 21. More load, more webservers 22. More load, more webservers 23. More load, more webservers 24. More load, more webservers 25. More load, more webservers 26. Pushing updates to cache 27. Today 28. Adding reverse proxy caching 29. Adding reverse proxy caching 30. Typical website structureHeaderLatest newsArticle content pagePage contentNavigation 31. Caching blocks with individual TTLsTop header(cache for 2h)Latest newsArticle content pagePage contentNavigation(cache for 1h) 32. Caching blocks with individual cache durationTop header(cache for 2h)Latest news (cache for 2m)Article content pagePage content (cache for 30m)Navigation(cache for 1h) 33. ESI how it worksGET /page GET /page 34. ESI how it worksGET /page GET /page...

... 35. ESI how it worksGET /top

Login

36. ESI how it worksGET /page GET /page...

... 37. ESI how it worksGET /page GET /page...

Login

... 38. Varnish - what can/can't be cached ?Can :Static pagesImages, js, cssStatic parts of pages that don't change often (ESI)Can't :POST requestsVery large files (it's not a file server !)Requests with Set-CookieUser-specific content 39. ESI no caching on user-specific content ?Logged in as : Wim Godden5 messagescache for cache for 5min1hcache for 0s ? 40. Error... does not compute ! 41. Back in 2010 42. Avoid hitting the backendGET /pageDB 43. No more backendGET /page+ SLIC 44. Requesting /page (1st time)NginxShared memory1234/page/page 45. Requesting /page SLIC subrequests (1st time)Nginx123/menu/news/top (with session cookie)/menu/news/top (in SLIC session) 46. Requesting /page (next time)NginxShared memory 12/page/page/menu/news/top (in SLIC session) 47. SLIC on NginxLogged in as : Wim Godden5 messages ??? 48. New message is sent...POST /sendDBinsert into...set(...)top (in SLIC session) 49. AdvantagesNo repeated GET hits to webserver anymore !At login : POST warm up the cache !No repeated hits for user-specific contentNot even for non-specific content 50. News addedaddnews() methodDBinsert into...set(...)Memcache key /news 51. First release : ESIPart of the ESI 1.0 specOnly relevant features implementedExtension for dynamic session supportBut : unavailable for copyright reasons 52. Rebuilt from scratch : SLICControl structures : if/else, switch/case, foreachVariable handlingStrings : concatenation, substring, Exception handling, header manipulation, JSON support ! 53. SLIC code samplesYou are logged in as : 54. SLIC code samples

55. SLIC code samples 56. Approaches full block

You are logged in as : Wim Godden

You have 5 messages

Logged in as : Wim Godden5 messagestop_432 57. Approaches individual variablesLogged in as : Wim Godden

You are logged in as :

You have messages

5 messages 58. Approaches JSONLogged in as : Wim Godden5 messages

You are logged in as :

You have messages

59. Identifying the userIn Nginx configuration :slic_session_cookie Defined by language (or configurable)slic_session_identifier Defined by youExample for PHP :slic_session_cookie PHPSESSIDslic_session_identifier UserID 60. Identifying the userCookie :PHPSESSID =jpsidc1po35sq9q3og4f3hi6e2Nginx + SLIC4g3e2t UserID_jpsidc1po35sq9q3og4f3hi6e2 61. Retrieving user specific contentNginx + SLICget userData_432Cookie :PHPSESSID =jpsidc1po35sq9q3og4f3hi6e2 62. What's the result ? 63. Figures2nd customer :No. of web servers : 72 8No. of db servers : 15 4Total : 87 12 (86% reduction !)Last customer :No. of total servers : +/- 1350Expected reduction : 1350 380Expected savings : 1.5 Million per year 64. Why is it so much faster ? 65. Code changesRequiredTemplate conversionPush-to-DB Push-to-DB + Push-to-CacheChoice :If user is logged in push updates to cacheIf user is not logged in warm up cache on login 66. AvailabilityGood news :The concept is solid : ESI version stable at 4 customersOpen SourceBad news :First customer holds copyrightsTotal rebuildQ2 2015 : v0.1 (include, variable handling, )Final release : Q3 2015Site : http://slic.cu.beCode : Github 67. Some technical detailsWritten in Lua (with LuaJIT)Each SLIC:include is a subrequestGroups cache key requests together for multigetShares cache results across all subrequestsMemcached implementedRedis and others in the pipelineNot RFC compliant yetUnit testedFuture (1.0 or beyond) :Better cache abstractionTemplate compilationTranslation functionality... 68. So... 69. Questions ? 70. Questions ? 71. Thanks !@[email protected]