advanced lb

14

Upload: varnish-software

Post on 08-Apr-2017

201 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Advanced LB
Page 2: Advanced LB

Advanced load balancing with Varnish Plus

Dag Haavi FinstadVarnish Software

[email protected]

Page 3: Advanced LB

Agenda● Load balancing (LB) with Varnish● (to the backend)● Pinterest case: seamless gradual code deploy.● Format: part presentation, part VCL

examples.

Page 4: Advanced LB

Jargon● “Front”: client facing part of Varnish● Backends: origin servers.● VCL: Varnish Configuration Language.● a director: a Varnish load balancer instance.

Page 5: Advanced LB

Not so known trick: admin health

● Since 3.0 Varnish you can disable backends administratively.

● varnishadm backend.set_health backend1 (healthy|sick|probe)

● Overrides probes.● Glob-ing match, save you some typing. (“b*”,

“backend?”, “foo*_app”)

Page 6: Advanced LB

Entry level: Round-robin● Most common approach: Two backend

servers.● Varnish will literally walk a circular list for

each backend request.● You can take one down for maintenance

without anyone noticing.

Page 7: Advanced LB

Stickiness● If your application needs statefulness, Varnish

can send the client to the same backend every time.

● By client identifier, or● by any other means readable in VCL. (cookie,

GET argument, something..)

Page 8: Advanced LB

Other not very known additions● Fallback director. Pick the first healthy

backend.● Directors are stackable from 4.0. Round-

robin within fallback? We can do that.● New in 4.1: idle backend connections time

out and will be closed (backend_idle_timeout)

Page 9: Advanced LB

Reintroducing: Saint mode● Mark backends as sick for specific objects

● Went away for 4.0○ now back as a VMOD in 4.1

https://github.com/varnish/libvmod-saintmode

Page 10: Advanced LB

Pinterest case● Core idea: let existing user sessions continue

on the backend app-version they loaded, give n% of new users the latest deploy.

● Main goal: avoid full page loads/refreshes.● Varnish VCL can do this for you.

Page 11: Advanced LB

Pinterest case (II)

● “current” and “stable” appversions running.● client signals its JS bundle version.● If stable or current, set that director and go.● If older (or none), draw a random sample and

assign the client accordingly.

Page 12: Advanced LB

Pinterest case (III)● “Somewhat” Pinterest-specific.

● Main point: VCL configurability allows for a whole lot of magic...

Page 13: Advanced LB

Questions?

Page 14: Advanced LB

Linksrr.vcl:

https://gist.github.com/daghf/bf35bf15584f560220cc

sticky-ip.vcl:https://gist.github.com/daghf/ba4d96641755fcc8e3bb

sticky-cookie.vcl:https://gist.github.com/daghf/4f0df791486c764ffffa

pinterest-deploy.vcl:https://gist.github.com/daghf/c72ce762f4faf70dd9e1

pinterest engineering blog: https://engineering.pinterest.com/blog/stealthy-shipping-atomic-deploys )