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
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. 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. 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. 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. 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
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. 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. 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. 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. 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. Let‟s see the real stuff!
DIG DEEPER!
Zentrum für Informations- und Medienverarbeitung
Dipl.-Ök. Christian Nölle
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. 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. 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. 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. 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. 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. WHEN YOU HAVE DONE IT RIGHT:
Zentrum für Informations- und Medienverarbeitung
Dipl.-Ök. Christian Nölle
37. And remember:
SPEED HAS NEVER KILLED
ANYONE
Zentrum für Informations- und Medienverarbeitung
Dipl.-Ök. Christian Nölle