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 solve this problem, changing the way you think about designing sites with user-specific content.
Decarbonising Buildings: Making a net-zero built environment a reality
Remove web calls and scale your site like crazy !
1. Remove PHP calls
&
scale your site like crazy !
Wim Godden
Cu.be Solutions
2. Who am I ?
Wim Godden (@wimgtr)
Owner of Cu.be Solutions (http://cu.be)
PHP developer since 1997
Developer of OpenX
Zend Certified Engineer
Zend Framework Certified Engineer
MySQL Certified Developer
Speaker at PHP and Open Source conferences
3. Who are you ?
Developers ?
System/network engineers ?
Managers ?
4. We're at a PHP conference...
… and I'm going to show you how to use less PHP
24. 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
25. 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
26. ESI → no caching on user-specific content ?
Logged in as : Wim Godden
TTL = 0s ?
5 messages
TTL=1h TTL = 5min
27. Nginx
Web server
Reverse proxy
Lightweight, fast
12.3% of all Websites
28. Nginx
No threads, event-driven
Uses epoll / kqueue
Low memory footprint
10000 active connections = normal
29. ESI on Nginx
Logged in as : Wim Godden
5 messages
Menu NEWS
30. ESI on Nginx
<esi:include src="/top" session="1" ttl="1h" />
<esi:include
src="/menu" <esi:include src="/news" ttl="5m" />
ttl="1h" />
32. Requesting /page ESI subrequests (1st time)
Nginx
1
2
3
/menu
/news
/top (in ESI session)
33. Requesting /page (next time)
Nginx
1
Shared memory
/page
2
/page
/menu
/news
/top (in ESI session)
34. New message is sent...
POST /send
o ... se
i nt t (..
e rt .)
ins
DB
top (in ESI session)
35. 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. News added
addnews() method
o ... se
i nt t (..
e rt .)
ins
DB
Memcache key /news
37. 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
Imagine doing it for the bid status on Ebay items ;-)
38. How many Memcache requests ?
Logged in as : Wim Godden
<esi:include src="/top" session="1" ttl="1h" />
5 messages
<esi:include
src="/menu" <esi:include src="/news" ttl="5m" />
ttl="1h" />
39. ESI implementation
Part of the ESI 1.0 spec
Only relevant features implemented
Extension for dynamic session support
42. Why Nginx ?
Native Memcache support
Excellent and superfast subrequest system
Including parallel subrequests
Handles thousands of connections per worker
With minimal memory footprint
Integrates with php-fpm
Performance gain (5 - 15%)
Additional features (chroot, slow request log, offline processing, ...)
Graceful rolling upgrades
44. Figures
Second customer :
No. of web servers : 72 → 8
No. of db servers : 15 → 4
Total : 87 → 12 (86% reduction !)
Third customer :
No. of total servers : +/- 1350
Expected reduction : 1350 → 300
Expected savings : €1.6 Million (6.7M złoty) per year
47. A real example : vBulletin
18
16
14
12
10 Standard install
Memcached
8 Nginx + ESI + memcached
6
4
2
0
DB Load Web Load Max load
48. Availability
Good news :
It will become Open Source
It's solid : stable at 2 customers, being installed at 2 more
Bad news :
First customer holds copyrights
Once changes for customer 3 + 4 are backported for customer 1
→ Open Source release
Binaries : Dec 2012 – Jan 2013
Source : Jan-Feb 2013 (on Github !)