Download - Varnish to the rescue
![Page 1: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/1.jpg)
Varnish to the rescue
Leszek Krupiński
![Page 2: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/2.jpg)
@leafnode
PHPers Manual
Consultant Architect
![Page 3: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/3.jpg)
intro
![Page 4: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/4.jpg)
web
1. User 2. Browser 3. Server
![Page 5: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/5.jpg)
user is impatient
![Page 6: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/6.jpg)
fast!
![Page 7: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/7.jpg)
100ms
![Page 8: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/8.jpg)
1s =
-11% Page Views -16% User Satisfaction
-7% Conversion
![Page 9: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/9.jpg)
1-5s !
32% consumers lost
![Page 10: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/10.jpg)
(2012)
average: 2.45s
![Page 11: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/11.jpg)
Optimize application
![Page 12: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/12.jpg)
• Frameworks • Limits • Time-consuming operations • Cost
![Page 13: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/13.jpg)
Maybe it’s not needed?
![Page 14: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/14.jpg)
Cache!
![Page 15: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/15.jpg)
Many levels, many solutions
![Page 16: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/16.jpg)
But… my site is very dynamic!
![Page 17: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/17.jpg)
1s TTL
![Page 18: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/18.jpg)
From 20 rq/s to 1 rq/s in single apt-get install
![Page 19: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/19.jpg)
Fresh content takes most hits
![Page 20: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/20.jpg)
Varnish The Web Accelerator
![Page 21: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/21.jpg)
![Page 22: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/22.jpg)
![Page 23: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/23.jpg)
![Page 24: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/24.jpg)
Architecture
![Page 25: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/25.jpg)
Works with the kernel not against it
![Page 26: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/26.jpg)
mmap, threads, epoll, kqueue
![Page 27: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/27.jpg)
Backends: memory, file
![Page 28: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/28.jpg)
If it fits in memory, use memory
![Page 29: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/29.jpg)
Works on HTTP headers
![Page 30: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/30.jpg)
Cache-control, If-Modified-Since, Expires, Pragma, If-None-Match, Etag,
Vary, Age
![Page 31: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/31.jpg)
Varnish uses language both browser and
backend know
![Page 32: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/32.jpg)
In-memory logs
![Page 33: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/33.jpg)
75 000 rq/s at TMECC 143 000 rq/s at Redpill-Linpro
![Page 34: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/34.jpg)
Do I need a lot of memory?
![Page 35: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/35.jpg)
Nope
![Page 36: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/36.jpg)
Fresh content takes most hits
![Page 37: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/37.jpg)
Take that, slashdot effect!
![Page 38: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/38.jpg)
Configuration
![Page 39: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/39.jpg)
Lots of possibilities
![Page 40: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/40.jpg)
Unfortunately, lots of possibilities
![Page 41: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/41.jpg)
Varnish Configuration
Language
![Page 42: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/42.jpg)
Compiled directly to C
![Page 43: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/43.jpg)
Hook-like configuration
![Page 44: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/44.jpg)
vcl_fetch vcl_recv
vcl_hit vcl_miss
vcl_hash vcl_pass
vcl_deliver vcl_error
![Page 45: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/45.jpg)
![Page 46: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/46.jpg)
restart
![Page 47: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/47.jpg)
Objects
req, bereq, resp, beresp, obj
![Page 48: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/48.jpg)
Defaults
![Page 49: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/49.jpg)
vcl_recv
![Page 50: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/50.jpg)
![Page 51: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/51.jpg)
![Page 52: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/52.jpg)
![Page 53: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/53.jpg)
vcl_hash
![Page 54: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/54.jpg)
![Page 55: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/55.jpg)
VMods
![Page 56: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/56.jpg)
throttle, cookie, shield, redis, memcached, curl,
url code, redirect…
![Page 57: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/57.jpg)
Varnish: load balancer
failover system
![Page 58: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/58.jpg)
![Page 59: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/59.jpg)
Directors
![Page 60: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/60.jpg)
Default: random
![Page 61: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/61.jpg)
Round-robin, client, hash, dns
![Page 62: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/62.jpg)
Health check
![Page 63: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/63.jpg)
![Page 64: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/64.jpg)
Saint mode
![Page 65: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/65.jpg)
Grace mode
![Page 66: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/66.jpg)
Two hard things
![Page 67: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/67.jpg)
Invalidate cache
![Page 68: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/68.jpg)
Ban listEfficient way to invalidate cache
![Page 69: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/69.jpg)
Over HTTP
![Page 70: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/70.jpg)
Use PURGE header
![Page 71: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/71.jpg)
![Page 72: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/72.jpg)
![Page 73: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/73.jpg)
![Page 74: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/74.jpg)
Real life issues
![Page 75: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/75.jpg)
Cookies
![Page 76: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/76.jpg)
Varnish does not cache when cookies
are involved
![Page 77: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/77.jpg)
Ignore cookies
![Page 78: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/78.jpg)
![Page 79: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/79.jpg)
Pick cookies
![Page 80: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/80.jpg)
![Page 81: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/81.jpg)
Pick URLs
![Page 82: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/82.jpg)
![Page 83: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/83.jpg)
Redirects
![Page 84: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/84.jpg)
POST
![Page 85: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/85.jpg)
PHP sessions
![Page 86: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/86.jpg)
CURL VMod
![Page 87: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/87.jpg)
![Page 88: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/88.jpg)
![Page 89: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/89.jpg)
PHP + memcached
![Page 90: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/90.jpg)
![Page 91: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/91.jpg)
mobile detection
![Page 92: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/92.jpg)
![Page 93: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/93.jpg)
mobile detection II
![Page 94: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/94.jpg)
![Page 95: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/95.jpg)
VMod: DeviceAtlas Mobile Detection
![Page 96: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/96.jpg)
Cache “one-time” data
![Page 97: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/97.jpg)
Example: dynamic image resizing
![Page 98: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/98.jpg)
1B pictures 10 sizes
![Page 99: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/99.jpg)
apache + moddims
![Page 100: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/100.jpg)
Fresh content takes most hits
![Page 101: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/101.jpg)
Different TTL for different parts?
![Page 102: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/102.jpg)
ESI!
![Page 103: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/103.jpg)
![Page 104: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/104.jpg)
![Page 105: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/105.jpg)
Testing?
![Page 106: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/106.jpg)
jQuery plugin
![Page 107: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/107.jpg)
Just in! Varnish 4.0
![Page 108: Varnish to the rescue](https://reader031.vdocuments.net/reader031/viewer/2022030316/5872a21b1a28ab07208b5f09/html5/thumbnails/108.jpg)
Log query language, background fetch, byte
counters, security improvements