Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Varnish to the Rescue
Search
Leszek Krupiński
April 11, 2014
Technology
0
130
Varnish to the Rescue
Introduction to Varnish. Basics & pitfalls. Presented at techfusion.io
Leszek Krupiński
April 11, 2014
Tweet
Share
More Decks by Leszek Krupiński
See All by Leszek Krupiński
So that the daemon won’t die
leafnode
2
400
Practical PHP7
leafnode
2
460
Dobrze posól swoje hasło
leafnode
0
110
Dobrze posól swoje hasło (z notatkami)
leafnode
0
95
PHPNG kontra HHVM
leafnode
0
100
PHPNG kontra HHVM (z notatkami)
leafnode
0
70
Ewolucja PHP: PHP 5.6, NG, PHP 7, HHVM
leafnode
2
300
Sculpin - Generowanie statycznych stron w PHP
leafnode
2
63
Skalowanie aplikacji PHP
leafnode
1
410
Other Decks in Technology
See All in Technology
Behind Postgres 18: The People, the Code, & the Invisible Work | Claire Giordano | PGConfEU 2025
clairegiordano
0
140
20251027_findyさん_音声エージェントLT
almondo_event
2
440
JSConf JPのwebsiteをGatsbyからNext.jsに移行した話 - Next.jsの多言語静的サイトと課題
leko
2
190
AI時代、“平均値”ではいられない
uhyo
8
2.6k
ソースを読む時の思考プロセスの例-MkDocs
sat
PRO
1
220
DSPy入門
tomehirata
0
110
dbtとAIエージェントを組み合わせて見えたデータ調査の新しい形
10xinc
2
490
ストレージエンジニアの仕事と、近年の計算機について / 第58回 情報科学若手の会
pfn
PRO
3
850
マルチエージェントのチームビルディング_2025-10-25
shinoyamada
0
180
AIでデータ活用を加速させる取り組み / Leveraging AI to accelerate data utilization
okiyuki99
1
480
From Natural Language to K8s Operations: The MCP Architecture and Practice of kubectl-ai
appleboy
0
230
生成AI時代のPythonセキュリティとガバナンス
abenben
0
140
Featured
See All Featured
Designing for Performance
lara
610
69k
Being A Developer After 40
akosma
91
590k
Statistics for Hackers
jakevdp
799
220k
Stop Working from a Prison Cell
hatefulcrawdad
272
21k
YesSQL, Process and Tooling at Scale
rocio
173
15k
Scaling GitHub
holman
463
140k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.2k
[RailsConf 2023] Rails as a piece of cake
palkan
57
5.9k
How GitHub (no longer) Works
holman
315
140k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4k
The Language of Interfaces
destraynor
162
25k
The Cult of Friendly URLs
andyhume
79
6.6k
Transcript
Varnish to the rescue Leszek Krupiński
@leafnode PHPers Manual Consultant Architect
intro
web 1. User 2. Browser 3. Server
user is impatient
fast!
100ms
1s = -11% Page Views -16% User Satisfaction -7% Conversion
1-5s ! 32% consumers lost
(2012) average: 2.45s
Optimize application
• Frameworks • Limits • Time-consuming operations • Cost
Maybe it’s not needed?
Cache!
Many levels, many solutions
But… my site is very dynamic!
1s TTL
From 20 rq/s to 1 rq/s in single apt-get install
Fresh content takes most hits
Varnish The Web Accelerator
None
None
None
Architecture
Works with the kernel not against it
mmap, threads, epoll, kqueue
Backends: memory, file
If it fits in memory, use memory
Works on HTTP headers
Cache-control, If-Modified-Since, Expires, Pragma, If-None-Match, Etag, Vary, Age
Varnish uses language both browser and backend know
In-memory logs
75 000 rq/s at TMECC 143 000 rq/s at Redpill-Linpro
Do I need a lot of memory?
Nope
Fresh content takes most hits
Take that, slashdot effect!
Configuration
Lots of possibilities
Unfortunately, lots of possibilities
Varnish Configuration Language
Compiled directly to C
Hook-like configuration
vcl_fetch vcl_recv vcl_hit vcl_miss vcl_hash vcl_pass vcl_deliver vcl_error
None
restart
Objects req, bereq, resp, beresp, obj
Defaults
vcl_recv
None
None
None
vcl_hash
None
VMods
throttle, cookie, shield, redis, memcached, curl, url code, redirect…
Varnish: load balancer failover system
None
Directors
Default: random
Round-robin, client, hash, dns
Health check
None
Saint mode
Grace mode
Two hard things
Invalidate cache
Ban list Efficient way to invalidate cache
Over HTTP
Use PURGE header
None
None
None
Real life issues
Cookies
Varnish does not cache when cookies are involved
Ignore cookies
None
Pick cookies
None
Pick URLs
None
Redirects
POST
PHP sessions
CURL VMod
None
None
PHP + memcached
None
mobile detection
None
mobile detection II
None
VMod: DeviceAtlas Mobile Detection
Cache “one-time” data
Example: dynamic image resizing
1B pictures 10 sizes
apache + moddims
Fresh content takes most hits
Different TTL for different parts?
ESI!
None
None
Testing?
jQuery plugin
Just in! Varnish 4.0
Log query language, background fetch, byte counters, security improvements
http://speakerdeck.com/leafnode