Making dynamic sites scale like static sites

3,779 views
3,675 views

Published on

A new Nginx module allows caching of dynamic content through a new ESI implementation, without hitting PHP every time.

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,779
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
33
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Making dynamic sites scale like static sites

  1. 1. Making dynamic sites scale like static sites Wim Godden Cu.be Solutions
  2. 2. Who am I ? <ul><li>Wim Godden (@wimgtr)
  3. 3. Owner of Cu.be Solutions (http://cu.be)
  4. 4. PHP developer since 1997
  5. 5. Developer of OpenX
  6. 6. Zend Certified Engineer
  7. 7. Zend Framework Certified Engineer
  8. 8. MySQL Certified Developer </li></ul>
  9. 9. Who are you ? <ul><li>Developers ?
  10. 10. System/network engineers ?
  11. 11. Managers ?
  12. 12. Varnish ?
  13. 13. Nginx ? </li></ul>
  14. 14. Making dynamic sites scale like static sites (aka &quot;Nginx-PHP on steroids&quot;) Wim Godden Cu.be Solutions
  15. 15. Varnish <ul><li>Not just a load balancer
  16. 16. Reverse proxy cache / http accelerator / …
  17. 17. Caches (parts of) pages in memory
  18. 18. Careful : </li><ul><li>uses threads (like Apache)
  19. 19. Nginx usually scales better (but doesn't have VCL) </li></ul></ul>
  20. 20. Varnish - ESI <ul>Perfect for caching pages </ul>In your article page output : <esi:include src=&quot;/news.php&quot;/> In your Varnish config : sub vcl_fetch { if (req.url == &quot;/news.php&quot;) { esi; /* Do ESI processing */ set obj.ttl = 2m; } elseif (req.url == &quot;/nav.php&quot;) { esi; set obj.ttl = 1m; } elseif …. … . }
  21. 21. Varnish - what can/can't be cached ? <ul><li>Can : </li><ul><li>Static pages
  22. 22. Images, js, css
  23. 23. Static parts of pages that don't change often (ESI) </li></ul><li>Can't : </li><ul><li>POST requests
  24. 24. Very large files (it's not a file server !)
  25. 25. Requests with Set-Cookie
  26. 26. User-specific content </li></ul></ul>
  27. 27. ESI -> no caching on user-specific content ? Logged in as : Wim Godden 5 messages TTL = 5min TTL=1h TTL = 0s ?
  28. 28. Dynamic content Request Varnish Ideally user X : /top /top request to Apache same user Y : /top /top request to Apache same user X : /top /top request to Apache if unchanged : served from cache user Y : /top /top request to Apache if unchanged : served from cache
  29. 29. Coming to Nginx soon... Logged in as : Wim Godden 5 messages NEWS Menu
  30. 30. Coming to Nginx soon... <esim:include src=&quot;/news&quot; ttl=&quot;5m&quot; /> <esim:include src=&quot;/menu&quot; ttl=&quot;1h&quot; /> <esim:include src=&quot;/top&quot; usesession=&quot;1&quot; ttl=&quot;1h&quot; />
  31. 31. Requesting /page (1 st time) Nginx /page /page
  32. 32. Requesting /page ESI subrequests (1 st time) Nginx /menu.php /news.php /top.php ($sessionid$)
  33. 33. Requesting /page (next time) Nginx /page /menu.php /news.php /top.php ($sessionid$) /page
  34. 34. New message arrives... <ul>top.php ($sessionid$) </ul>DB
  35. 35. Advantages <ul><li>No repeated hits to PHP anymore ! </li><ul><li>Only the initial hit (unless you pre-heat/warm up the cache !)
  36. 36. No hits for user-specific content
  37. 37. Not even for non-specific content </li></ul></ul>
  38. 38. News added <ul>news.php </ul>DB
  39. 39. Do we need TTLs ? Logged in as : Wim Godden 5 messages <esim:include src=&quot;/news&quot; ttl=&quot;5m&quot; /> <esim:include src=&quot;/menu&quot; ttl=&quot;1h&quot; /> <esim:include src=&quot;/top&quot; usesession=&quot;1&quot; ttl=&quot;1h&quot; />
  40. 40. Advantages <ul><li>No repeated hits to backend anymore ! </li><ul><li>Only the initial hit (unless you pre-heat/warm up the cache !)
  41. 41. Not for user-specific content
  42. 42. Not even for non-specific content </li><ul><li>No TTLs for non-specific content
  43. 43. TTL for user-specific content is required (defaults to 5min)
  44. 44. Imagine doing it for the bid status on Ebay items ;-) </li></ul></ul><li>No need to specify per-URL ESI parameters in configuration file </li><ul><li>Except when full page is dynamic (and you want to cache it) </li><ul><li>-> so this doesn't just work for ESI pages </li></ul><li>Uses lots of regular expressions </li></ul></ul>
  45. 45. How many Memcache requests ? Logged in as : Wim Godden 5 messages <esim:include src=&quot;/news&quot; ttl=&quot;5m&quot; /> <esim:include src=&quot;/menu&quot; ttl=&quot;1h&quot; /> <esim:include src=&quot;/top&quot; usesession=&quot;1&quot; ttl=&quot;1h&quot; />
  46. 46. Why Nginx ? <ul><li>Native Memcache support
  47. 47. Excellent and superfast subrequest system </li><ul><li>Including parallel subrequests </li></ul><li>Handles thousands of connections per worker </li><ul><li>With minimal memory footprint </li></ul><li>PHP-FPM integration </li><ul><li>No need to add a separate caching layer
  48. 48. Local = faster
  49. 49. Easier to debug performance issues (esp. with slow script feature) </li></ul></ul>
  50. 50. Under development <ul><li>Feature set = unclear
  51. 51. Performance = even more unclear </li><ul><li>Debugging code makes it slow
  52. 52. Benchmarks for an upcoming conference </li></ul><li>Extends ESI standard, but doesn't follow it entirely </li><ul><li>(what standard ?) </li></ul><li>Release date ? </li><ul><li>Beta : Dec 2011
  53. 53. Stable : Feb 2012 </li></ul></ul>
  54. 54. <ul>Questions ? </ul>
  55. 55. <ul>Questions ? </ul>
  56. 56. Contact <ul><li>Twitter @wimgtr
  57. 57. Web http://techblog.wimgodden.be
  58. 58. Slides http://www.slideshare.net/wimg
  59. 59. E-mail [email_address] </li></ul>
  60. 60. Please... <ul>Rate my talk : http://joind.in/4000 </ul>
  61. 61. <ul>Thanks ! </ul>

×