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.
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 ?
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
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
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") />
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
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 !)