Skip to navigation

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

AlgorithmAPI valueHow it choosesUse it when
Least request (default)least_request”Sends each request or connection to the target with the fewest in progress.”Most apps, especially when some requests are slow (reports, uploads) and you don’t want them to pile up on one VM. Start here.
Round robinround_robin”Takes turns across healthy targets.”Your VMs are the same size and requests take about the same time

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

  1. Each node of the load balancer keeps a list of targets that currently pass their health check.
  2. For each new request or connection, the node picks one target from that list with the algorithm.
  3. 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

Set the algorithm in the portal

1

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.

2

Choose the algorithm

Under Algorithm and options, choose Least request or Round robin. The text under the buttons explains the choice.

3

Save

On the create form, click Create Load Balancer. On the Settings tab, click Save.

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.

{
"name": "web",
"protocol": "HTTP",
"algorithm": "round_robin",
"targets": [
{"kind": "vm", "resource_id": "vm-7f3c2d1e", "port": 8080},
{"kind": "vm", "resource_id": "vm-8a4d3e2f", "port": 8080}
],
"health_check": {"protocol": "TCP"}
}

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:

for i in $(seq 1 20); do curl -s http://103.149.10.86/whoami; echo; done | sort | uniq -c

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.

Limits

SettingAllowedDefault
Algorithmleast_request or round_robinleast_request
ScopeOne per target group—
WeightsNot available—

Troubleshooting

You seeWhat it meansWhat to do
One VM gets almost all the trafficThe other VMs fail their health checkCheck each VM’s port or health path. See Health checks.
Slow requests pile up on one VMRound robin ignores how busy a VM isSwitch to Least request.
Users are logged out when they move between VMsEach request can reach a different VMStore sessions where every VM can read them, such as a database or shared cache, or turn on Sticky sessions in the portal.
”Choose a supported load balancing algorithm”The algorithm isn’t least_request or round_robinChoose one of the two.