Varnish Caching

21
http://www.flickr.com/photos/jkannenberg/541059011 gareth rushgrove | morethanseven.net Varnish Cache Clever Software for Making HTTP Applications Faster Refresh Cambridge 6th July 2011

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.

Transcript of Varnish Caching

Page 1: Varnish Caching

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

Varnish CacheClever Software for Making HTTP Applications Faster

Refresh Cambridge 6th July 2011

Page 2: Varnish Caching

Gareth Rushgrove

gareth rushgrove | morethanseven.net

Page 3: Varnish Caching

Work at freeagentcentral.com

gareth rushgrove | morethanseven.net

Page 4: Varnish Caching

Blog at morethanseven.net

gareth rushgrove | morethanseven.net

Page 5: Varnish Caching

Currate devopsweekly.com

gareth rushgrove | morethanseven.net

Page 6: Varnish Caching

www.varnish-cache.org

gareth rushgrove | morethanseven.net

Page 7: Varnish Caching

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

Page 8: Varnish Caching

gareth rushgrove | morethanseven.net

Seriously, what is Varnish?

- Cache

- Reverse Proxy- HTTP Accelerator

Page 9: Varnish Caching

gareth rushgrove | morethanseven.net

A Story of HTTP Caching

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

Page 10: Varnish Caching

gareth rushgrove | morethanseven.net

A Typical App

Database Web Server Web Traffic

Page 11: Varnish Caching

gareth rushgrove | morethanseven.net

More Traffic == Slower responses

Database Web Server

Page 12: Varnish Caching

gareth rushgrove | morethanseven.net

Eventually...

Database Web Server

Page 13: Varnish Caching

Database Web Server Varnish

gareth rushgrove | morethanseven.net

Add Varnish

Page 14: Varnish Caching

Database Web Server Varnish

gareth rushgrove | morethanseven.net

Deal with more traffic

Page 15: Varnish Caching

An Example

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

Page 16: Varnish Caching

gareth rushgrove | morethanseven.net

www.vagrantbox.es

Page 17: Varnish Caching

Overengineering for Fun

Database

Gunicorn Varnish Nginx

Gunicorn Varnish Nginx

memcached

memcached

Page 18: Varnish Caching

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

Page 19: Varnish Caching

⚡ 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

Page 20: Varnish Caching

⚡ 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

Page 21: Varnish Caching

Questions?

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