Load balancing
Run each app on every server of a cluster and send each visitor to the nearest server, or to the one with the most room.
Load balancing runs an app on every server of a cluster and shares its visitors between them. You choose where each visitor goes:
| Mode | Every visitor goes to |
|---|---|
| Nearest server (the default) | The server closest to them |
| Most available server | The server with the most free memory and processor |
- It needs replication on. Otherwise the switch is refused: "Turn on replication first: load balancing needs it."
- Off by default. An instance admin turns it on per cluster.
Turn it on
Open the cluster
Settings -> Servers, then the cluster's folder.
Switch on Load balancing
Beside Failover and Replication. The toast says Load balancing on for eu.
Pick where visitors go
Nearest server or Most available server, in the list beside the switch. Change it any
time: eu sends visitors to the most available server.
Activity records it: Turned load balancing on for cluster eu: visitors go to the nearest server.
Which apps it reaches
An app is load balanced when all of these are true:
- it has a Cloudflare domain. Visitors reach every server only through Cloudflare. See Addresses and Cloudflare
- it keeps no data on its server: no Volume, no File, no published port
- it is not a Compose app
From its next deploy, such an app runs on every server of the cluster: at least one replica on each, more if its replica count is higher. Settings -> Advanced -> Replicas says: "Load balancing runs it on 3 servers: visitors are shared between them".
An app with stored data stays on one server. Its data has one writer: two servers writing the same files would lose one's changes. Replication keeps that data ready on the other servers for a failover.
Nearest server
Each server runs the app beside its own Cloudflare connector, and Cloudflare sends each visitor to the server closest to them. When a server stops, its visitors go to the next closest at once: the others were already answering.
Most available server
The app still runs on every server, ready to take over, but only one server takes its visitors: the one with the most room.
- Deplo looks at each server's free memory and processor every 30 seconds.
- It changes server only when another one has clearly more room, so visitors do not bounce between two that are about the same.
- The new server starts taking visitors before the old one stops, so none are dropped.
- If that server stops, another one takes the visitors within about 30 seconds.
Turn it off
The same switch. With Most available server, every server takes visitors again at once. Apps go back to their own replica count at their next deploy.
Turning replication off turns load balancing off too.
Over the API: setClusterLoadBalancing, Cluster.loadBalancingEnabled and
Cluster.loadBalancingMode. Over MCP: set_cluster_load_balancing.
See also
Did this page help you?