varnish to the rescue

Post on 16-Apr-2017

247 Views

Category:

Internet

2 Downloads

Preview:

Click to see full reader

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

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

restart

Objects

req, bereq, resp, beresp, obj

Defaults

vcl_recv

vcl_hash

VMods

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

url code, redirect…

Varnish: load balancer

failover system

Directors

Default: random

Round-robin, client, hash, dns

Health check

Saint mode

Grace mode

Two hard things

Invalidate cache

Ban listEfficient way to invalidate cache

Over HTTP

Use PURGE header

Real life issues

Cookies

Varnish does not cache when cookies

are involved

Ignore cookies

Pick cookies

Pick URLs

Redirects

POST

PHP sessions

CURL VMod

PHP + memcached

mobile detection

mobile detection II

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!

Testing?

jQuery plugin

Just in! Varnish 4.0

Log query language, background fetch, byte

counters, security improvements

http://speakerdeck.com/leafnode

top related