# Load balancers

CrushTest tests a farm through its load balancer as your users reach it, and shows how the load spread over the back ends.

## Setup

In the server's editor:

1. The protocol addresses point at the **balancer**.
2. Under **Load balancer**, **Add a back end** for each CrushFTP or CrushMFT server behind it: a name, **its own admin URL** (not the balancer's), an admin user or a v27 token, and its TLS check. A pinned certificate list (`pin`, comma separated) covers back ends that each have their own certificate.
3. With **CrushBalance 27**: its admin URL and a read-only **API token** (and its metrics token, if set). CrushTest then also reads the balancer's own record of every connection.

![Two back ends and CrushBalance in the server's editor](Load-Balancers/backends.png)

## What it shows

- **During the run:** our sessions per back end, now.
- **In the results:** per back end, the run's sessions and operations, its CPU and counters; with CrushBalance, the run's connections per endpoint as the balancer saw them.

## Failures a balancer causes

CrushTest names them, so they are not mistaken for server errors:

| Error | What happened |
|---|---|
| `lb_session_moved` | an HTTP request of a signed-in session was answered by a back end that does not hold the session (401 or a redirect to the login): the balancer does not keep a session on one back end |
| `lb_passive` | an FTP data connection failed behind a balancer: the passive port was not sent to the back end that opened it |

Each shows as a banner on the run. For HTTP, the keep-alive client keeps each session on one connection and so on one back end; the CrushTunnel client opens a new connection for every request, as CrushFTP's own clients do, and shows whether the balancer keeps sessions together ([Profiles](Profiles.md)).

## Clean-up behind a balancer

After the run CrushTest removes its files through the balancer. A balancer that moves sessions between back ends can make that slow; the clean-up stops after 2 minutes, and what is left shows under **left to clean up** on the server.
