v0.27.53
Changes
feature: implement leastRequests LB algorithm (#4181)
Implements a new LB algorithm that routes each request to the endpoint
with the lowest load factor, defined as inflight requests divided by
endpoint weight. When multiple endpoints share the lowest load factor,
ties are broken using smooth weighted round-robin over the tied set,
proportional to endpoint weights.
With equal weights and no inflight requests it behaves like roundRobin.
ref #557
How to test
- Start proxy that listens on 9999 port that proxies to 4 backends
using leastRequests LB algorithm:
./bin/skipper -inline-routes='r1: * -> <leastRequests, "http://127.0.0.1:9001", "http://127.0.0.1:9002", "http://127.0.0.1:9003", "http://127.0.0.1:9004">' --address :9999- Start 4 backends, each responding with it's ID (1-4) and add
artificial latency to the each:
./bin/skipper -inline-routes='r1: * -> latency("25s") -> inlineContent("1") -> <shunt>' --address :9001 &
./bin/skipper -inline-routes='r1: * -> latency("10s") -> inlineContent("2") -> <shunt>' --address :9002 &
./bin/skipper -inline-routes='r1: * -> latency("5s") -> inlineContent("3") -> <shunt>' --address :9003 &
./bin/skipper -inline-routes='r1: * -> latency("1s") -> inlineContent("4") -> <shunt>' --address :9004
- Attack the proxy with vegeta:
echo "GET http://localhost:9999" | vegeta attack -duration=30s -rate=200 | vegeta encode | jq -r '.body | @base64d' | sort | uniq -c | sort -rn | awk 'BEGIN {print "count server"} {print $1, $2}' | column -t
count server
4299 4
927 3
478 2
296 1Benchmark results
go test -bench=BenchmarkLeastRequestsAlgorithm -benchmem -run='^$' -cpu 1,2,4,8,16 ./loadbalancer
goos: darwin
goarch: arm64
pkg: github.com/zalando/skipper/loadbalancer
cpu: Apple M1 Max
BenchmarkLeastRequestsAlgorithm/10_endpoints 3001717 385.7 ns/op 0 B/op 0 allocs/op
BenchmarkLeastRequestsAlgorithm/10_endpoints-2 3078313 402.7 ns/op 0 B/op 0 allocs/op
BenchmarkLeastRequestsAlgorithm/10_endpoints-4 3115698 385.1 ns/op 0 B/op 0 allocs/op
BenchmarkLeastRequestsAlgorithm/10_endpoints-8 3117997 385.5 ns/op 0 B/op 0 allocs/op
BenchmarkLeastRequestsAlgorithm/10_endpoints-16 3111014 384.8 ns/op 0 B/op 0 allocs/op
BenchmarkLeastRequestsAlgorithm/100_endpoints 329112 3642 ns/op 0 B/op 0 allocs/op
BenchmarkLeastRequestsAlgorithm/100_endpoints-2 333442 3624 ns/op 0 B/op 0 allocs/op
BenchmarkLeastRequestsAlgorithm/100_endpoints-4 322792 3557 ns/op 0 B/op 0 allocs/op
BenchmarkLeastRequestsAlgorithm/100_endpoints-8 337102 3594 ns/op 0 B/op 0 allocs/op
BenchmarkLeastRequestsAlgorithm/100_endpoints-16 326228 3802 ns/op 0 B/op 0 allocs/op
BenchmarkLeastRequestsAlgorithm/1000_endpoints 29665 40382 ns/op 0 B/op 0 allocs/op
BenchmarkLeastRequestsAlgorithm/1000_endpoints-2 29586 40255 ns/op 0 B/op 0 allocs/op
BenchmarkLeastRequestsAlgorithm/1000_endpoints-4 29678 40373 ns/op 0 B/op 0 allocs/op
BenchmarkLeastRequestsAlgorithm/1000_endpoints-8 29643 40328 ns/op 0 B/op 0 allocs/op
BenchmarkLeastRequestsAlgorithm/1000_endpoints-16 29624 40184 ns/op 0 B/op 0 allocs/op
BenchmarkLeastRequestsAlgorithm/10000_endpoints 2755 437176 ns/op 0 B/op 0 allocs/op
BenchmarkLeastRequestsAlgorithm/10000_endpoints-2 2751 437743 ns/op 0 B/op 0 allocs/op
BenchmarkLeastRequestsAlgorithm/10000_endpoints-4 2754 436034 ns/op 0 B/op 0 allocs/op
BenchmarkLeastRequestsAlgorithm/10000_endpoints-8 2748 436233 ns/op 0 B/op 0 allocs/op
BenchmarkLeastRequestsAlgorithm/10000_endpoints-16 2745 437377 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/zalando/skipper/loadbalancer 29.709s
Multiarch Docker image
Multiarch Docker image is available in GitHub's docker registry:
docker run -it ghcr.io/zalando/skipper:v0.27.53 skipper --help