109
Varnish to the rescue Leszek Krupiński

Varnish to the rescue

Embed Size (px)

Citation preview

Page 1: Varnish to the rescue

Varnish to the rescue

Leszek Krupiński

Page 2: Varnish to the rescue

@leafnode

PHPers Manual

Consultant Architect

Page 3: Varnish to the rescue

intro

Page 4: Varnish to the rescue

web

1. User 2. Browser 3. Server

Page 5: Varnish to the rescue

user is impatient

Page 6: Varnish to the rescue

fast!

Page 7: Varnish to the rescue

100ms

Page 8: Varnish to the rescue

1s =

-11% Page Views -16% User Satisfaction

-7% Conversion

Page 9: Varnish to the rescue

1-5s !

32% consumers lost

Page 10: Varnish to the rescue

(2012)

average: 2.45s

Page 11: Varnish to the rescue

Optimize application

Page 12: Varnish to the rescue

• Frameworks • Limits • Time-consuming operations • Cost

Page 13: Varnish to the rescue

Maybe it’s not needed?

Page 14: Varnish to the rescue

Cache!

Page 15: Varnish to the rescue

Many levels, many solutions

Page 16: Varnish to the rescue

But… my site is very dynamic!

Page 17: Varnish to the rescue

1s TTL

Page 18: Varnish to the rescue

From 20 rq/s to 1 rq/s in single apt-get install

Page 19: Varnish to the rescue

Fresh content takes most hits

Page 20: Varnish to the rescue

Varnish The Web Accelerator

Page 21: Varnish to the rescue
Page 22: Varnish to the rescue
Page 23: Varnish to the rescue
Page 24: Varnish to the rescue

Architecture

Page 25: Varnish to the rescue

Works with the kernel not against it

Page 26: Varnish to the rescue

mmap, threads, epoll, kqueue

Page 27: Varnish to the rescue

Backends: memory, file

Page 28: Varnish to the rescue

If it fits in memory, use memory

Page 29: Varnish to the rescue

Works on HTTP headers

Page 30: Varnish to the rescue

Cache-control, If-Modified-Since, Expires, Pragma, If-None-Match, Etag,

Vary, Age

Page 31: Varnish to the rescue

Varnish uses language both browser and

backend know

Page 32: Varnish to the rescue

In-memory logs

Page 33: Varnish to the rescue

75 000 rq/s at TMECC 143 000 rq/s at Redpill-Linpro

Page 34: Varnish to the rescue

Do I need a lot of memory?

Page 35: Varnish to the rescue

Nope

Page 36: Varnish to the rescue

Fresh content takes most hits

Page 37: Varnish to the rescue

Take that, slashdot effect!

Page 38: Varnish to the rescue

Configuration

Page 39: Varnish to the rescue

Lots of possibilities

Page 40: Varnish to the rescue

Unfortunately, lots of possibilities

Page 41: Varnish to the rescue

Varnish Configuration

Language

Page 42: Varnish to the rescue

Compiled directly to C

Page 43: Varnish to the rescue

Hook-like configuration

Page 44: Varnish to the rescue

vcl_fetch vcl_recv

vcl_hit vcl_miss

vcl_hash vcl_pass

vcl_deliver vcl_error

Page 45: Varnish to the rescue
Page 46: Varnish to the rescue

restart

Page 47: Varnish to the rescue

Objects

req, bereq, resp, beresp, obj

Page 48: Varnish to the rescue

Defaults

Page 49: Varnish to the rescue

vcl_recv

Page 50: Varnish to the rescue
Page 51: Varnish to the rescue
Page 52: Varnish to the rescue
Page 53: Varnish to the rescue

vcl_hash

Page 54: Varnish to the rescue
Page 55: Varnish to the rescue

VMods

Page 56: Varnish to the rescue

throttle, cookie, shield, redis, memcached, curl,

url code, redirect…

Page 57: Varnish to the rescue

Varnish: load balancer

failover system

Page 58: Varnish to the rescue
Page 59: Varnish to the rescue

Directors

Page 60: Varnish to the rescue

Default: random

Page 61: Varnish to the rescue

Round-robin, client, hash, dns

Page 62: Varnish to the rescue

Health check

Page 63: Varnish to the rescue
Page 64: Varnish to the rescue

Saint mode

Page 65: Varnish to the rescue

Grace mode

Page 66: Varnish to the rescue

Two hard things

Page 67: Varnish to the rescue

Invalidate cache

Page 68: Varnish to the rescue

Ban listEfficient way to invalidate cache

Page 69: Varnish to the rescue

Over HTTP

Page 70: Varnish to the rescue

Use PURGE header

Page 71: Varnish to the rescue
Page 72: Varnish to the rescue
Page 73: Varnish to the rescue
Page 74: Varnish to the rescue

Real life issues

Page 75: Varnish to the rescue

Cookies

Page 76: Varnish to the rescue

Varnish does not cache when cookies

are involved

Page 77: Varnish to the rescue

Ignore cookies

Page 78: Varnish to the rescue
Page 79: Varnish to the rescue

Pick cookies

Page 80: Varnish to the rescue
Page 81: Varnish to the rescue

Pick URLs

Page 82: Varnish to the rescue
Page 83: Varnish to the rescue

Redirects

Page 84: Varnish to the rescue

POST

Page 85: Varnish to the rescue

PHP sessions

Page 86: Varnish to the rescue

CURL VMod

Page 87: Varnish to the rescue
Page 88: Varnish to the rescue
Page 89: Varnish to the rescue

PHP + memcached

Page 90: Varnish to the rescue
Page 91: Varnish to the rescue

mobile detection

Page 92: Varnish to the rescue
Page 93: Varnish to the rescue

mobile detection II

Page 94: Varnish to the rescue
Page 95: Varnish to the rescue

VMod: DeviceAtlas Mobile Detection

Page 96: Varnish to the rescue

Cache “one-time” data

Page 97: Varnish to the rescue

Example: dynamic image resizing

Page 98: Varnish to the rescue

1B pictures 10 sizes

Page 99: Varnish to the rescue

apache + moddims

Page 100: Varnish to the rescue

Fresh content takes most hits

Page 101: Varnish to the rescue

Different TTL for different parts?

Page 102: Varnish to the rescue

ESI!

Page 103: Varnish to the rescue
Page 104: Varnish to the rescue
Page 105: Varnish to the rescue

Testing?

Page 106: Varnish to the rescue

jQuery plugin

Page 107: Varnish to the rescue

Just in! Varnish 4.0

Page 108: Varnish to the rescue

Log query language, background fetch, byte

counters, security improvements

Page 109: Varnish to the rescue

http://speakerdeck.com/leafnode