Your SlideShare is downloading. ×

Making dynamic sites scale like static sites

3,388

Published on

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

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,388
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
32
Comments
0
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

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

×