varnish, the high performance valhalla?

83
Kings of Code 2011 Varnish, the high performance valhalla?

Upload: jeroen-van-dijk

Post on 15-Jan-2015

6.604 views

Category:

Technology


0 download

DESCRIPTION

Varnish, the high-performance HTTP accelerator. Is it really a high performance valhalla?

TRANSCRIPT

Page 1: Varnish, the high performance valhalla?

Kings of Code 2011

Varnish, the high performance valhalla?

Page 2: Varnish, the high performance valhalla?

∂ Open source addict

JEROEN VAN DIJK

∂ CTO @ Enrise∂ Email : [email protected]∂ Twitter: @neorey

2

Page 3: Varnish, the high performance valhalla?

∂ Open source addict

JEROEN VAN DIJK

∂ CTO @ Enrise∂ Email : [email protected]∂ Twitter: @neorey

2

Page 4: Varnish, the high performance valhalla?

THE ENRISE RESTAURANT

3

Page 5: Varnish, the high performance valhalla?

THE ENRISE RESTAURANT

∂ We want to prepare the best dishes

3

Page 6: Varnish, the high performance valhalla?

THE ENRISE RESTAURANT

∂ We want to prepare the best dishes∂ With the best ingredients

3

Page 7: Varnish, the high performance valhalla?

∂ Engineers are our top chefs!

THE ENRISE RESTAURANT

∂ We want to prepare the best dishes∂ With the best ingredients∂ To create a magical client experience!

3

Page 8: Varnish, the high performance valhalla?

BEFORE WE START

WHO KNOWS RFC 2616?

4

Page 9: Varnish, the high performance valhalla?

BEFORE WE START

WHO KNOWS HTTP?

5

Page 10: Varnish, the high performance valhalla?

BEFORE WE START

WHO THINKS HE/SHE KNOWS

HTTP?

6

Page 11: Varnish, the high performance valhalla?

∂ Wikipedia : Proxy

STANDARD PROXY

7

Page 12: Varnish, the high performance valhalla?

∂ Wikipedia : Reverse proxy

REVERSE PROXY

8

Page 13: Varnish, the high performance valhalla?

∂ Wikipedia : Reverse proxy

REVERSE PROXY

8

Page 14: Varnish, the high performance valhalla?

∂ Wikipedia : Reverse proxy

REVERSE PROXIES

9

Page 15: Varnish, the high performance valhalla?

∂ Wikipedia : Reverse proxy

REVERSE PROXIES

9

Page 16: Varnish, the high performance valhalla?

∂ Wikipedia : Reverse proxy

REVERSE PROXIES

9

Page 17: Varnish, the high performance valhalla?

∂ NOT a webserver!

WHAT IS VARNISH? (1)

10

Page 18: Varnish, the high performance valhalla?

∂ NOT a webserver!

WHAT IS VARNISH? (1)

∂Caching reverse proxy

10

Page 19: Varnish, the high performance valhalla?

∂ NOT a webserver!

WHAT IS VARNISH? (1)

∂Caching reverse proxy∂Load balancer

10

Page 20: Varnish, the high performance valhalla?

∂ NOT a webserver!

WHAT IS VARNISH? (1)

∂Caching reverse proxy∂Load balancer∂Fail over system

10

Page 21: Varnish, the high performance valhalla?

∂ NOT a webserver!

WHAT IS VARNISH? (1)

∂Caching reverse proxy∂Load balancer∂Fail over system∂HTTP Accelerator

10

Page 22: Varnish, the high performance valhalla?

WHAT IS VARNISH? (2)

11

Page 23: Varnish, the high performance valhalla?

WHAT IS VARNISH? (2)

∂ Originally built for a Norwegian newspaper

11

Page 24: Varnish, the high performance valhalla?

WHAT IS VARNISH? (2)

∂ Originally built for a Norwegian newspaper∂ > 545k new hostnames in December 2010§NetCraft monthly survey

11

Page 25: Varnish, the high performance valhalla?

∂ Massive growth in usage

WHAT IS VARNISH? (2)

∂ Originally built for a Norwegian newspaper∂ > 545k new hostnames in December 2010§NetCraft monthly survey

∂ Known users§Wikileaks§Facebook§Twitter§SlashDot

11

Page 26: Varnish, the high performance valhalla?

∂ Scaling limitations currently unknown

WHAT IS VARNISH? (3)

12

Page 27: Varnish, the high performance valhalla?

∂ Scaling limitations currently unknown

WHAT IS VARNISH? (3)

∂Designed for 64bit architecture

12

Page 28: Varnish, the high performance valhalla?

∂ Scaling limitations currently unknown

WHAT IS VARNISH? (3)

∂Designed for 64bit architecture∂Highly scalable

12

Page 29: Varnish, the high performance valhalla?

∂ Scaling limitations currently unknown

WHAT IS VARNISH? (3)

∂Designed for 64bit architecture∂Highly scalable§Varnish in front of Varnish(es)

12

Page 30: Varnish, the high performance valhalla?

∂ Scaling limitations currently unknown

WHAT IS VARNISH? (3)

∂Designed for 64bit architecture∂Highly scalable§Varnish in front of Varnish(es)∂Perfect browser cache solution

12

Page 31: Varnish, the high performance valhalla?

∂ Scaling limitations currently unknown

WHAT IS VARNISH? (3)

∂Designed for 64bit architecture∂Highly scalable§Varnish in front of Varnish(es)∂Perfect browser cache solution§Prevent those hard refresh calls!

12

Page 32: Varnish, the high performance valhalla?

∂ Possible request paths

INTERNALS (1)

13

Page 33: Varnish, the high performance valhalla?

∂ Optimal request path

INTERNALS (2)

14

Page 34: Varnish, the high performance valhalla?

∂ Caching request path

INTERNALS (3)

15

Page 35: Varnish, the high performance valhalla?

∂ Prevent caching

INTERNALS (4)

16

Page 36: Varnish, the high performance valhalla?

∂ Bypassing Varnish

INTERNALS (5)

17

Page 37: Varnish, the high performance valhalla?

∂ Errors or issueing restarts

INTERNALS (6)

18

Page 38: Varnish, the high performance valhalla?

∂ Compiled to C when run

VARNISH CONFIGURATION LANGUAGE (1)

19

Page 39: Varnish, the high performance valhalla?

∂ Compiled to C when run

VARNISH CONFIGURATION LANGUAGE (1)

∂ 11 subroutines (vcl_recv, vcl_hash, etc ...)

19

Page 40: Varnish, the high performance valhalla?

∂ Compiled to C when run

VARNISH CONFIGURATION LANGUAGE (1)

∂ 11 subroutines (vcl_recv, vcl_hash, etc ...)∂ Backend(s)

19

Page 41: Varnish, the high performance valhalla?

∂ Compiled to C when run

VARNISH CONFIGURATION LANGUAGE (1)

∂ 11 subroutines (vcl_recv, vcl_hash, etc ...)∂ Backend(s)∂ Directors (random, round robin, hash)

19

Page 42: Varnish, the high performance valhalla?

∂ Compiled to C when run

VARNISH CONFIGURATION LANGUAGE (1)

∂ 11 subroutines (vcl_recv, vcl_hash, etc ...)∂ Backend(s)∂ Directors (random, round robin, hash)∂ Access control lists

19

Page 43: Varnish, the high performance valhalla?

∂ Compiled to C when run

VARNISH CONFIGURATION LANGUAGE (1)

∂ 11 subroutines (vcl_recv, vcl_hash, etc ...)∂ Backend(s)∂ Directors (random, round robin, hash)∂ Access control lists∂ Saint and grace mode

19

Page 44: Varnish, the high performance valhalla?

∂ Compiled to C when run

VARNISH CONFIGURATION LANGUAGE (1)

∂ 11 subroutines (vcl_recv, vcl_hash, etc ...)∂ Backend(s)∂ Directors (random, round robin, hash)∂ Access control lists∂ Saint and grace mode∂ Custom subroutines

19

Page 45: Varnish, the high performance valhalla?

∂ Compiled to C when run

VARNISH CONFIGURATION LANGUAGE (1)

∂ 11 subroutines (vcl_recv, vcl_hash, etc ...)∂ Backend(s)∂ Directors (random, round robin, hash)∂ Access control lists∂ Saint and grace mode∂ Custom subroutines∂ Inline C

19

Page 46: Varnish, the high performance valhalla?

∂ Compiled to C when run

VARNISH CONFIGURATION LANGUAGE (1)

∂ 11 subroutines (vcl_recv, vcl_hash, etc ...)∂ Backend(s)∂ Directors (random, round robin, hash)∂ Access control lists∂ Saint and grace mode∂ Custom subroutines∂ Inline C∂ Since v3.0 : VMODS

19

Page 47: Varnish, the high performance valhalla?

∂ Cache images in vcl_recv

VARNISH CONFIGURATION LANGUAGE (2)

if (req.request == “GET” &&req.url ~ “\.(gif|jpg|jpeg|bmp|png|ico)$”) {unset req.http.cookie;set req.grace = 1m;return(lookup);

}

20

Page 48: Varnish, the high performance valhalla?

∂ Remove Google Analytics in vcl_recv

VARNISH CONFIGURATION LANGUAGE (3)

if (req.http.cookie) { set req.http.Cookie = regsuball(req.http.Cookie,

"__utm.=[^;]+(; )?", ""); if (req.http.cookie ~ "^ *$") { remove req.http.cookie; }}

21

Page 49: Varnish, the high performance valhalla?

∂ Multiple backend configuration

VARNISH CONFIGURATION LANGUAGE (4)

backend default { .host="192.168.1.10"; .port="8080"; .probe={ .url=”/test.php”; }}backend second { .host="192.168.1.20"; .port="8080";}

22

Page 50: Varnish, the high performance valhalla?

∂ Load balanced 33 / 66 % config

VARNISH CONFIGURATION LANGUAGE (5)

director balance random { { .backend = default; .weight = 1; } { .backend = second; .weight = 2; }}sub vcl_recv { set.req.backend = balance; return(pass);}

23

Page 51: Varnish, the high performance valhalla?

∂ Adding headers on response

VARNISH CONFIGURATION LANGUAGE (6)

if (obj.hits > 0) { #if hit add hit count set resp.http.X-Cache = "HIT-" obj.hits;} else { set resp.http.X-Cache = "MISS”;}

24

Page 52: Varnish, the high performance valhalla?

VARNISHING WORDPRESS (1)

25

Page 53: Varnish, the high performance valhalla?

VARNISHING WORDPRESS (1)

∂Siege on standard WordPress homepage

25

Page 54: Varnish, the high performance valhalla?

VARNISHING WORDPRESS (1)

∂Siege on standard WordPress homepage§No Varnish

25

Page 55: Varnish, the high performance valhalla?

VARNISHING WORDPRESS (1)

∂Siege on standard WordPress homepage§No Varnish§Default Varnish installation

25

Page 56: Varnish, the high performance valhalla?

VARNISHING WORDPRESS (1)

∂Siege on standard WordPress homepage§No Varnish§Default Varnish installation§Custom VCL configuration

25

Page 57: Varnish, the high performance valhalla?

∂ No Varnish

VARNISHING WORDPRESS (2)

26

Page 58: Varnish, the high performance valhalla?

∂ No Varnish

VARNISHING WORDPRESS (2)

26

Page 59: Varnish, the high performance valhalla?

∂ No Varnish

VARNISHING WORDPRESS (2)

26

Page 60: Varnish, the high performance valhalla?

∂ Default Varnish

VARNISHING WORDPRESS (3)

27

Page 61: Varnish, the high performance valhalla?

∂ Default Varnish

VARNISHING WORDPRESS (3)

27

Page 62: Varnish, the high performance valhalla?

∂ Default Varnish

VARNISHING WORDPRESS (3)

27

Page 63: Varnish, the high performance valhalla?

∂ Kill those cookies!!

VARNISHING WORDPRESS (4)

# Drop any cookies sent to WordPress.sub vcl_recv { unset req.http.cookie;}# Drop any cookies WordPress tries to send backsub vcl_fetch { unset beresp.http.set-cookie;}

28

Page 64: Varnish, the high performance valhalla?

∂ Custom Varnish

VARNISHING WORDPRESS (5)

29

Page 65: Varnish, the high performance valhalla?

∂ Custom Varnish

VARNISHING WORDPRESS (5)

29

Page 66: Varnish, the high performance valhalla?

∂ Custom Varnish

VARNISHING WORDPRESS (5)

29

Page 67: Varnish, the high performance valhalla?

OTHER PITFALLS

30

Page 68: Varnish, the high performance valhalla?

OTHER PITFALLS

∂ Accept headers§application/vnd.kingsofcode.speakers+xml;§return “Vary: Accept” header

30

Page 69: Varnish, the high performance valhalla?

OTHER PITFALLS

∂ Accept headers§application/vnd.kingsofcode.speakers+xml;§return “Vary: Accept” header∂ Accept-encoding header

30

Page 70: Varnish, the high performance valhalla?

∂ Not specifically Varnish issues

OTHER PITFALLS

∂ Accept headers§application/vnd.kingsofcode.speakers+xml;§return “Vary: Accept” header∂ Accept-encoding header∂ Vary: User-Agent header

30

Page 71: Varnish, the high performance valhalla?

∂ Very powerful for content assembly

EDGE SIDE INCLUDES (1)

∂Markup language∂Co-authored Akamai, IBM, Oracle & more∂Extensive features

31

Page 72: Varnish, the high performance valhalla?

∂ Examples? http://esi-examples.akamai.com

EDGE SIDE INCLUDES (2)

∂ if ... else§<esi:choose><esi:when> ... <esi:otherwise>

∂ Variables§<esi:assign> and <esi:vars>

∂ Varnish implements only one feature!§<esi:include src=”uri” />

32

Page 73: Varnish, the high performance valhalla?

∂ VCL config for ESI

EDGE SIDE INCLUDES (3)

if (req.url ~ "^/url/to/esi/snippets") { unset beresp.http.set-cookie;}## enable esi on header from backendif (beresp.http.enable-esi == "1") { set beresp.do_esi = true; //varnish 3.0

unset beresp.http.enable-esi;}

33

Page 74: Varnish, the high performance valhalla?

∂ Where are the ESI’s?

EDGE SIDE INCLUDES (4)

34

Page 75: Varnish, the high performance valhalla?

∂ Different TTL’s for content snippets

EDGE SIDE INCLUDES (5)

35

Page 76: Varnish, the high performance valhalla?

∂ You can’t go without

TOOLS

∂Varnishstat∂Varnishsizes∂Varnishtop∂Varnishadm∂Varnishlog

36

Page 77: Varnish, the high performance valhalla?

VARNISHLOG

∂ Log hits§varnishlog -o VCL_Call hit | grep RxURL∂ Log misses§varnishlog -i TxURL

37

Page 78: Varnish, the high performance valhalla?

∂ Request of a gif image by client

VARNISHLOG

38

Page 79: Varnish, the high performance valhalla?

∂ Request of a gif image by client

VARNISHLOG

38

Page 80: Varnish, the high performance valhalla?

∂ Request of a gif image by client

VARNISHLOG

38

Page 81: Varnish, the high performance valhalla?

∂ Request of a gif image by client

VARNISHLOG

38

Page 82: Varnish, the high performance valhalla?

CAVEATS

∂ Unsuitable for 32 bit

∂ Beware of cookie monster applications

∂ Check your API design

∂ Avoid large files

∂ Minimize cookie usage in ESI

∂ No SSL support

39

Page 83: Varnish, the high performance valhalla?

∂ Questions? Thank you!