Algorithms
The algorithm is the rule that decides which target gets the next request (Application load balancers) or the next connection (Network load balancers). It only chooses among targets that pass their health check.
When to use each algorithm
If you’re not sure, keep Least request.
Targets have no weights. Every healthy target is treated the same, so use VMs of the same size behind one load balancer.
How it works
- Each node of the load balancer keeps a list of targets that currently pass their health check.
- For each new request or connection, the node picks one target from that list with the algorithm.
- If a target fails its health check, it leaves the list and the others share its traffic. When it passes again, it rejoins.
In the API, the algorithm belongs to each target group, so groups can differ. The portal’s create form sets one algorithm for every forwarding rule.
Before you begin
- A load balancer, or the details to create one. See Create a load balancer.
- To change it with the API, an API token with
load-balancer.write.
Set the algorithm in the portal
Open the form
To set it on a new load balancer: under Network & Security, click Load Balancer, then Create Load Balancer.
To change it on an existing one: open the load balancer, click Settings, then Edit next to Algorithm and options.
The same section has Options: Sticky sessions for an Application load balancer (“Keep a visitor on the same target with a cookie.”) and Proxy Protocol for a Network load balancer. Proxy Protocol is proxy_protocol (v1 or v2) on a TCP target group in the API. Sticky sessions aren’t available yet: the current gateway refuses them.
Set the algorithm with the API
Send algorithm in each target group. Leave it out to get least_request.
To change it on an existing load balancer, read the load balancer, change algorithm in its specification, and send the whole specification back with PUT and the current version. See Change a load balancer for a full example.
Verify
Send a batch of requests and count where they land. If each VM returns its own hostname (for example on a /whoami page), this shows the split:
With Round robin, the counts are about equal. With Least request, each request goes to the VM with the fewest in progress, so the counts can differ when some requests are slow. Small samples vary; use 100 or more requests for a clearer picture.
