Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
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
470
Dobrze posól swoje hasło
leafnode
0
110
Dobrze posól swoje hasło (z notatkami)
leafnode
0
100
PHPNG kontra HHVM
leafnode
0
110
PHPNG kontra HHVM (z notatkami)
leafnode
0
75
Ewolucja PHP: PHP 5.6, NG, PHP 7, HHVM
leafnode
2
300
Sculpin - Generowanie statycznych stron w PHP
leafnode
2
68
Skalowanie aplikacji PHP
leafnode
1
420
Other Decks in Technology
See All in Technology
Amazon Quick Suite で始める手軽な AI エージェント
shimy
0
180
LLM-Readyなデータ基盤を高速に構築するためのアジャイルデータモデリングの実例
kashira
0
270
re:Invent2025 コンテナ系アップデート振り返り(+CloudWatchログのアップデート紹介)
masukawa
0
390
mairuでつくるクレデンシャルレス開発環境 / Credential-less development environment using Mailru
mirakui
5
540
エンジニアとPMのドメイン知識の溝をなくす、 AIネイティブな開発プロセス
applism118
4
1.3k
年間40件以上の登壇を続けて見えた「本当の発信力」/ 20251213 Masaki Okuda
shift_evolve
PRO
1
140
[デモです] NotebookLM で作ったスライドの例
kongmingstrap
0
160
会社紹介資料 / Sansan Company Profile
sansan33
PRO
11
390k
打 造 A I 驅 動 的 G i t H u b ⾃ 動 化 ⼯ 作 流 程
appleboy
0
360
AIエージェント開発と活用を加速するワークフロー自動生成への挑戦
shibuiwilliam
4
240
生成AIを利用するだけでなく、投資できる組織へ / Becoming an Organization That Invests in GenAI
kaminashi
0
110
.NET 10の概要
tomokusaba
0
120
Featured
See All Featured
Automating Front-end Workflow
addyosmani
1371
200k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.3k
Reflections from 52 weeks, 52 projects
jeffersonlam
355
21k
Testing 201, or: Great Expectations
jmmastey
46
7.8k
Building Flexible Design Systems
yeseniaperezcruz
330
39k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
37
2.7k
How GitHub (no longer) Works
holman
316
140k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.8k
Java REST API Framework Comparison - PWX 2021
mraible
34
9k
Optimizing for Happiness
mojombo
379
70k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.8k
Agile that works and the tools we love
rasmusluckow
331
21k
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