envoyproxy / envoy

Cloud-native high-performance edge/middle/service proxy
https://www.envoyproxy.io
Apache License 2.0
24.79k stars 4.76k forks source link

Make WRR LB thread aware #3278

Open htuch opened 6 years ago

htuch commented 6 years ago

The existing WRR LB uses a per-thread EDF scheduler. This makes memory usage O(m n) where m is the number of hosts and n the number of endpoints. We can shrink this to O(n w), where w is the weight range, if we precompute the schedule on the main thread (as we do for consistent hash balancers) and just maintain an index that we rotate around the shared schedule for WRR. This comes at the downside of increased memory use when we have a wide range of weights, but as long as we maintain a limited set of weights (which we need to do anyway to sanely support locality weighting with the consistent hash balancers), this should be reasonable.

htuch commented 6 years ago

Somewhat related to https://github.com/envoyproxy/envoy/issues/2874.

htuch commented 6 years ago

@alyssawilk points out that this might not do brilliantly as the number of hosts scales if we want the full range of weights preserved, and that what we do today with the consistent hash schemes is also problematic. We should explore these tradeoffs more thoroughly before committing to a specific implementation path here.

htuch commented 6 years ago

FWIW, gRPC-LB (https://grpc.io/blog/loadbalancing) effectively works with a fully precomputed static schedule for WRR.