varnish, the high performance valhalla?

Post on 15-Jan-2015

6.605 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

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

TRANSCRIPT

Kings of Code 2011

Varnish, the high performance valhalla?

∂ Open source addict

JEROEN VAN DIJK

∂ CTO @ Enrise∂ Email : jeroen@enrise.com∂ Twitter: @neorey

2

∂ Open source addict

JEROEN VAN DIJK

∂ CTO @ Enrise∂ Email : jeroen@enrise.com∂ Twitter: @neorey

2

THE ENRISE RESTAURANT

3

THE ENRISE RESTAURANT

∂ We want to prepare the best dishes

3

THE ENRISE RESTAURANT

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

3

∂ 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

BEFORE WE START

WHO KNOWS RFC 2616?

4

BEFORE WE START

WHO KNOWS HTTP?

5

BEFORE WE START

WHO THINKS HE/SHE KNOWS

HTTP?

6

∂ Wikipedia : Proxy

STANDARD PROXY

7

∂ Wikipedia : Reverse proxy

REVERSE PROXY

8

∂ Wikipedia : Reverse proxy

REVERSE PROXY

8

∂ Wikipedia : Reverse proxy

REVERSE PROXIES

9

∂ Wikipedia : Reverse proxy

REVERSE PROXIES

9

∂ Wikipedia : Reverse proxy

REVERSE PROXIES

9

∂ NOT a webserver!

WHAT IS VARNISH? (1)

10

∂ NOT a webserver!

WHAT IS VARNISH? (1)

∂Caching reverse proxy

10

∂ NOT a webserver!

WHAT IS VARNISH? (1)

∂Caching reverse proxy∂Load balancer

10

∂ NOT a webserver!

WHAT IS VARNISH? (1)

∂Caching reverse proxy∂Load balancer∂Fail over system

10

∂ NOT a webserver!

WHAT IS VARNISH? (1)

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

10

WHAT IS VARNISH? (2)

11

WHAT IS VARNISH? (2)

∂ Originally built for a Norwegian newspaper

11

WHAT IS VARNISH? (2)

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

11

∂ 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

∂ Scaling limitations currently unknown

WHAT IS VARNISH? (3)

12

∂ Scaling limitations currently unknown

WHAT IS VARNISH? (3)

∂Designed for 64bit architecture

12

∂ Scaling limitations currently unknown

WHAT IS VARNISH? (3)

∂Designed for 64bit architecture∂Highly scalable

12

∂ Scaling limitations currently unknown

WHAT IS VARNISH? (3)

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

12

∂ 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

∂ 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

∂ Possible request paths

INTERNALS (1)

13

∂ Optimal request path

INTERNALS (2)

14

∂ Caching request path

INTERNALS (3)

15

∂ Prevent caching

INTERNALS (4)

16

∂ Bypassing Varnish

INTERNALS (5)

17

∂ Errors or issueing restarts

INTERNALS (6)

18

∂ Compiled to C when run

VARNISH CONFIGURATION LANGUAGE (1)

19

∂ Compiled to C when run

VARNISH CONFIGURATION LANGUAGE (1)

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

19

∂ Compiled to C when run

VARNISH CONFIGURATION LANGUAGE (1)

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

19

∂ Compiled to C when run

VARNISH CONFIGURATION LANGUAGE (1)

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

19

∂ 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

∂ 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

∂ 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

∂ 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

∂ 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

∂ 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

∂ 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

∂ 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

∂ 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

∂ 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

VARNISHING WORDPRESS (1)

25

VARNISHING WORDPRESS (1)

∂Siege on standard WordPress homepage

25

VARNISHING WORDPRESS (1)

∂Siege on standard WordPress homepage§No Varnish

25

VARNISHING WORDPRESS (1)

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

25

VARNISHING WORDPRESS (1)

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

25

∂ No Varnish

VARNISHING WORDPRESS (2)

26

∂ No Varnish

VARNISHING WORDPRESS (2)

26

∂ No Varnish

VARNISHING WORDPRESS (2)

26

∂ Default Varnish

VARNISHING WORDPRESS (3)

27

∂ Default Varnish

VARNISHING WORDPRESS (3)

27

∂ Default Varnish

VARNISHING WORDPRESS (3)

27

∂ 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

∂ Custom Varnish

VARNISHING WORDPRESS (5)

29

∂ Custom Varnish

VARNISHING WORDPRESS (5)

29

∂ Custom Varnish

VARNISHING WORDPRESS (5)

29

OTHER PITFALLS

30

OTHER PITFALLS

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

30

OTHER PITFALLS

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

30

∂ 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

∂ Very powerful for content assembly

EDGE SIDE INCLUDES (1)

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

31

∂ 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

∂ 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

∂ Where are the ESI’s?

EDGE SIDE INCLUDES (4)

34

∂ Different TTL’s for content snippets

EDGE SIDE INCLUDES (5)

35

∂ You can’t go without

TOOLS

∂Varnishstat∂Varnishsizes∂Varnishtop∂Varnishadm∂Varnishlog

36

VARNISHLOG

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

37

∂ Request of a gif image by client

VARNISHLOG

38

∂ Request of a gif image by client

VARNISHLOG

38

∂ Request of a gif image by client

VARNISHLOG

38

∂ Request of a gif image by client

VARNISHLOG

38

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

∂ Questions? Thank you!

top related