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

1,354 views

Published on

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

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,354
On SlideShare
0
From Embeds
0
Number of Embeds
49
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

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

  1. 1. Varnish, a HTTP accelerator SPEED HAS NEVER KILLED ANYONE Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  2. 2. CHRISTIAN NÖLLE Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  3. 3.      Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle Degree Self-employed Scientific assistant University Living
  4. 4. VARNISH = (HTTP|WEB) (PROXY|ACCELERATOR) Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  5. 5. No worries! Our setup is fast! We‘ve got speed! Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  6. 6. How much can it handle? Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  7. 7. 10 Req/s? 50 Req/s? 500 Req/s? 687 Re… 100 Req/s? Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  8. 8. Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  9. 9. Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  10. 10. Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  11. 11. Source: Peter Suneson, http://www.sxc.hu/profile/CMSeter Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  12. 12. SUDDENLY BECOMING STATIONARY, THAT'S WHAT GETS YOU. Jeremy Clarkson Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  13. 13. ? No Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle Yes
  14. 14. FAIRLY MODERN PIECE OF SOFTWARE Varnish works on 32-bit, but was designed for 64bit. It's all about virtual 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 you must have the Linux - 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 für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  15. 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 God„s sake! Let it listen to port 80 Change DNS of Domain to varnish server Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  16. 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 für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  17. 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 = VCL Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  18. 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 für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  19. 19. SUBROUTINES vcl_recv vcl_pipe vcl_hash vcl_pass vcl_miss vcl_hit vcl_deliver Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle vcl_fetch
  20. 20. HIT vcl_recv vcl_pipe vcl_hash vcl_pass vcl_miss vcl_hit vcl_deliver Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle vcl_fetch
  21. 21. MISS vcl_recv vcl_pipe vcl_hash vcl_pass vcl_miss vcl_hit vcl_deliver Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle vcl_fetch
  22. 22. PASS vcl_recv vcl_pipe vcl_hash vcl_pass vcl_miss vcl_hit vcl_deliver Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle vcl_fetch
  23. 23. PIPE vcl_recv vcl_pipe vcl_hash vcl_pass vcl_miss vcl_hit vcl_deliver Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle vcl_fetch
  24. 24. ALL UP AND RUNNING, BUT… Easy! Cache is too small! Source: Bob Smith, http://sxc.hu/browse.phtml?f=profile&l=brainloc Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  25. 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 für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  26. 26. TYPO3 always sends a cookie: fe_typo_user Even if not needed Or only needed for certain parts of the site; e.g. login TYPO3 AND COOKIES Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  27. 27. Know your content! Know your installation of TYPO3! Know your bad hacks! BY THE WAY: YOU GOT ANY CLUE OF THE WEBSITE, YOU’D LIKE TO CACHE? Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  28. 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 don‟t need the fe_typo3_user cookie at all? – $TYPO3_CONF_VARS['FE']['dontSetCookie'] = 1 Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  29. 29. Let‟s see the real stuff! DIG DEEPER! Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  30. 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 für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  31. 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 für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  32. 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 für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  33. 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 für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  34. 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” website Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  35. 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 für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  36. 36. WHEN YOU HAVE DONE IT RIGHT: Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  37. 37. And remember: SPEED HAS NEVER KILLED ANYONE Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  38. 38. Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle
  39. 39. Mail: noelle@uni-wuppertal.de TWITTER: @STBC Zentrum für Informations- und Medienverarbeitung Dipl.-Ök. Christian Nölle

×