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

Remove php calls and scale your site like crazy !

on

  • 12,065 views

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.

Statistics

Views

Total Views
12,065
Views on SlideShare
12,057
Embed Views
8

Actions

Likes
0
Downloads
0
Comments
1

2 Embeds 8

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

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • 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
    Processing…
Post Comment
Edit your comment

Remove php calls and scale your site like crazy ! Remove php calls and scale your site like crazy ! Presentation Transcript

  • 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, PHPCompatibility, ...Speaker at PHP and Open Source conferences
  • 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 src="/article/id/732"/>
  • 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 :POST requestsVery large files (its not a file server !)Requests with Set-CookieUser-specific content
  • 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 key="top" src="/top" session="true" ttl="1h" />
  • 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-specific contentNot even for non-specific content
  • 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-specific contentNot even for non-specific contentNo TTLs for non-specific content
  • 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" />
  • First release : ESIPart of the ESI 1.0 specOnly relevant features implementedExtension for dynamic session supportBut : unavailable for copyright reasons
  • Rebuilt from scratch : SCLSession-specific Caching LanguageLanguage details :Control structures : if/else, switch/case, foreachVariable handlingStrings : concatenation, substring, ...
  • 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>
  • 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>
  • 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>
  • 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
  • Whats the result ?
  • 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
  • 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 MemcachedNginx + SCL + memcached
  • 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 !)
  • So...
  • Questions ?
  • Questions ?
  • ContactTwitter @wimgtrWeb http://techblog.wimgodden.beSlides http://www.slideshare.net/wimgE-mail wim.godden@cu.bePlease rate my talk :http://joind.in/8439
  • Thanks !Please rate my talk :http://joind.in/8439