advanced lb
TRANSCRIPT
![Page 1: Advanced LB](https://reader037.vdocuments.site/reader037/viewer/2022100103/58e8cc321a28abb3398b4d91/html5/thumbnails/1.jpg)
![Page 2: Advanced LB](https://reader037.vdocuments.site/reader037/viewer/2022100103/58e8cc321a28abb3398b4d91/html5/thumbnails/2.jpg)
Advanced load balancing with Varnish Plus
Dag Haavi FinstadVarnish Software
![Page 3: Advanced LB](https://reader037.vdocuments.site/reader037/viewer/2022100103/58e8cc321a28abb3398b4d91/html5/thumbnails/3.jpg)
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](https://reader037.vdocuments.site/reader037/viewer/2022100103/58e8cc321a28abb3398b4d91/html5/thumbnails/4.jpg)
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](https://reader037.vdocuments.site/reader037/viewer/2022100103/58e8cc321a28abb3398b4d91/html5/thumbnails/5.jpg)
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](https://reader037.vdocuments.site/reader037/viewer/2022100103/58e8cc321a28abb3398b4d91/html5/thumbnails/6.jpg)
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](https://reader037.vdocuments.site/reader037/viewer/2022100103/58e8cc321a28abb3398b4d91/html5/thumbnails/7.jpg)
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](https://reader037.vdocuments.site/reader037/viewer/2022100103/58e8cc321a28abb3398b4d91/html5/thumbnails/8.jpg)
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](https://reader037.vdocuments.site/reader037/viewer/2022100103/58e8cc321a28abb3398b4d91/html5/thumbnails/9.jpg)
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](https://reader037.vdocuments.site/reader037/viewer/2022100103/58e8cc321a28abb3398b4d91/html5/thumbnails/10.jpg)
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](https://reader037.vdocuments.site/reader037/viewer/2022100103/58e8cc321a28abb3398b4d91/html5/thumbnails/11.jpg)
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](https://reader037.vdocuments.site/reader037/viewer/2022100103/58e8cc321a28abb3398b4d91/html5/thumbnails/12.jpg)
Pinterest case (III)● “Somewhat” Pinterest-specific.
● Main point: VCL configurability allows for a whole lot of magic...
![Page 13: Advanced LB](https://reader037.vdocuments.site/reader037/viewer/2022100103/58e8cc321a28abb3398b4d91/html5/thumbnails/13.jpg)
Questions?
![Page 14: Advanced LB](https://reader037.vdocuments.site/reader037/viewer/2022100103/58e8cc321a28abb3398b4d91/html5/thumbnails/14.jpg)
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 )