Remove PHP calls&scale your site like crazy !Wim GoddenCu.be Solutions
Who am I ?Wim Godden (@wimgtr)Founder of Cu.be Solutions (http://cu.be)Open source developer since 1997Developer of OpenX,...
Who are you ?Developers ?System/network engineers ?Managers ?
To understand the presentUnderstand the past
The Stone AgeNew blog post by : caveman003
Pre-PHP : draw it and make html
The Egyptian Era
Old-school PHP : rebuild-every-time
The Industrial Revolution
PHP : lets cache
Extra ! Extra !
PHP : dynamic content in static content
The Modern Era
PHP : multiple webservers
PHP : push updates to cache
Today
Adding reverse proxy caching
Website X with ESIArticle content pagePage contentHeaderLatest newsNavigation
Website X with ESIArticle content pagePage contentHeader(TTL = 2h)Latest newsNavigation(TTL = 1h)
Website X with ESIArticle content pagePage content (TTL = 30m)Header(TTL = 2h)Latest news (TTL = 2m)Navigation(TTL = 1h)
Going to /page/id/732<esi:include src="/header"/><esi:include src="/nav"/><esi:include src="/latest-news"/><esi:include sr...
A simple benchmark – 2KByte JPEGApache 2.2 4210IIS 7.5 3960Varnish 3.0 11400
A dynamically generated, but static pageApache 2.2 + PHP (3 DB queries) 18IIS 7.5 + .Net (3 DB queries) 16Varnish 3.0 11400
Varnish - what can/cant be cached ?Can :Static pagesImages, js, cssStatic parts of pages that dont change often (ESI)Cant ...
ESI → no caching on user-specific content ?Logged in as : Wim Godden5 messagesTTL = 5minTTL=1hTTL = 0s ?
NginxWeb serverReverse proxyLightweight, fast12.81% of all Websites
NginxNo threads, event-drivenUses epoll / kqueueLow memory footprint10000 active connections = normal
ESI on NginxLogged in as : Wim Godden5 messagesNEWSMenu
ESI SCL on Nginx<scl:include key="news" src="/news" ttl="5m" /><scl:includekey="menu"src="/menu"ttl="1h" /><scl:include ke...
Requesting /page (1sttime)NginxShared memory1234/page/page
Requesting /page ESI subrequests (1sttime)Nginx123/menu/news/top (in ESI session)
Requesting /page (next time)NginxShared memory12/page/menu/news/top (in ESI session)/page
New message is sent...POST /sendDBinsert into...set(...)top (in ESI session)
AdvantagesNo repeated GET hits to webserver anymore !At login : POST → warm up the cache !No repeated hits for user-specif...
News addedaddnews() methodDBinsert into...set(...)Memcache key /news
AdvantagesNo repeated GET hits to webserver anymore !At login : POST → warm up the cache !No repeated hits for user-specif...
How many Memcache requests ?Logged in as : Wim Godden5 messages<scl:include key="news" src="/news" ttl="5m" /><scl:include...
First release : ESIPart of the ESI 1.0 specOnly relevant features implementedExtension for dynamic session supportBut : un...
Rebuilt from scratch : SCLSession-specific Caching LanguageLanguage details :Control structures : if/else, switch/case, fo...
SCL code samples<scl:switch var="session_var(isAdmin)"><scl:case value="1"><scl:include key="admin-buttons" src="/admin-bu...
SCL code samples<scl:foreach item="messageId"src="cache_var(thread + query_var(threadId))"><scl:include key="thread-messag...
ESI code samples<esi:foreach items="message"collection="$(ESIGLOBAL{thread_ + $(QUERY_STRING{threadId})})"><esi:include ke...
Why Nginx ?Native Memcached supportExcellent and superfast subrequest systemIncluding parallel subrequestsHandles thousand...
Whats the result ?
Figures2ndcustomer :No. of web servers : 72 → 8No. of db servers : 15 → 4Total : 87 → 12 (86% reduction !)Last customer :N...
Why is it so much faster ?
A real example : vBulletin
A real example : vBulletinThreadisModerator session variableisAdmin session variable
A real example : vBulletinDB Server Load Web Server Load Max Requests/sec (1 = 282)05101520253035Standard installWith Memc...
AvailabilityGood news :It will become Open SourceIts solid : stable at 4 customersBad news :First customer holds copyright...
So...
Questions ?
Questions ?
ContactTwitter @wimgtrWeb http://techblog.wimgodden.beSlides http://www.slideshare.net/wimgE-mail wim.godden@cu.bePlease r...
Thanks !Please rate my talk :http://joind.in/8439
Upcoming SlideShare
Loading in...5
×

Remove php calls and scale your site like crazy !

14,212

Published 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 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.

Published in: Technology
1 Comment
1 Like
Statistics
Notes
  • 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
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
14,212
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
1
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Remove php calls and scale your site like crazy !"

  1. 1. Remove PHP calls&scale your site like crazy !Wim GoddenCu.be Solutions
  2. 2. Who am I ?Wim Godden (@wimgtr)Founder of Cu.be Solutions (http://cu.be)Open source developer since 1997Developer of OpenX, PHPCompatibility, ...Speaker at PHP and Open Source conferences
  3. 3. Who are you ?Developers ?System/network engineers ?Managers ?
  4. 4. To understand the presentUnderstand the past
  5. 5. The Stone AgeNew blog post by : caveman003
  6. 6. Pre-PHP : draw it and make html
  7. 7. The Egyptian Era
  8. 8. Old-school PHP : rebuild-every-time
  9. 9. The Industrial Revolution
  10. 10. PHP : lets cache
  11. 11. Extra ! Extra !
  12. 12. PHP : dynamic content in static content
  13. 13. The Modern Era
  14. 14. PHP : multiple webservers
  15. 15. PHP : push updates to cache
  16. 16. Today
  17. 17. Adding reverse proxy caching
  18. 18. Website X with ESIArticle content pagePage contentHeaderLatest newsNavigation
  19. 19. Website X with ESIArticle content pagePage contentHeader(TTL = 2h)Latest newsNavigation(TTL = 1h)
  20. 20. Website X with ESIArticle content pagePage content (TTL = 30m)Header(TTL = 2h)Latest news (TTL = 2m)Navigation(TTL = 1h)
  21. 21. Going to /page/id/732<esi:include src="/header"/><esi:include src="/nav"/><esi:include src="/latest-news"/><esi:include src="/article/id/732"/>
  22. 22. A simple benchmark – 2KByte JPEGApache 2.2 4210IIS 7.5 3960Varnish 3.0 11400
  23. 23. A dynamically generated, but static pageApache 2.2 + PHP (3 DB queries) 18IIS 7.5 + .Net (3 DB queries) 16Varnish 3.0 11400
  24. 24. Varnish - what can/cant be cached ?Can :Static pagesImages, js, cssStatic parts of pages that dont change often (ESI)Cant :POST requestsVery large files (its not a file server !)Requests with Set-CookieUser-specific content
  25. 25. ESI → no caching on user-specific content ?Logged in as : Wim Godden5 messagesTTL = 5minTTL=1hTTL = 0s ?
  26. 26. NginxWeb serverReverse proxyLightweight, fast12.81% of all Websites
  27. 27. NginxNo threads, event-drivenUses epoll / kqueueLow memory footprint10000 active connections = normal
  28. 28. ESI on NginxLogged in as : Wim Godden5 messagesNEWSMenu
  29. 29. ESI SCL on Nginx<scl:include key="news" src="/news" ttl="5m" /><scl:includekey="menu"src="/menu"ttl="1h" /><scl:include key="top" src="/top" session="true" ttl="1h" />
  30. 30. Requesting /page (1sttime)NginxShared memory1234/page/page
  31. 31. Requesting /page ESI subrequests (1sttime)Nginx123/menu/news/top (in ESI session)
  32. 32. Requesting /page (next time)NginxShared memory12/page/menu/news/top (in ESI session)/page
  33. 33. New message is sent...POST /sendDBinsert into...set(...)top (in ESI session)
  34. 34. 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
  35. 35. News addedaddnews() methodDBinsert into...set(...)Memcache key /news
  36. 36. 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 contentNo TTLs for non-specific content
  37. 37. How many Memcache requests ?Logged in as : Wim Godden5 messages<scl:include key="news" src="/news" ttl="5m" /><scl:includekey="menu"src="/menu"ttl="1h" /><scl:include key="top" src="/top" session="true" ttl="1h" />
  38. 38. First release : ESIPart of the ESI 1.0 specOnly relevant features implementedExtension for dynamic session supportBut : unavailable for copyright reasons
  39. 39. Rebuilt from scratch : SCLSession-specific Caching LanguageLanguage details :Control structures : if/else, switch/case, foreachVariable handlingStrings : concatenation, substring, ...
  40. 40. SCL code samples<scl:switch var="session_var(isAdmin)"><scl:case value="1"><scl:include key="admin-buttons" src="/admin-buttons.php" /></scl:case><scl:default><div id="just-a-user"><scl:include key="user-buttons" src="/user-buttons.php" /></div></scl:default></scl:switch>
  41. 41. SCL code samples<scl:foreach item="messageId"src="cache_var(thread + query_var(threadId))"><scl:include key="thread-message_ + messageId"src="/thread/message.php?id= + messageId" /></scl:foreach>
  42. 42. ESI code samples<esi:foreach items="message"collection="$(ESIGLOBAL{thread_ + $(QUERY_STRING{threadId})})"><esi:include key="thread-message + $message"src="/thread/message.php?id= + $message" /></esi:foreach>
  43. 43. 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
  44. 44. Whats the result ?
  45. 45. Figures2ndcustomer :No. of web servers : 72 → 8No. of db servers : 15 → 4Total : 87 → 12 (86% reduction !)Last customer :No. of total servers : +/- 1350Expected reduction : 1350 → 300Expected savings : €1.6 Million per year
  46. 46. Why is it so much faster ?
  47. 47. A real example : vBulletin
  48. 48. A real example : vBulletinThreadisModerator session variableisAdmin session variable
  49. 49. A real example : vBulletinDB Server Load Web Server Load Max Requests/sec (1 = 282)05101520253035Standard installWith MemcachedNginx + SCL + memcached
  50. 50. AvailabilityGood news :It will become Open SourceIts solid : stable at 4 customersBad news :First customer holds copyrightsTotal rebuild→ Open Source releaseBeta : Sep 2013Final : End 2013 (on Github !)
  51. 51. So...
  52. 52. Questions ?
  53. 53. Questions ?
  54. 54. ContactTwitter @wimgtrWeb http://techblog.wimgodden.beSlides http://www.slideshare.net/wimgE-mail wim.godden@cu.bePlease rate my talk :http://joind.in/8439
  55. 55. Thanks !Please rate my talk :http://joind.in/8439

×