when dynamic becomes static
TRANSCRIPT
![Page 1: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/1.jpg)
When dynamic becomes static(the next step in web caching techniques)
Wim GoddenCu.be Solutions
@wimgtr
![Page 2: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/2.jpg)
Who am I ?
Wim Godden (@wimgtr)
![Page 3: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/3.jpg)
Where I'm from
![Page 4: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/4.jpg)
Where I'm from
![Page 5: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/5.jpg)
Where I'm from
![Page 6: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/6.jpg)
Where I'm from
![Page 7: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/7.jpg)
Where I'm from
![Page 8: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/8.jpg)
Where I'm from
![Page 9: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/9.jpg)
My town
![Page 10: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/10.jpg)
My town
![Page 11: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/11.jpg)
Belgium – the traffic
![Page 12: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/12.jpg)
Who am I ?
Wim Godden (@wimgtr)
Founder of Cu.be Solutions (http://cu.be)
Open Source developer since 1997
Developer of OpenX, PHPCompatibility, PHPConsistent, ...
Speaker at Open Source conferences
![Page 13: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/13.jpg)
Who are you ?
Developers ?
System/network engineers ?
Managers ?
![Page 14: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/14.jpg)
Quick note
Whenever you see
feel free to think
![Page 15: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/15.jpg)
To understand the present
Understand the past
![Page 16: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/16.jpg)
The Stone Age
New blog post by : caveman003
![Page 17: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/17.jpg)
Pre-dynamic : draw it and make html
![Page 18: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/18.jpg)
The Egyptian Era
![Page 19: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/19.jpg)
Old-school dynamic : 'rebuild-every-time'
![Page 20: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/20.jpg)
The Industrial Revolution
![Page 21: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/21.jpg)
Dynamic : let's cache
![Page 22: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/22.jpg)
Extra ! Extra !
![Page 23: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/23.jpg)
Dynamic content in static content
![Page 24: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/24.jpg)
The Modern Era
![Page 25: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/25.jpg)
More load, more webservers
![Page 26: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/26.jpg)
Pushing updates to cache
![Page 27: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/27.jpg)
Today
![Page 28: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/28.jpg)
Adding reverse proxy caching
![Page 29: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/29.jpg)
Typical website structure
Article content page
Page content
Header
Latest news
Navigation
![Page 30: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/30.jpg)
Caching blocks with individual TTLs
Article content page
Page content
Top header(TTL = 2h)
Latest news
Navigation(TTL = 1h)
![Page 31: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/31.jpg)
Caching blocks with individual TTLs
Article content page
Page content (TTL = 30m)
Top header(TTL = 2h)
Latest news (TTL = 2m)
Navigation(TTL = 1h)
![Page 32: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/32.jpg)
ESI – how it works
GET /pageGET /page
![Page 33: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/33.jpg)
ESI – how it works
<html>...<esi:include src="/top"/><esi:include src="/nav"/><div id=”something”> <esi:include src="/latest-news"/></div><esi:include src="/article/id/732"/>...</html>
GET /pageGET /page
![Page 34: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/34.jpg)
ESI – how it works
<div id=”top-part”> <a href=”/login”>Login</a></div>
GET /top
![Page 35: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/35.jpg)
ESI – how it works
<html>...<esi:include src="/top"/><esi:include src="/nav"/><div id=”something”> <esi:include src="/latest-news"/></div><esi:include src="/article/id/732"/>...</html>
GET /pageGET /page
![Page 36: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/36.jpg)
ESI – how it works
<html>...<div id=”top-part”> <a href=”/login”>Login</a></div><esi:include src="/nav"/><div id=”something”> <esi:include src="/latest-news"/></div><esi:include src="/article/id/732"/>...</html>
GET /pageGET /page
![Page 37: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/37.jpg)
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
![Page 38: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/38.jpg)
ESI → no caching on user-specific content ?
Logged in as : Wim Godden
5 messages
TTL = 5minTTL=1h
TTL = 0s ?
![Page 39: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/39.jpg)
Error... does not compute !
![Page 40: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/40.jpg)
The semi-functional Varnish way
Use VCL to attach session id or UUID to cache entriesif( req.http.Cookie ~ "myapp_unique_user_id" ) {
set req.http.X-Varnish-Hashed-On =
regsub( req.http.Cookie, "^.*?
myapp_unique_user_id=([^;]*);*.*$", "\1" );
}
Painful, messy configuration
Inefficient and messy way to update data
POST /sendmessagePOST /sendmessage
PURGE /top?UUID
GET /page GET /top?UUID
DB
![Page 41: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/41.jpg)
The almost functional Varnish way
Varnish module : VMOD-Memcached
Connects Varnish directly to Memcached
Advantage :It works
It will speed a few things up
Disadvantage :A pain to set up
No plug&play → DIY !
Only works on info stored in session
![Page 42: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/42.jpg)
Back in 2010
![Page 43: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/43.jpg)
Avoid hitting the backend
GET /page
DB
![Page 44: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/44.jpg)
No more backend
GET /page+ SLIC
![Page 45: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/45.jpg)
Requesting /page (1st time)
Nginx
Shared memory
1
2
3
4
/page
/page
<html>...<slic:include src="/top" key=”top” session=”true”/><slic:include src="/nav" key=”nav”/><slic:include src="/article/id/732" key=”article732”/>...</html>
![Page 46: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/46.jpg)
Requesting /page SLIC subrequests (1st time)
Nginx1
2
3/nav/article732/top (in SLIC session)
/nav/article/id/732/top (with session cookie)
![Page 47: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/47.jpg)
Requesting /page (next time)
Nginx
Shared memory1
2
/page/nav/article732/top (in SLIC session)
/page
![Page 48: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/48.jpg)
SLIC on Nginx
<slic:include key="article732" src="/article/732" /><slic:includekey="nav"src="/nav" />
<slic:include key="top" src="/top" session="true" />Logged in as : Wim Godden
5 messages ???
![Page 49: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/49.jpg)
New message is sent...
POST /send
DB
insert i
nto... set(...)
top (in SLIC session)
![Page 50: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/50.jpg)
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
![Page 51: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/51.jpg)
News added
addnews() method
DB
insert i
nto... set(...)
Memcache key /news
![Page 52: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/52.jpg)
First release : ESI
Part of the ESI 1.0 spec
Only relevant features implemented
Extension for dynamic session support
But : unavailable for copyright reasons
![Page 53: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/53.jpg)
Rebuilt from scratch : SLIC
Control structures : if/else, switch/case, foreach
Variable handling
Strings : concatenation, substring, …
Exception handling, header manipulation, …
JSON support !
![Page 54: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/54.jpg)
SLIC code samples
You are logged in as : <slic:session_var("person_name") />
![Page 55: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/55.jpg)
SLIC code samples
<slic:switch var="session_var('isAdmin')">
<slic:case value="1"> <slic:include key="admin-buttons" src="/admin-buttons.php" /> </slic:case>
<slic:default> <div id="just-a-user"> <slic:include key="user-buttons" src="/user-buttons.php" /> </div> </slic:default>
</slic:switch>
![Page 56: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/56.jpg)
SLIC code samples
<slic:foreach item="messageId" src="global_var('thread' + query_var('threadId'))">
<slic:include key="'thread-message_' + messageId" src="'/thread/message.php?id=' + messageId" />
</slic:foreach>
![Page 57: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/57.jpg)
Approaches – full block
<p id=”LoggedInAs”> You are logged in as : Wim Godden</p><p id=”MessageCount”> 5 messages</p>
Logged in as : Wim Godden
5 messages
top_432
![Page 58: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/58.jpg)
Approaches – individual variables
<p id=”LoggedInAs”> You are logged in as : <slic:session_var("person_name") /></p><p id=”MessageCount”> <slic:session_var(“messages”) /> messages</p>
Logged in as : Wim Godden
5 messages
![Page 59: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/59.jpg)
Approaches – JSON
<p id=”LoggedInAs”> You are logged in as : <slic:session_var("userData").person_name /></p><p id=”MessageCount”> <slic:session_var(“userData”).message_count /> messages</p>
Logged in as : Wim Godden
5 messages
![Page 60: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/60.jpg)
Identifying the user
In Nginx configuration :slic_session_cookie <name> → Defined by language (or configurable)
slic_session_identifier <string> → Defined by you
Example for PHP :slic_session_cookie PHPSESSID
slic_session_identifier UserID
![Page 61: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/61.jpg)
Identifying the user
Nginx + SLIC
Cookie :PHPSESSID =jpsidc1po35sq9q3og4f3hi6e2
get UserID_jpsidc1po35sq9q3og4f3hi6e2432
![Page 62: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/62.jpg)
Retrieving user specific content
Nginx + SLIC
get userData_432
Cookie :PHPSESSID =jpsidc1po35sq9q3og4f3hi6e2
![Page 63: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/63.jpg)
What's the result ?
![Page 64: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/64.jpg)
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 → 380
Expected savings : €1.5 Million per year
![Page 65: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/65.jpg)
Why is it so much faster ?
![Page 66: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/66.jpg)
Code changes
Required
Template conversion
Push-to-DB → Push-to-DB + Push-to-Cache
Choice :If user is logged in → push updates to cache
If user is not logged in → warm up cache on login
![Page 67: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/67.jpg)
Availability
Good news :The concept is solid : ESI version stable at 4 customers
Open Source
Bad news :First customer holds copyrights
Total rebuild
March : v0.1 (include, variable handling, …)
Final release : Q2-3 2015 (?)
Site : http://slic.cu.be
Code : Github
![Page 68: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/68.jpg)
Some technical details
Written in Lua (with LuaJIT)Each SLIC:include is a subrequest
Groups cache key requests together for multiget
Shares cache results across all subrequests
Template compilation (!!)
Memcached implemented
Redis and others in the pipeline
Not RFC compliant yet
Unit tested
Future (1.0 or beyond) :Translation functionality
...
![Page 69: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/69.jpg)
So...
![Page 70: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/70.jpg)
Questions ?
![Page 71: When dynamic becomes static](https://reader035.vdocuments.us/reader035/viewer/2022062320/55a66dce1a28ab6b4f8b4603/html5/thumbnails/71.jpg)
Questions ?