SlideShare a Scribd company logo
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 ;-)
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
Header
(TTL = 2h)
Latest news

Article content page
Navigation
(TTL = 1h)

Page content
Website X with ESI
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="/header"/>
<esi:include src="/nav"/>
<esi:include src="/latest-news"/>
<esi:include src="/article/id/732"/>
Varnish - ESI
Perfect for caching pages
<esi:include src="/top"/>
<esi:include src="/news"/>

Article content page
<esi:include
src="/nav"/>

<esi:include src="/article/732"/>

In your Varnish config :
sub vcl_fetch {
if (req.url == "/news") {
esi; /* Do ESI processing */
set obj.ttl = 2m;
} elseif (req.url == "/nav") {
esi;
set obj.ttl = 1m;
} elseif ….
….
}
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 ESI session)
Requesting /page (next time)

Nginx
Shared memory

1

/page

2

/page
/menu
/news
/top (in ESI session)
New message is sent...

POST /send
o
i nt
rt
e
ins

...

se
t

(..
.)

DB

top (in ESI 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, ...
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>
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 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

Thread

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 : Dec-Jan
Final : Q1-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 rate my talk :
http://joind.in/9568
Thanks !
Please rate my talk :
http://joind.in/9568

More Related Content

ODP
Beyond PHP - it's not (just) about the code
ODP
Nginx and friends - putting a turbo button on your site
ODP
My app is secure... I think
ODP
Remove php calls and scale your site like crazy !
ODP
The why and how of moving to PHP 5.4/5.5
ODP
The why and how of moving to PHP 5.5/5.6
ODP
When dynamic becomes static: the next step in web caching techniques
ODP
Caching and tuning fun for high scalability @ FrOSCon 2011
Beyond PHP - it's not (just) about the code
Nginx and friends - putting a turbo button on your site
My app is secure... I think
Remove php calls and scale your site like crazy !
The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.5/5.6
When dynamic becomes static: the next step in web caching techniques
Caching and tuning fun for high scalability @ FrOSCon 2011

What's hot (20)

ODP
The why and how of moving to php 5.4/5.5
ODP
Beyond php - it's not (just) about the code
ODP
My app is secure... I think
ODP
My app is secure... I think
PDF
Introduction to Flask Micro Framework
ODP
The why and how of moving to php 5.4
PDF
Node.js API 서버 성능 개선기
PDF
Pycon - Python for ethical hackers
PDF
Learning Dtrace
KEY
Zend Framework Study@Tokyo #2
PDF
Web Crawling with NodeJS
PDF
"Swoole: double troubles in c", Alexandr Vronskiy
 
PPTX
Python and EM CLI: The Enterprise Management Super Tools
PDF
Memcached Presentation @757rb
PPT
Why and How Powershell will rule the Command Line - Barcamp LA 4
ODP
Caching and tuning fun for high scalability
PDF
Python RESTful webservices with Python: Flask and Django solutions
PDF
Top Node.js Metrics to Watch
PDF
Kickin' Ass with Cache-Fu (without notes)
 
The why and how of moving to php 5.4/5.5
Beyond php - it's not (just) about the code
My app is secure... I think
My app is secure... I think
Introduction to Flask Micro Framework
The why and how of moving to php 5.4
Node.js API 서버 성능 개선기
Pycon - Python for ethical hackers
Learning Dtrace
Zend Framework Study@Tokyo #2
Web Crawling with NodeJS
"Swoole: double troubles in c", Alexandr Vronskiy
 
Python and EM CLI: The Enterprise Management Super Tools
Memcached Presentation @757rb
Why and How Powershell will rule the Command Line - Barcamp LA 4
Caching and tuning fun for high scalability
Python RESTful webservices with Python: Flask and Django solutions
Top Node.js Metrics to Watch
Kickin' Ass with Cache-Fu (without notes)
 
Ad

Similar to When dynamic becomes static: the next step in web caching techniques (20)

ODP
When dynamic becomes static: the next step in web caching techniques
ODP
When dynamic becomes static : the next step in web caching techniques
ODP
When dynamic becomes static : the next step in web caching techniques
ODP
When dynamic becomes static - the next step in web caching techniques
ODP
Remove web calls and scale your site like crazy !
ODP
When dynamic becomes static
ODP
Making dynamic sites scale like static sites
ODP
Caching and tuning fun for high scalability
ODP
When dynamic becomes static
PDF
Saving The World From Guaranteed APOCALYPSE* Using Varnish and Memcached
ODP
Caching and tuning fun for high scalability @ FOSDEM 2012
PDF
Using NGINX as an Effective and Highly Available Content Cache
ODP
Caching and tuning fun for high scalability @ PHPTour
PDF
ITB2017 - Nginx Effective High Availability Content Caching
PDF
High Availability Content Caching with NGINX
PPTX
High Availability Content Caching with NGINX
PDF
Cache all the things - A guide to caching Drupal
PDF
High Performance Drupal Sites
PPT
Presentation (PowerPoint File)
PPT
Presentation (PowerPoint File)
When dynamic becomes static: the next step in web caching techniques
When dynamic becomes static : the next step in web caching techniques
When dynamic becomes static : the next step in web caching techniques
When dynamic becomes static - the next step in web caching techniques
Remove web calls and scale your site like crazy !
When dynamic becomes static
Making dynamic sites scale like static sites
Caching and tuning fun for high scalability
When dynamic becomes static
Saving The World From Guaranteed APOCALYPSE* Using Varnish and Memcached
Caching and tuning fun for high scalability @ FOSDEM 2012
Using NGINX as an Effective and Highly Available Content Cache
Caching and tuning fun for high scalability @ PHPTour
ITB2017 - Nginx Effective High Availability Content Caching
High Availability Content Caching with NGINX
High Availability Content Caching with NGINX
Cache all the things - A guide to caching Drupal
High Performance Drupal Sites
Presentation (PowerPoint File)
Presentation (PowerPoint File)
Ad

More from Wim Godden (20)

PDF
Beyond php - it's not (just) about the code
PDF
Bringing bright ideas to life
PDF
The why and how of moving to php 8
PDF
The why and how of moving to php 7
PDF
My app is secure... I think
PDF
My app is secure... I think
PDF
Building interactivity with websockets
PDF
Bringing bright ideas to life
ODP
Your app lives on the network - networking for web developers
ODP
The why and how of moving to php 7.x
ODP
The why and how of moving to php 7.x
ODP
Beyond php - it's not (just) about the code
ODP
My app is secure... I think
ODP
Building interactivity with websockets
ODP
Your app lives on the network - networking for web developers
ODP
My app is secure... I think
ODP
The promise of asynchronous php
ODP
My app is secure... I think
ODP
My app is secure... I think
ODP
Practical git for developers
Beyond php - it's not (just) about the code
Bringing bright ideas to life
The why and how of moving to php 8
The why and how of moving to php 7
My app is secure... I think
My app is secure... I think
Building interactivity with websockets
Bringing bright ideas to life
Your app lives on the network - networking for web developers
The why and how of moving to php 7.x
The why and how of moving to php 7.x
Beyond php - it's not (just) about the code
My app is secure... I think
Building interactivity with websockets
Your app lives on the network - networking for web developers
My app is secure... I think
The promise of asynchronous php
My app is secure... I think
My app is secure... I think
Practical git for developers

Recently uploaded (20)

PPTX
sap open course for s4hana steps from ECC to s4
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Unlocking AI with Model Context Protocol (MCP)
DOCX
The AUB Centre for AI in Media Proposal.docx
 
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Approach and Philosophy of On baking technology
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
cuic standard and advanced reporting.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
sap open course for s4hana steps from ECC to s4
Network Security Unit 5.pdf for BCA BBA.
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
MYSQL Presentation for SQL database connectivity
Diabetes mellitus diagnosis method based random forest with bat algorithm
Unlocking AI with Model Context Protocol (MCP)
The AUB Centre for AI in Media Proposal.docx
 
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Encapsulation theory and applications.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Encapsulation_ Review paper, used for researhc scholars
Approach and Philosophy of On baking technology
Programs and apps: productivity, graphics, security and other tools
cuic standard and advanced reporting.pdf
Chapter 3 Spatial Domain Image Processing.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Building Integrated photovoltaic BIPV_UPV.pdf

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

  • 1. When dynamic becomes static – the next step in web caching techniques Wim Godden Cu.be Solutions
  • 2. Disclaimer The next step as in : what you will be doing in the future Not as in : go home and run it ;-)
  • 3. 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
  • 4. Who are you ? Developers ? System/network engineers ? Managers ?
  • 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
  • 9. Old-school PHP : 'rebuild-every-time'
  • 11. PHP : let's cache
  • 13. PHP : dynamic content in static content
  • 15. PHP : multiple webservers
  • 16. PHP : push updates to cache
  • 17. Today
  • 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. Varnish - ESI Perfect for caching pages <esi:include src="/top"/> <esi:include src="/news"/> Article content page <esi:include src="/nav"/> <esi:include src="/article/732"/> In your Varnish config : sub vcl_fetch { if (req.url == "/news") { esi; /* Do ESI processing */ set obj.ttl = 2m; } elseif (req.url == "/nav") { esi; set obj.ttl = 1m; } elseif …. …. }
  • 24. A simple benchmark – 2KByte JPEG Apache 2.2 4210 IIS 7.5 3960 Varnish 3.0 11400
  • 25. 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
  • 26. 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
  • 27. ESI → no caching on user-specific content ? Logged in as : Wim Godden TTL = 0s ? TTL=1h 5 messages TTL = 5min
  • 28. Nginx Web server Reverse proxy Lightweight, fast 12.81% of all Websites
  • 29. Nginx No threads, event-driven Uses epoll / kqueue Low memory footprint 10000 active connections = normal
  • 30. ESI on Nginx Logged in as : Wim Godden 5 messages Menu NEWS
  • 31. 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" />
  • 32. Requesting /page (1st time) Nginx 1 Shared memory /page 4 /page 3 2
  • 33. Requesting /page ESI subrequests (1st time) Nginx 1 2 3 /menu /news /top (in ESI session)
  • 34. Requesting /page (next time) Nginx Shared memory 1 /page 2 /page /menu /news /top (in ESI session)
  • 35. New message is sent... POST /send o i nt rt e ins ... se t (.. .) DB top (in ESI session)
  • 36. 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
  • 37. News added addnews() method o i nt rt e ins ... se t (.. .) DB Memcache key /news
  • 38. 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
  • 39. 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" />
  • 40. First release : ESI Part of the ESI 1.0 spec Only relevant features implemented Extension for dynamic session support But : unavailable for copyright reasons
  • 41. Rebuilt from scratch : SCL Session-specific Caching Language Language details : Control structures : if/else, switch/case, foreach Variable handling Strings : concatenation, substring, ...
  • 42. SCL code samples You are logged in as : <scl:session_var("person_name") /> You are logged in as : <@s("person_name") />
  • 43. 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>
  • 44. 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>
  • 45. 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>
  • 46. 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
  • 48. 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
  • 49. Why is it so much faster ?
  • 50. A real example : vBulletin
  • 51. A real example : vBulletin isAdmin session variable Thread isModerator session variable
  • 52. 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)
  • 53. 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 : Dec-Jan Final : Q1-Q2 (on Github !)
  • 54. So...
  • 58. Thanks ! Please rate my talk : http://joind.in/9568

Editor's Notes