When dynamic becomes static: the next step in web caching techniques
Upcoming SlideShare
Loading in...5
×
 

When dynamic becomes static: the next step in web caching techniques

on

  • 2,267 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
2,267
Views on SlideShare
2,131
Embed Views
136

Actions

Likes
0
Downloads
18
Comments
0

4 Embeds 136

http://velocityconf.com 121
https://twitter.com 9
http://wiki-na.ms.com 3
http://lanyrd.com 3

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…
Post Comment
Edit your comment

    When dynamic becomes static: the next step in web caching techniques When dynamic becomes static: the next step in web caching techniques Presentation Transcript

    • When dynamic becomes static – the next step in web caching techniques Wim Godden Cu.be Solutions
    • Disclaimer The next step As in : what you will be doing in the future Not as in : go home and run it ;-) Language of choice : PHP But : think Perl, Python, Ruby, Java, .Net, …
    • Who am I ? Wim Godden (@wimgtr) Founder of Cu.be Solutions (http://cu.be) Open source developer since 1997 Developer of OpenX, PHPCompatibility, ... Speaker at PHP and Open Source conferences
    • Who are you ? Developers ? System/network engineers ? Managers ?
    • To understand the present Understand the past
    • The Stone Age New blog post by : caveman003
    • Pre-PHP : draw it and make html
    • The Egyptian Era
    • Old-school PHP : 'rebuild-every-time'
    • The Industrial Revolution
    • PHP : let's 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 ESI Header Latest news Article content page Navigation Page content
    • Website X with ESI Top header (TTL = 2h) Latest news Article content page Navigation (TTL = 1h) Page content
    • Website X with ESI Top header (TTL = 2h) Latest news (TTL = 2m) Article content page Navigation (TTL = 1h) Page content (TTL = 30m)
    • Going to /page/id/732 <esi:include src="/top"/> <esi:include src="/nav"/> <esi:include src="/latest-news"/> <esi:include src="/article/id/732"/>
    • Varnish - ESI <esi:include src="/top"/> <esi:include src="/news"/> Article content page <esi:include src="/nav"/> <esi:include src="/article/732"/>
    • A simple benchmark – 2KByte JPEG Apache 2.2 4210 IIS 7.5 3960 Varnish 3.0 11400
    • 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
    • Varnish - what can/can't be cached ? Can : Static pages Images, js, css Static parts of pages that don't change often (ESI) Can't : POST requests Very large files (it's not a file server !) Requests with Set-Cookie User-specific content
    • ESI → no caching on user-specific content ? Logged in as : Wim Godden TTL = 0s ? TTL=1h 5 messages TTL = 5min
    • Nginx Web server Reverse proxy Lightweight, fast 12.81% of all Websites
    • Nginx No threads, event-driven Uses epoll / kqueue Low memory footprint 10000 active connections = normal
    • ESI on Nginx Logged in as : Wim Godden 5 messages Menu NEWS
    • ESI SCL on Nginx <scl:include key="top" src="/top" session="true" ttl="1h" /> <scl:include key="menu" src="/menu" ttl="1h" /> <scl:include key="news" src="/news" ttl="5m" />
    • Requesting /page (1st time) Nginx 1 Shared memory /page 4 /page 3 2
    • Requesting /page ESI subrequests (1st time) Nginx 1 2 3 /menu /news /top (in SCL session)
    • Requesting /page (next time) Nginx Shared memory 1 /page 2 /page /menu /news /top (in SCL session)
    • New message is sent... POST /send o i nt rt e ins ... se t (.. .) DB top (in SCL session)
    • 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
    • News added addnews() method o i nt rt e ins ... se t (.. .) DB Memcache key /news
    • 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
    • How many Memcache requests ? Logged in as : Wim Godden <scl:include key="top" src="/top" session="true" ttl="1h" /> 5 messages <scl:include key="menu" src="/menu" ttl="1h" /> <scl:include key="news" src="/news" ttl="5m" />
    • First release : ESI Part of the ESI 1.0 spec Only relevant features implemented Extension for dynamic session support But : unavailable for copyright reasons
    • Rebuilt from scratch : SCL Session-specific Caching Language Language details : Control structures : if/else, switch/case, foreach Variable handling Strings : concatenation, substring, … Exception handling, header manipulation, ...
    • SCL code samples You are logged in as : <scl:session_var("person_name") /> You are logged in as : <@s("person_name") />
    • 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="global_var('thread' + query_var('threadId'))"> <scl:include key="'thread-message_' + messageId" src="'/thread/message.php?id=' + messageId" /> </scl:foreach>
    • Identifying the user In Nginx configuration : scl_session_cookie <name> → Defined by language (or configurable) scl_session_identifier <string> → Defined by you Example for PHP : scl_session_cookie PHPSESSID scl_session_identifier UID
    • Identifying the user Cookie : PHPSESSID = jpsidc1po35sq9q3og4f3hi6e2 Nginx + SCL 432 get UID_jpsidc1po35sq9q3og4f3hi6e2
    • Retrieving user specific content Cookie : PHPSESSID = jpsidc1po35sq9q3og4f3hi6e2 Nginx + SCL get top_432
    • Why Nginx ? Native Memcached support Excellent and superfast subrequest system Including parallel subrequests Handles thousands of connections per worker With minimal memory footprint Integrates with php-fpm Additional features (chroot, slow request log, offline processing, ...) Graceful rolling upgrades
    • What's the result ?
    • Figures 2nd customer : No. of web servers : 72 → 8 No. of db servers : 15 → 4 Total : 87 → 12 (86% reduction !) Last customer : No. of total servers : +/- 1350 Expected reduction : 1350 → 300 Expected savings : €1.6 Million per year
    • Why is it so much faster ?
    • A real example : vBulletin
    • A real example : vBulletin isAdmin session variable Post isModerator session variable
    • A real example : vBulletin 35 30 25 20 Standard install With Memcached Nginx + SCL + memcached 15 10 5 0 DB Server Load Web Server Load Max Requests/sec (1 = 282)
    • Availability Good news : It will become Open Source It's solid : ESI version stable at 4 customers Bad news : First customer holds copyrights Total rebuild → Open Source release No current projects, so spare time Beta : Jan-Feb Stable : Q2 (on Github)
    • So...
    • Questions ?
    • Questions ?
    • Contact Twitter Web Slides E-mail @wimgtr http://techblog.wimgodden.be http://www.slideshare.net/wimg wim.godden@cu.be Please provide feedback : http://go.cu.be/velocity2013