Simple load balancing
Decide how to load balance incoming requests to backend services.
About simple load balancing
Gloo Gateway supports multiple load balancing algorithms for selecting backend services to forward incoming requests to. By default, incoming requests are forwarded to the instance with the least requests. You can change this behavior and instead use a round robin algorithm to forward the request to a backend service.
Least request
The least request load balancer algorithm generally selects the host with the fewest requests. The following rules apply:
- If no
localityTypeis set, send the request to the host with the fewest requests. - If
localityTypeis set, a weighted round robin approach is used, in which higher weighted endpoints are considered more often in the round robin rotation to achieve the selected weight.
Round robin
The round robin load balancer algorithm selects a backend host in a round robin order. If a localityType is also defined, a weighted round robin algorithm is used, in which higher weighted endpoints are considered more often in the round robin rotation to achieve the selected weight.
Random
The random load balancer algorithm selects a random host that is available. This load balancing algorithm usually performs better than the round robin algorithm if no health checks are configured for the backend host.
Other load balancing options
Learn about other load balancing options that you can set in the load balancer policy.
Healthy panic threshold
By default, Gloo Gateway only considers services that are healthy and available when load balancing incoming requests among backend services. In the case that the number of healthy backend services becomes too low, you can instruct Gloo Gateway to disregard the backend health status and either load balance requests among all or no hosts by using the healthy_panic_threshold setting. If not set, the threshold defaults to 50%. To disable panic mode, set this field to 0.
To learn more about this setting and when to use it, see the Envoy documentation.
Update merge window
Sometimes, your deployments might have health checks and metadata updates that use a lot of CPU and memory. In such cases, you can use the update_merge_window setting. This way, Gloo Gateway merges all updates together within a specific timeframe. For more information about this setting, see the Envoy documentation. If not set, the update merge window defaults to 1000ms. To disable the update merge window, set this field to 0s.
Before you begin
Follow the Get started guide to install Gloo Gateway.
Follow the Sample app guide to create a gateway proxy with an HTTP listener and deploy the httpbin sample app.
Get the external address of the gateway and save it in an environment variable.
Set up a load balancing algorithm
Define the load balancing algorithm that you want to use for your backend app in a BackendConfigPolicy.
Create a BackendConfigPolicy to configure your load balancing algorithm for the httpbin app.
Verify that your configuration is applied by reviewing the Envoy configuration.
- Port forward the
httpdeployment on port 19000.kubectl port-forward deploy/http -n gloo-system 19000 & - Open the
config_dumpendpoint.open http://localhost:19000/config_dump - Search for the
lb_policyfield, and verify that the policy that you set is listed, along with your other load balancing settings. For example, the following output shows theLEAST_REQUESTpolicy, with thechoice_countfield set to3, and settings for the slow start window.... "lb_policy": "LEAST_REQUEST", "metadata": {}, "common_lb_config": { "consistent_hashing_lb_config": {} }, "ignore_health_on_host_removal": true, "least_request_lb_config": { "choice_count": 3, "slow_start_config": { "slow_start_window": "10s", "aggression": { "default_value": 1.5, "runtime_key": "upstream.kube_httpbin_httpbin_9000.slowStart.aggression" }, "min_weight_percent": { "value": 10 } } } ... - Stop port-forwarding the
httpdeployment.lsof -ti:19000 | xargs kill -9
- Port forward the
Cleanup
You can remove the resources that you created in this guide.
kubectl delete BackendConfigPolicy httpbin-lb-policy -n httpbin