solo-io / wasm

Web Assembly tools and SDKs for extending cloud-native infrastructure
Apache License 2.0
306 stars 40 forks source link

Is it possible to use wasm to extend the load balance strategy? #225

Closed mjaow closed 3 years ago

mjaow commented 3 years ago

I don't want a rr load balance for gloo, but I found there is no way to customize it in gloo?

Have a look at wasm examples, all of them seem like do some filter/transform before request backend service. Is it possible to implement a customized load balance strategy with wasm?

just like

  1. user request
  2. jump into wasm, customize load balance and send dest name to header
  3. jump back to vs, with header, it will be routed directly to backend (gloo support header direction)
Sodman commented 3 years ago

Hi @mjaow, first - do any of the other non-rr Envoy load balancing strategies in Envoy work for you? This would be the easiest solution. https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/upstream/load_balancing/load_balancers#arch-overview-load-balancing-types

Next, in terms of Gloo Edge - you can route based on headers if you'd like, see our docs here on the various routing/matching patterns we support - https://docs.solo.io/gloo-edge/latest/guides/traffic_management/destination_selection/

If you want to use logic from a wasm filter from routing, Gloo Edge supports routing to a cluster as a header value, so you could have a wasm filter add the header for the cluster you wanted, then clear the route cache, and I believe gloo should forward the request to your desired cluster.

Otherwise, right now I don't believe your use case of a custom load balancing strategy is supported by the wasm ABI or the Envoy API. Here's a relevant discussion about extending load balancing strategies in upstream envoy - https://github.com/envoyproxy/envoy/issues/5598

mjaow commented 3 years ago

Yeah, for some reason, existing lb_policy of envoy is not able to support. We need a better global least request to make load even , envoy only support least req locally. Thanks for advice and the related link. I'll take a shot

Sodman commented 3 years ago

Closing this as resolved for now, feel free to re-open if you have any more questions!