39
Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle SPEED HAS NEVER KILLED ANYONE Varnish, a HTTP accelerator

"Speed has never killed anyone" - Varnish, a HTTP accelerator

Embed Size (px)

DESCRIPTION

Varnish is a web accelerator, which acts as a reverse HTTP caching proxy in front of your TYPO3 servers - but unlike other reverse proxys varnish is built for speed. This talks gives you a insight into how to set it up and configuring varnish right for TYPO3. Talk held at the TYPO32 Conference East Europe in Cluj-Napoca, Rumania

Citation preview

  • 1. Varnish, a HTTP acceleratorSPEED HAS NEVER KILLED ANYONEZentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle

2. CHRISTIAN NLLEZentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 3. Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian NlleDegree Self-employed Scientific assistant University Living 4. VARNISH = (HTTP|WEB) (PROXY|ACCELERATOR)Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 5. No worries! Our setup is fast! Weve got speed!Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 6. How much can it handle?Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 7. 10 Req/s?50 Req/s?500 Req/s? 687 Re 100 Req/s? Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 8. Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 9. Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 10. Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 11. Source: Peter Suneson, http://www.sxc.hu/profile/CMSeterZentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 12. SUDDENLY BECOMING STATIONARY, THAT'S WHAT GETS YOU. Jeremy ClarksonZentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 13. ? NoZentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian NlleYes 14. FAIRLY MODERN PIECE OF SOFTWARE Varnish works on 32-bit, but was designed for64bit. It's all aboutvirtual memory: Things like stack size suddenly matter on 32bit. If you must use Varnish on 32-bit, you're somewhat on your own. However, try to fit it within 2GB. I wouldn't recommend a cache larger than 1GB, and no more than a few hundred threads... (Why are you on 32bit again?) In order for you to install Varnish youmust have theLinux - FreeBSD Solaris and root access Varnish can be installed on other UNIX systems as following:well, but it is not tested particularly well on these platforms. Varnish is, from time to time, said to work on: 32 bit versions of the before-mentioned systems. OS X NetBSD OpenBSD Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 15. GET IT UP AND RUNNING Put your cache in memory Put Your Cache In Memory If not applicable: Buy more memory! If not applicable: Put it on disk, for Gods sake! Let it listen to port 80 Change DNS of Domain to varnish serverZentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 16. FIRE IT UP! varnishd -f /etc/varnish/my.vcl -s malloc,1G -T 127.0.0.1:2000 -a 0.0.0.0:80 -f /etc/varnish/my.vcl Where is my configuration file? -s malloc,1G What kind of cache storage and how big is it? -T 127.0.0.1:6082 Text-administration interface. Listening on? -a 0.0.0.0:80 Listen on port 80 for all HTTP requests Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 17. ANY CONFIG? Sure! Minimum config needed at installation time: Define your backend server! Use it with -f /etc/varnish/myown.vcl at startup time Write it with Varnish Configuration Language = VCLZentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 18. VCL Defines caching rules Gets parsed, compiled and linked against varnish Default VCL is always included after your rules! Keep it simple! Focus on caching policy subroutines!Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 19. SUBROUTINES vcl_recv vcl_pipe vcl_hashvcl_pass vcl_missvcl_hitvcl_deliverZentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nllevcl_fetch 20. HIT vcl_recv vcl_pipe vcl_hashvcl_pass vcl_missvcl_hitvcl_deliverZentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nllevcl_fetch 21. MISS vcl_recv vcl_pipe vcl_hashvcl_pass vcl_missvcl_hitvcl_deliverZentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nllevcl_fetch 22. PASS vcl_recv vcl_pipe vcl_hashvcl_pass vcl_missvcl_hitvcl_deliverZentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nllevcl_fetch 23. PIPE vcl_recv vcl_pipe vcl_hashvcl_pass vcl_missvcl_hitvcl_deliverZentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nllevcl_fetch 24. ALL UP AND RUNNING, BUTEasy! Cache is too small! Source: Bob Smith, http://sxc.hu/browse.phtml?f=profile&l=brainloc Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 25. Varnish will, in the default configuration, not cache a object coming from the backend with a Set-Cookie header present. Also, if the client sends a Cookie header, Varnish will bypass the cache and go directly to the backend.BEWARE OF COOKIES!Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 26. TYPO3 always sends a cookie: fe_typo_user Even if not needed Or only needed for certain parts of the site; e.g. loginTYPO3 AND COOKIESZentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 27. Know your content! Know your installation of TYPO3! Know your bad hacks!BY THE WAY: YOU GOT ANY CLUE OF THE WEBSITE, YOUD LIKE TO CACHE? Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 28. WHAT TO DO WITH COOKIES? First of all: Depends on your setting! Investigate! Numerous possibilities, some of them: Use an extension (moc_varnish, cachinfo, varnish, vcc) Unset cookies in VCL, allow only where needed! You dont need the fe_typo3_user cookie at all? $TYPO3_CONF_VARS['FE']['dontSetCookie'] = 1Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 29. Lets see the real stuff!DIG DEEPER!Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 30. backend default { .host = "12.34.56.78"; .port = "80"; .probe = { .url = "/probe.txt"; .timeout = 1s; .interval = 3s; .window = 10; .threshold = 5; } } PROBE YOUR BACKEND SERVERS ON HEALTH! Some real world VCL examples Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 31. director test round-robin { { .backend = server1; } { .backend = server2; } { .backend = { .host = "12.34.56.78"; .port = "82"; } } }DEFINE DIRECTORS Some real world VCL examples Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 32. sub vcl_recv { if (req.backend.healthy) { set req.grace = 30s; } else { set req.grace = 1h; } }GRACE MODE: DELIVER AN OLD OBJECT Some real world VCL examples Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 33. sub vcl_fetch { if (beresp.http.cache-control ~ "(no-cache|private)" || beresp.http.pragma ~ "no-cache") { set beresp.ttl = 0s; # Make sure that We remove alle cache headers, so the Browser does # not cache it for us! remove beresp.http.Cache-Control; remove beresp.http.Expires; remove beresp.http.Last-Modified; remove beresp.http.ETag; remove beresp.http.Pragma; return (deliver); } }RESPECT NO CACHE SETTING FROM BACKEND Some real world VCL examples Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 34. WHAT ELSE DO WE DO? Device detection Lifetime manipulation if requested more often, lifetime in cache gets prolonged Let internal network purge an object with STRG + F5 from browser But only when backends are healthy! Cache all images, css, js a.s.f. for at least one week Saint mode to deal with strange content from backend Mix up different sources in one websiteZentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 35. START IT RIGHT: Find out about your website Go for varnish package, not source! Keep your VCL simple Monitor your varnish Use the tools provided (varnishstat, varnishlog varnishhist) Keep an eye on syslog/messages Munin / Cacti Tune only when there is a problem. Do not overfix!Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 36. WHEN YOU HAVE DONE IT RIGHT:Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 37. And remember:SPEED HAS NEVER KILLED ANYONEZentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 38. Zentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle 39. Mail: [email protected]: @STBCZentrum fr Informations- und Medienverarbeitung Dipl.-k. Christian Nlle