2. Outline
• Varnish in general
• Overview
• Inner workings
• Varnish and Edge Side Includes
• Overview
• Integrating with TYPO3 Cache
• Different strategies
• ESI Vs. Ajax
• Purging
• Cache control headers
• Making static content client cacheable.
• Technical walk through of Varnish conf - MOC Best practices
4. Varnish - defined
• 1. To cover with varnish.
• 2. To give a smooth and glossy
finish to.
• 3. To give a deceptively attractive
appearance to.
5. Varnish - in a nutshell
Browser Varnish Webserver
No
Exists in cache?
Generate content or
Yes serve file.
Send appropriate cache
No
headers.
Cacheable?
Request file
Serve Yes
content
Insert into
mem cache
6. Poul-Henning Kamp
“The majority of you are doing that wrong. Not just wrong as in not
perfect, but wrong as in wasting half, or more, of your performance.
7. You are doing it
wrong! Poul-Henning Kamp
“The majority of you are doing that wrong. Not just wrong as in not
perfect, but wrong as in wasting half, or more, of your performance.
9. Use the operating system - Dont
fight the kernel!
• Let the operatingsweat keeping track og “hot”
dont break your
system handle all memory -
and “cold” content
• Use shared memory for all logging and
statistics
10. Purging - the right way
• Dont traverse the entire cache when purging
objects!
• Keep track of purge regular expressions only
check objects agains list og purges (but
and
once).
13. Fighting the kernel
• System: Create object i memory
• System determines that object is “cold”
• The Kernel runs out of memory
• Kernel Pages (caches) ram to disc
14. Fighting the kernel
• System: Create object i memory
• System determines that object is “cold”
• The Kernel runs out of memory
• Kernel Pages (caches) ram to disc
• System caches object to disk (DiskIO)
• System creates file (DiskIO)
• Systems requests object from kernel.
• Kernel has to fetch from own diskcache
• System writes to file (DiskIO). Deletes from RAM
15. Fighting the kernel
• System: Create object i memory
• System determines that object is “cold”
• The Kernel runs out of memory
• Kernel Pages (caches) ram to disc
• System caches object to disk (DiskIO)
• System creates file (DiskIO)
• Systems requests object from kernel.
• Kernel has to fetch from own diskcache
• System writes to file (DiskIO). Deletes from RAM
• System: Object is needed, find from own disk cache, and insert into
RAM
• Kernel has to flush other stuff to disc, to make room for new
object.
• ....
16. Performance
• Onetiming purposes is 7 system calls - 4 are
for
cached delivery
• Can deliver about 150.000 r/sec (cached
content)
17. Performance
• Onetiming purposes is 7 system calls - 4 are
for
cached delivery
• Can deliver about 150.000 r/sec (cached
content)
18. Performance
• Onetiming purposes is 7 system calls - 4 are
for
cached delivery
• Can deliver about 150.000 r/sec (cached
content)
21. Varnish - edge side includes
Browser Varnish Webserver
No
Exists in cache?
Generate content or
Yes serve file.
Send appropriate cache
No
headers.
Cacheable?
No Contains
ESI Yes
markers?
Request file
Insert into
mem cache
Yes
Generate partial
content
Stitch
Insert into
content
mem cache
together
22. Using ajax for dynamic content
Browser Varnish Webserver
No
Exists in cache?
Generate content or
Yes serve file.
Send appropriate cache
No
headers.
Cacheable?
Serve Yes
content
Request file Insert into
mem cache
Generate partial
content
27. Best practices - respect cache-
control headers
• By default respect cache headers
• Varnish default TTL set to 0s (default is not 0, depending on build)
• No cache headers - no caching in varnish
• Strip cache headers when serving to client
28. Best practices - respect cache-
control headers
• By default respect cache headers
• Varnish default TTL set to 0s (default is not 0, depending on build)
• No cache headers - no caching in varnish
• Strip cache headers when serving to client
• ...except for resources
• png|gif|jpg|swf|js|css are always cached. In varnish for 1 week, and in
client browser for 1hour.
29. Best practices - respect cache-
control headers
• By default respect cache headers
• Varnish default TTL set to 0s (default is not 0, depending on build)
• No cache headers - no caching in varnish
• Strip cache headers when serving to client
• ...except for resources
• png|gif|jpg|swf|js|css are always cached. In varnish for 1 week, and in
client browser for 1hour.
• ... and TYPO3 backend
• Never cache typo3/ content (except resources which can be cached)
30. Disable cache when front-end user
logged in
• Write special cooking upon login to TYPO3
front-end
• Varnishcontent (except for resources) and
passes
configuration respects cookie
31. Other stuff
• Edge side includes
• Allow stale content for 24 hours
• Pipe typo3 login (instead of pass)
• Fixes problem with login whn load ballancing
32. The VCL walkthrough
• Check the in
production.vcl
moc_cache
extension (1.1
or later)
33. I want my
website to
perform!
So where can I get the moc_varnish ext?
34. TYPO3 Ext repo, or GIT
• Fetch from TYPO3 Ext Repo
• Or clone from http://gerrit.mocsystems.com/
p/moc_varnish.git
• Forge: http://forge.typo3.org/projects/
extension-moc_varnish/