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 techniquesWim Godden Cu.be Solutions

2. Disclaimer The next stepas in : what you will be doing in the futureNot as in : go home and run it ;-) 3. Who am I ? Wim Godden (@wimgtr) Founder of Cu.be Solutions (http://cu.be) Open source developer since 1997 Developer of OpenX, PHPCompatibility, ... Speaker at PHP and Open Source conferences 4. Who are you ? Developers ? System/network engineers ? Managers ? 5. To understand the present Understand the past 6. The Stone Age New blog post by : caveman003 7. Pre-PHP : draw it and make html 8. The Egyptian Era 9. Old-school PHP : 'rebuild-every-time' 10. The Industrial Revolution 11. PHP : let's cache 12. Extra ! Extra ! 13. PHP : dynamic content in static content 14. The Modern Era 15. PHP : multiple webservers 16. PHP : push updates to cache 17. Today 18. Adding reverse proxy caching 19. Website X with ESI HeaderLatest newsArticle content page Navigation Page content 20. Website X with ESI Header (TTL = 2h) Latest newsArticle content page Navigation (TTL = 1h)Page content 21. Website X with ESI Header (TTL = 2h) Latest news (TTL = 2m)Article content page Navigation (TTL = 1h)Page content (TTL = 30m) 22. Going to /page/id/732 23. Varnish - ESI Perfect for caching pages Article content page In your Varnish config : sub vcl_fetch { if (req.url == "/news") { esi; /* Do ESI processing */ set obj.ttl = 2m; } elseif (req.url == "/nav") { esi; set obj.ttl = 1m; } elseif . . } 24. A simple benchmark 2KByte JPEGApache 2.24210IIS 7.53960Varnish 3.011400 25. A dynamically generated, but static pageApache 2.2 + PHP (3 DB queries)18IIS 7.5 + .Net (3 DB queries)16Varnish 3.011400 26. Varnish - what can/can't be cached ? Can : Static pages Images, js, css Static parts of pages that don't change often (ESI)Can't : POST requests Very large files (it's not a file server !) Requests with Set-Cookie User-specific content 27. ESI no caching on user-specific content ? Logged in as : Wim GoddenTTL = 0s ?TTL=1h5 messagesTTL = 5min 28. Nginx Web server Reverse proxy Lightweight, fast 12.81% of all Websites 29. Nginx No threads, event-driven Uses epoll / kqueue Low memory footprint 10000 active connections = normal 30. ESI on Nginx Logged in as : Wim Godden 5 messagesMenuNEWS 31. ESI SCL on Nginx 32. Requesting /page (1st time)Nginx 1Shared memory /page4/page3 2 33. Requesting /page ESI subrequests (1st time)Nginx 1 2 3/menu /news /top (in ESI session) 34. Requesting /page (next time)Nginx Shared memory1/page2/page /menu /news /top (in ESI session) 35. New message is sent...POST /send o i nt rt e ins...se t(.. .)DBtop (in ESI session) 36. Advantages No repeated GET hits to webserver anymore ! At login : POST warm up the cache ! No repeated hits for user-specific content Not even for non-specific content 37. News addedaddnews() method o i nt rt e ins...se t(.. .)DBMemcache key /news 38. Advantages No repeated GET hits to webserver anymore ! At login : POST warm up the cache ! No repeated hits for user-specific content Not even for non-specific content No TTLs for non-specific content 39. How many Memcache requests ? Logged in as : Wim Godden 5 messages 40. First release : ESI Part of the ESI 1.0 spec Only relevant features implemented Extension for dynamic session support But : unavailable for copyright reasons 41. Rebuilt from scratch : SCL Session-specific Caching Language Language details :Control structures : if/else, switch/case, foreach Variable handling Strings : concatenation, substring, ... 42. SCL code samplesYou are logged in as : You are logged in as : 43. SCL code samples

44. SCL code samples 45. ESI code samples 46. Why Nginx ? Native Memcached support Excellent and superfast subrequest system Including parallel subrequestsHandles thousands of connections per worker With minimal memory footprintIntegrates with php-fpm Additional features (chroot, slow request log, offline processing, ...) Graceful rolling upgrades 47. What's the result ? 48. Figures 2nd customer :No. of web servers : 72 8 No. of db servers : 15 4 Total : 87 12 (86% reduction !)Last customer :No. of total servers : +/- 1350 Expected reduction : 1350 300 Expected savings : 1.6 Million per year 49. Why is it so much faster ? 50. A real example : vBulletin 51. A real example : vBulletinisAdmin session variableThreadisModerator session variable 52. A real example : vBulletin 35302520Standard install With Memcached Nginx + SCL + memcached151050 DB Server LoadWeb Server LoadMax Requests/sec (1 = 282) 53. Availability Good news : It will become Open Source It's solid : ESI version stable at 4 customersBad news : First customer holds copyrights Total rebuild Open Source release No current projects, so spare timeBeta : Dec-Jan Final : Q1-Q2 (on Github !) 54. So... 55. Questions ? 56. Questions ? 57. Contact Twitter Web Slides E-mail@wimgtr http://techblog.wimgodden.be http://www.slideshare.net/wimg [email protected] rate my talk : http://joind.in/9568 58. Thanks ! Please rate my talk : http://joind.in/9568