This document summarizes a presentation about using caching and reverse proxies like Nginx and Varnish to improve PHP application performance and scalability. It discusses using Edge Side Includes (ESI) and a custom caching language (SCL) to cache dynamic and user-specific content on the edge. Benchmark results show these techniques reducing server requirements by over 80% for some applications like vBulletin forums. The presenter also provides contact information and announces plans to open source the SCL caching language.
2. 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
3. Who are you ?
Developers ?
System/network engineers ?
Managers ?
23. 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
24. 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
25. ESI → no caching on user-specific content ?
Logged in as : Wim Godden
5 messages
TTL = 5minTTL=1h
TTL = 0s ?
31. Requesting /page ESI subrequests (1st
time)
Nginx
1
2
3
/menu
/news
/top (in ESI session)
32. Requesting /page (next time)
Nginx
Shared memory
1
2
/page
/menu
/news
/top (in ESI session)
/page
33. New message is sent...
POST /send
DB
insert into...
set(...)
top (in ESI session)
34. 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
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
No TTLs for non-specific content
37. How many Memcache requests ?
Logged in as : Wim Godden
5 messages
<scl:include key="news" src="/news" ttl="5m" />
<scl:include
key="menu"
src="/menu"
ttl="1h" />
<scl:include key="top" src="/top" session="true" ttl="1h" />
38. First release : ESI
Part of the ESI 1.0 spec
Only relevant features implemented
Extension for dynamic session support
But : unavailable for copyright reasons
39. Rebuilt from scratch : SCL
Session-specific Caching Language
Language details :
Control structures : if/else, switch/case, foreach
Variable handling
Strings : concatenation, substring, ...
43. 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
45. 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
48. A real example : vBulletin
Thread
isModerator session variable
isAdmin session variable
49. A real example : vBulletin
DB Server Load Web Server Load Max Requests/sec (1 = 282)
0
5
10
15
20
25
30
35
Standard install
With Memcached
Nginx + SCL + memcached
50. Availability
Good news :
It will become Open Source
It's solid : stable at 4 customers
Bad news :
First customer holds copyrights
Total rebuild
→ Open Source release
Beta : Sep 2013
Final : End 2013 (on Github !)