Remove web calls and scale your site like crazy !

  • 46,735 views
Uploaded on

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 …

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 solve this problem, changing the way you think about designing sites with user-specific content.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • The            setup            in            the            video            no            longer            works.           
    And            all            other            links            in            comment            are            fake            too.           
    But            luckily,            we            found            a            working            one            here (copy paste link in browser) :            www.goo.gl/i7K0s4
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
46,735
On Slideshare
0
From Embeds
0
Number of Embeds
5

Actions

Shares
Downloads
6
Comments
1
Likes
4

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. Remove PHP calls &scale your site like crazy ! Wim Godden Cu.be Solutions
  • 2. Who am I ? Wim Godden (@wimgtr) Owner of Cu.be Solutions (http://cu.be) PHP developer since 1997 Developer of OpenX Zend Certified Engineer Zend Framework Certified Engineer MySQL Certified Developer Speaker at PHP and Open Source conferences
  • 3. Who are you ? Developers ? System/network engineers ? Managers ?
  • 4. Were at a PHP conference... … and Im going to show you how to use less PHP
  • 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 : lets 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 Header Latest news Article content page Navigation Page content
  • 20. Website X with ESI Header (TTL = 2h) Latest news Article 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 <esi:include src="/header"/> <esi:include src="/nav"/> <esi:include src="/latest-news"/> <esi:include src="/article/id/732"/>
  • 23. A simple benchmark – 2KByte JPEG Apache 2.2 4210 IIS 7.5 3960 Varnish 3.0 11400
  • 24. A dynamically generated, but static page Apache 2.2 + PHP (3 DB queries) 18 IIS 7.5 + .Net (3 DB queries) 16 Varnish 3.0 11400
  • 25. Varnish - what can/cant be cached ? Can : Static pages Images, js, css Static parts of pages that dont change often (ESI) Cant : POST requests Very large files (its not a file server !) Requests with Set-Cookie User-specific content
  • 26. ESI → no caching on user-specific content ? Logged in as : Wim Godden TTL = 0s ? 5 messages TTL=1h TTL = 5min
  • 27. Nginx Web server Reverse proxy Lightweight, fast 12.3% of all Websites
  • 28. Nginx No threads, event-driven Uses epoll / kqueue Low memory footprint 10000 active connections = normal
  • 29. ESI on Nginx Logged in as : Wim Godden 5 messages Menu NEWS
  • 30. ESI on Nginx <esi:include src="/top" session="1" ttl="1h" /> <esi:include src="/menu" <esi:include src="/news" ttl="5m" /> ttl="1h" />
  • 31. Requesting /page (1st time) Nginx 1 3 Shared memory /page 2 4 /page
  • 32. Requesting /page ESI subrequests (1st time) Nginx 1 2 3 /menu /news /top (in ESI session)
  • 33. Requesting /page (next time) Nginx 1 Shared memory /page 2 /page /menu /news /top (in ESI session)
  • 34. New message is sent... POST /send o ... se i nt t (.. e rt .) ins DB top (in ESI session)
  • 35. 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
  • 36. News added addnews() method o ... se i nt t (.. e rt .) ins DB Memcache key /news
  • 37. 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 Imagine doing it for the bid status on Ebay items ;-)
  • 38. How many Memcache requests ? Logged in as : Wim Godden <esi:include src="/top" session="1" ttl="1h" /> 5 messages <esi:include src="/menu" <esi:include src="/news" ttl="5m" /> ttl="1h" />
  • 39. ESI implementation Part of the ESI 1.0 spec Only relevant features implemented Extension for dynamic session support
  • 40. ESI code samples <esi:choose> <esi:when test="$(ESISESSION{isAdmin})==true"> <esi:include src="admin-buttons" alt="/admin-buttons.php" /> </esi:when> <esi:otherwise> <div id="justauser"> <esi:include src="user-buttons" alt="/user-buttons.php" /> </div> </esi:otherwise> </esi:choose>
  • 41. ESI code samples<esi:foreach items="message" collection="$(ESIGLOBAL{thread_ + $(QUERY_STRING{threadId})})"> <esi:include src="thread-message" alt="/thread/message.php" /></esi:foreach>
  • 42. Why Nginx ? Native Memcache support Excellent and superfast subrequest system Including parallel subrequests Handles thousands of connections per worker With minimal memory footprint Integrates with php-fpm Performance gain (5 - 15%) Additional features (chroot, slow request log, offline processing, ...) Graceful rolling upgrades
  • 43. Whats the result ?
  • 44. Figures Second customer : No. of web servers : 72 → 8 No. of db servers : 15 → 4 Total : 87 → 12 (86% reduction !) Third customer : No. of total servers : +/- 1350 Expected reduction : 1350 → 300 Expected savings : €1.6 Million (6.7M złoty) per year
  • 45. Why is it so much faster ?
  • 46. A real example : vBulletin
  • 47. A real example : vBulletin 18 16 14 12 10 Standard install Memcached 8 Nginx + ESI + memcached 6 4 2 0 DB Load Web Load Max load
  • 48. Availability Good news : It will become Open Source Its solid : stable at 2 customers, being installed at 2 more Bad news : First customer holds copyrights Once changes for customer 3 + 4 are backported for customer 1 → Open Source release Binaries : Dec 2012 – Jan 2013 Source : Jan-Feb 2013 (on Github !)
  • 49. So...
  • 50. Questions ?
  • 51. Questions ?
  • 52. Contact Twitter @wimgtr Web http://techblog.wimgodden.be Slides http://www.slideshare.net/wimg E-mail wim.godden@cu.be Please rate my talk : http://joind.in/7184
  • 53. Thanks !Please rate my talk : http://joind.in/7184