Varnish Caching

Preview:

DESCRIPTION

Lightning talk given at Refresh Cambridge event on 6th July 2011. Very quick introduction to where an HTTP Caching solution fits in, and an example of the kind of effect it could have on performance.

Citation preview

http://www.flickr.com/photos/jkannenberg/541059011gareth rushgrove | morethanseven.net

Varnish CacheClever Software for Making HTTP Applications Faster

Refresh Cambridge 6th July 2011

Gareth Rushgrove

gareth rushgrove | morethanseven.net

Work at freeagentcentral.com

gareth rushgrove | morethanseven.net

Blog at morethanseven.net

gareth rushgrove | morethanseven.net

Currate devopsweekly.com

gareth rushgrove | morethanseven.net

www.varnish-cache.org

gareth rushgrove | morethanseven.net

gareth rushgrove | morethanseven.net http://www.flickr.com/photos/exalthim/3597210568

What is Varnish?

Varnish Cache is an open source, state of the art web application accelerator. You install it on your web server and it makes your website fly.Official blurb

gareth rushgrove | morethanseven.net

Seriously, what is Varnish?

- Cache

- Reverse Proxy- HTTP Accelerator

gareth rushgrove | morethanseven.net

A Story of HTTP Caching

http://www.flickr.com/photos/solsken/62924477

gareth rushgrove | morethanseven.net

A Typical App

Database Web Server Web Traffic

gareth rushgrove | morethanseven.net

More Traffic == Slower responses

Database Web Server

gareth rushgrove | morethanseven.net

Eventually...

Database Web Server

Database Web Server Varnish

gareth rushgrove | morethanseven.net

Add Varnish

Database Web Server Varnish

gareth rushgrove | morethanseven.net

Deal with more traffic

An Example

gareth rushgrove | morethanseven.net http://www.flickr.com/photos/jonrb/3735816042

gareth rushgrove | morethanseven.net

www.vagrantbox.es

Overengineering for Fun

Database

Gunicorn Varnish Nginx

Gunicorn Varnish Nginx

memcached

memcached

backend default { .host = "127.0.0.1"; .port = "8000";}sub vcl_recv { if (req.request == "GET" && req.http.cookie) { return(lookup); }}sub vcl_fetch { if (beresp.ttl < 180s) { set beresp.ttl = 180s; } esi; if (beresp.http.Set-Cookie) { return(deliver); }}

Varnish Configuration

gareth rushgrove | morethanseven.net

⚡ ab -c 10 -n 400 http://www.vagrantbox.es/

Requests per second: 59.63 [#/sec] (mean)

Percentage of the requests served within a certain time (ms) 50% 164 66% 174 75% 183 80% 188 90% 207 95% 231 98% 246 99% 279 100% 408 (longest request)

Without Varnish

gareth rushgrove | morethanseven.net

⚡ ab -c 10 -n 400 http://www.vagrantbox.es/

Requests per second: 103.61 [#/sec] (mean)

Percentage of the requests served within a certain time (ms) 50% 92 66% 101 75% 107 80% 111 90% 120 95% 129 98% 141 99% 149 100% 157 (longest request)

With Varnish

gareth rushgrove | morethanseven.net

Questions?

gareth rushgrove | morethanseven.net http://flickr.com/photos/psd/102332391/