Upload
aoe
View
2.403
Download
1
Embed Size (px)
Citation preview
Make your
website fly
using Varnish Fabrizio Branca
T3DD12
System Developer
AOE media
Wiesbaden
TYPO3 & Magento
Twitter: @fbrnc
Blog: http://www.fabrizio-branca.de
Fabrizio Branca
• Who has any experience with Varnish?
• Who has a production site using Varnish?
• Who has played around with Varnish?
• Who has experience with any other
reverse proxy solution?
You?!
1m visitors in 24h 5000 concurrent users
Secret ingredient:
Varnish http://www.flickr.com/photos/judybaxter/8155091/
Reverse proxy caching
Browser TYPO3 (Apache + PHP + Mysql)
Request
Response
Reverse proxy caching
Browser TYPO3 (Apache + PHP + Mysql)
Varnish
Reverse proxy caching
Browser Varnish Nginx TYPO3 (Apache + PHP + Mysql)
- SSL termination - (Compression)
Reverse proxy caching
Browser Varnish Nginx TYPO3 (Apache + PHP + Mysql)
Varnish
HTTP Accelerator
Caching Reverse Proxy
Load Balancer
Failover system
„Varnish makes websites fly“
• Created by Poul-Henning Kamp
• Varnish Configuration Language (VCL)
– DSL, will be translated into C code and compiled
• Varnish uses thread and memory management of the operation system
• Additional tools: varnishtop, varnishlog,…
• Online-Documentation: http://www.varnish-cache.org/docs/2.1/
Varnish
Stability
Efficiency
CPU load
Speed
• In Ubuntu: sudo apt-get install varnish sudo vi /etc/default/varnish START=yes sudo /etc/init.d varnish start
• Will be started automatically on boot
• Listens to port 6081 by default
• Uses 127.0.0.1:8080 as a backend by default
• /etc/varnish/default.vcl
Installation
Setup
Varnish Varnish
Load Balancer
Amazon ELB F5 Varnish
TYPO3 backend TYPO3 frontends
Nginx, Varnish, Apache setup
Request Lifecycle (simplified)
Complete workflow: http://www.varnish-cache.org/trac/wiki/VCLExampleDefault
• Vary: User-Agent
(also implicitly set e.g. SetEnvIf)
Pitfalls
Tools: Varnishhist
• Restart: Flushes complete cache
• Reload: Reads VCL without flushing cache
Restart / Reload
Benchmarks
TYPO3 without cache
3,45 Pages/Second
10,72 Pages/Second
855,78 Pages/Second
TYPO3 with cache
TYPO3 with Varnish
• config.sendCacheHeaders = 1
• The conditions for allowing client caching are: – page was cached
– No *_INT or *_EXT objects were on the page (eg. USER_INT)
– No frontend user is logged in
– No backend user is logged in
• If these conditions are met, the headers sent are: – Last-Modified [SYS_LASTCHANGED of page id]
– Expires [expire time of page cache]
– Etag [md5 of content]
– Cache-Control: max-age: [seconds til expiretime]
– Pragma: public
Sending correct headers
• http://forge.typo3.org/projects/show/extens
ion-cacheinfo
EXT:cacheinfo
• http://forge.typo3.org/projects/show/extens
ion-purge
• Configuration in VCL
• Access protect
• Purge using Shift+Reload
Purging
Punching Holes…
http://www.flickr.com/photos/stevendepolo/3053981107/lightbox/
Punching holes
ESI AJAX Cookie /
Client storage
• Different lifetimes for clients and Varnish
• Cache status codes > 400
• Redirects
• Protect the backend!
Tuning
• Varnish (inkl. Dokumentation) http://www.varnish-cache.org
• Poul-Henning Kamp at T3CON10 http://vimeo.com/16676188
• http://forge.typo3.org/projects/show/extension-moc_varnish
• http://www.fabrizio-branca.de/varnish.html
• http://www.fabrizio-branca.de
• https://github.com/fbrnc
Further reading