• Save
Remove php calls and scale your site like crazy !
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Remove php calls and scale your site like crazy !

  • 13,295 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 this problem, changing the way developers 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
    Be the first to like this
No Downloads

Views

Total Views
13,295
On Slideshare
13,287
From Embeds
8
Number of Embeds
2

Actions

Shares
Downloads
0
Comments
1
Likes
0

Embeds 8

http://librosweb.es 6
http://lanyrd.com 2

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 GoddenCu.be Solutions
  • 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. Who are you ?Developers ?System/network engineers ?Managers ?
  • 4. To understand the presentUnderstand the past
  • 5. The Stone AgeNew blog post by : caveman003
  • 6. Pre-PHP : draw it and make html
  • 7. The Egyptian Era
  • 8. Old-school PHP : rebuild-every-time
  • 9. The Industrial Revolution
  • 10. PHP : lets cache
  • 11. Extra ! Extra !
  • 12. PHP : dynamic content in static content
  • 13. The Modern Era
  • 14. PHP : multiple webservers
  • 15. PHP : push updates to cache
  • 16. Today
  • 17. Adding reverse proxy caching
  • 18. Website X with ESIArticle content pagePage contentHeaderLatest newsNavigation
  • 19. Website X with ESIArticle content pagePage contentHeader(TTL = 2h)Latest newsNavigation(TTL = 1h)
  • 20. Website X with ESIArticle content pagePage content (TTL = 30m)Header(TTL = 2h)Latest news (TTL = 2m)Navigation(TTL = 1h)
  • 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. A simple benchmark – 2KByte JPEGApache 2.2 4210IIS 7.5 3960Varnish 3.0 11400
  • 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. 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. ESI → no caching on user-specific content ?Logged in as : Wim Godden5 messagesTTL = 5minTTL=1hTTL = 0s ?
  • 26. NginxWeb serverReverse proxyLightweight, fast12.81% of all Websites
  • 27. NginxNo threads, event-drivenUses epoll / kqueueLow memory footprint10000 active connections = normal
  • 28. ESI on NginxLogged in as : Wim Godden5 messagesNEWSMenu
  • 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. Requesting /page (1sttime)NginxShared memory1234/page/page
  • 31. Requesting /page ESI subrequests (1sttime)Nginx123/menu/news/top (in ESI session)
  • 32. Requesting /page (next time)NginxShared memory12/page/menu/news/top (in ESI session)/page
  • 33. New message is sent...POST /sendDBinsert into...set(...)top (in ESI session)
  • 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. News addedaddnews() methodDBinsert into...set(...)Memcache key /news
  • 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. 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. First release : ESIPart of the ESI 1.0 specOnly relevant features implementedExtension for dynamic session supportBut : unavailable for copyright reasons
  • 39. Rebuilt from scratch : SCLSession-specific Caching LanguageLanguage details :Control structures : if/else, switch/case, foreachVariable handlingStrings : concatenation, substring, ...
  • 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. 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. 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. 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. Whats the result ?
  • 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. Why is it so much faster ?
  • 47. A real example : vBulletin
  • 48. A real example : vBulletinThreadisModerator session variableisAdmin session variable
  • 49. A real example : vBulletinDB Server Load Web Server Load Max Requests/sec (1 = 282)05101520253035Standard installWith MemcachedNginx + SCL + memcached
  • 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. So...
  • 52. Questions ?
  • 53. Questions ?
  • 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. Thanks !Please rate my talk :http://joind.in/8439