Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

T3DD12 Caching with Varnish

879 views

Published on

Apr 16, 2012

Published in: Technology
  • Be the first to comment

T3DD12 Caching with Varnish

  1. 1. Make yourwebsite flyusing VarnishFabrizio BrancaT3DD12
  2. 2. System DeveloperAOE mediaWiesbadenTYPO3 & MagentoTwitter: @fbrncBlog: http://www.fabrizio-branca.deFabrizio Branca
  3. 3. • Who has any experience with Varnish?• Who has a production site using Varnish?• Who has played around with Varnish?• Who has experience with any otherreverse proxy solution?You?!
  4. 4. 1m visitors in 24h5000 concurrent users
  5. 5. Secret ingredient:Varnishhttp://www.flickr.com/photos/judybaxter/8155091/
  6. 6. Reverse proxy cachingBrowser TYPO3(Apache + PHP + Mysql)RequestResponse
  7. 7. Reverse proxy cachingBrowser TYPO3(Apache + PHP + Mysql)Varnish
  8. 8. Reverse proxy cachingBrowser VarnishNginx TYPO3(Apache + PHP + Mysql)- SSL termination- (Compression)
  9. 9. Reverse proxy cachingBrowser VarnishNginx TYPO3(Apache + PHP + Mysql)
  10. 10. VarnishHTTPAcceleratorCachingReverse ProxyLoadBalancerFailoversystem„Varnish makes websites fly“
  11. 11. • Created by Poul-Henning Kamp• Varnish Configuration Language (VCL)– DSL, will be translated into C code and compiled• Varnish uses thread and memorymanagement of the operation system• Additional tools: varnishtop, varnishlog,…• Online-Documentation:http://www.varnish-cache.org/docs/2.1/Varnish
  12. 12. Stability
  13. 13. Efficiency
  14. 14. CPU load
  15. 15. Speed
  16. 16. • In Ubuntu:sudo apt-get install varnishsudo vi /etc/default/varnishSTART=yessudo /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.vclInstallation
  17. 17. SetupVarnish VarnishLoadBalancerAmazon ELBF5VarnishTYPO3 backendTYPO3 frontends
  18. 18. Nginx, Varnish, Apache setup
  19. 19. Request Lifecycle (simplified)Complete workflow: http://www.varnish-cache.org/trac/wiki/VCLExampleDefault
  20. 20. • Vary: User-Agent(also implicitly set e.g. SetEnvIf)Pitfalls
  21. 21. Tools: Varnishhist
  22. 22. • Restart: Flushes complete cache• Reload: Reads VCL without flushing cacheRestart / Reload
  23. 23. BenchmarksTYPO3without cache3,45Pages/Second10,72Pages/Second855,78Pages/SecondTYPO3with cacheTYPO3with Varnish
  24. 24. • 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: publicSending correct headers
  25. 25. • http://forge.typo3.org/projects/show/extension-cacheinfoEXT:cacheinfo
  26. 26. • http://forge.typo3.org/projects/show/extension-purge• Configuration in VCL• Access protect• Purge using Shift+ReloadPurging
  27. 27. Punching Holes…http://www.flickr.com/photos/stevendepolo/3053981107/lightbox/
  28. 28. Punching holesESI AJAXCookie /Clientstorage
  29. 29. • Different lifetimes for clients and Varnish• Cache status codes > 400• Redirects• Protect the backend!Tuning
  30. 30. • Varnish (inkl. Dokumentation)http://www.varnish-cache.org• Poul-Henning Kamp at T3CON10http://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/fbrncFurther reading
  31. 31. Questions?Mail: fabrizio.branca@aoemedia.deTwitter: @fbrncBlog: http://www.fabrizio-branca.de

×