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. DisclaimerThe next stepAs in : what you will be doing in the futureNot as in : go home and run it ;-)Language of choice : PHPBut : think Perl, Python, Ruby, Java, .Net, 3. Who am I ?Wim Godden (@wimgtr) 4. Where I'm from 5. Where I'm from 6. Where I'm from 7. Where I'm from 8. Where I'm from 9. Where I'm from 10. My town 11. My town 12. Belgium the traffic 13. 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 14. Who are you ?Developers ?System/network engineers ?Managers ? 15. To understand the presentUnderstand the past 16. The Stone AgeNew blog post by : caveman003 17. Pre-dynamic : draw it and make html 18. The Egyptian Era 19. Old-school dynamic : 'rebuild-every-time' 20. The Industrial Revolution 21. Dynamic : let's cache 22. Extra ! Extra ! 23. Dynamic content in static content 24. The Modern Era 25. More load, more webservers 26. Pushing updates to cache 27. Today 28. Adding reverse proxy caching 29. Typical website structureHeaderLatest newsArticle content pagePage contentNavigation 30. Caching blocks with individual TTLsTop header(TTL = 2h)Latest newsArticle content pagePage contentNavigation(TTL = 1h) 31. Caching blocks with individual TTLsTop header(TTL = 2h)Latest news (TTL = 2m)Article content pagePage content (TTL = 30m)Navigation(TTL = 1h) 32. ESI how it worksGET /page GET /page 33. ESI how it worksGET /page GET /page...

... 34. ESI how it worksGET /top

Login

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

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

Login

... 37. 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 38. ESI no caching on user-specific content ?Logged in as : Wim Godden5 messagesTTL = 0s ?TTL=1h TTL = 5min 39. Error... does not compute ! 40. Back in 2010 41. No more backendGET /pageDB 42. No more backendGET /page 43. NginxWeb serverReverse proxyLightweight, fastLow memory footprint14.54% of all Websites 44. NginxNo threads, event-drivenUses epoll / kqueue20000 active connections = normal20000 req/sec = normal 45. ESI on NginxLogged in as : Wim Godden5 messagesMenu NEWS 46. ESI SLIC on NginxLogged in as : Wim Godden5 messagesMenu NEWS 47. Requesting /page (1st time)NginxShared memory1234/page/page 48. Requesting /page SLIC subrequests (1st time)Nginx123/menu/news/top (with session cookie)/menu/news/top (in SLIC session) 49. Requesting /page (next time)NginxShared memory 12/page/page/menu/news/top (in SLIC session) 50. SLIC on NginxLogged in as : Wim Godden5 messages ??? 51. New message is sent...POST /sendDBinsert into...set(...)top (in SLIC session) 52. 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 53. News addedaddnews() methodDBinsert into...set(...)Memcache key /news 54. How many Memcached requests ?Logged in as : Wim Godden5 messages 55. First release : ESIPart of the ESI 1.0 specOnly relevant features implementedExtension for dynamic session supportBut : unavailable for copyright reasons 56. Rebuilt from scratch : SLICControl structures : if/else, switch/case, foreachVariable handlingStrings : concatenation, substring, Exception handling, header manipulation, JSON support ! 57. SLIC code samplesYou are logged in as : You are logged in as : 58. SLIC code samples

59. SLIC code samples 60. Approaches full blockLogged in as : Wim Godden

You are logged in as :

You have 5 messages

5 messagestop_31 61. Approaches individual variablesLogged in as : Wim Godden

You are logged in as :

You have messages

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

You are logged in as :

You have messages

63. 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 64. Identifying the userCookie :PHPSESSID =jpsidc1po35sq9q3og4f3hi6e2Nginx + SLIC4g3e2t UserID_jpsidc1po35sq9q3og4f3hi6e2 65. Retrieving user specific contentNginx + SLICget userData_432Cookie :PHPSESSID =jpsidc1po35sq9q3og4f3hi6e2 66. Why Nginx ?Native Memcached supportExcellent and superfast subrequest systemIncluding parallel subrequestsHandles thousands of connections per workerWith minimal memory footprintIntegrates with php-fpmAdditional features (chroot, slow request log, offline processing, ...)Graceful rolling upgrades 67. What's the result ? 68. 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 69. Why is it so much faster ? 70. A real example : vBulletin 71. A real example : vBulletinPostisAdmin session variableisModerator session variable 72. A real example : vBulletinDB Server Load Web Server Load Max Requests/sec (1 = 282)35302520151050Standard installWith MemcachedNginx + SCL + memcached 73. 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 74. AvailabilityGood news :It will become Open SourceThe concept is solid : ESI version stable at 4 customersBad news :First customer holds copyrightsTotal rebuild Open Source releaseNo current projects, so spare timeAnyone feel like sponsoring ?Beta : October !Stable : January 75. So... 76. Questions ? 77. Questions ? 78. ContactTwitter @wimgtrWeb http://techblog.wimgodden.beSlides http://www.slideshare.net/wimgE-mail [email protected]