istro

Infrastructure

Load Balancing

How Bistro spreads work over app copies, cluster machines and one floating address.

Bistro balances load in three places. An app can run as several copies behind one address. A cluster can send a job to its least busy machine. A floating address keeps the dashboard reachable when a machine goes down.

#Copies of One App

An app with a web port can run as more than one copy. Each copy is its own systemd unit on an internal port from 30000. Caddy listens on the app's port or domain and sends each request to the next copy in turn (round robin).

bistro app set jellyfin replicas 3   # three copies behind one address
bistro app show jellyfin             # each copy, its state and port
  • Failed copies: a copy that refuses a connection or answers with a 5xx error is skipped for 30 seconds. Caddy retries the request on another copy for up to 3 seconds.
  • Health checks: when the app has an HTTP health check, Caddy also asks each copy every 10 seconds and skips the ones that do not answer.
  • Deploys: with 2 or more copies, bistro app set ID deploy rolling restarts one copy at a time, so the app never goes dark.

Some apps cannot have copies: a website folder (Caddy serves it once), an app with no web port, and an app on the host network.

#Copies That Follow the Load

Autoscale adds and removes copies by itself. It is off for every app until you turn it on.

bistro scale app ID on          # opt the app in
bistro scale app ID min 1       # fewest copies
bistro scale app ID max 4       # most copies, never more than the CPU cores
bistro scale history            # what it changed

Every 15 minutes Bistro reads the CPU of each opted-in app:

WhenThen
CPU 70% or more on 2 checks in a rowOne more copy, up to max
CPU 15% or less on 4 checks in a rowOne copy fewer, down to min

An app changes at most once every 30 minutes. A worker app can scale on jobs waiting instead of CPU: bistro scale app ID queue redis APPID KEY reads the length of a Redis or Valkey list.

#The Least Busy Machine

In a cluster, Bistro can run a job on the machine with the most room. It scores each reachable member by load per CPU core plus the share of memory in use, at the moment the job starts. There is no queue, and a running job never moves.

bistro cluster pick                       # name of the least busy member
echo 'uptime' | bistro cluster run auto root

#One Address for the Dashboard

High availability gives the cluster one floating address. It always sits on a member whose dashboard answers. When that machine dies, the address moves to the next member in about 3 seconds. It does not move back by itself.

bistro ha on 192.168.1.50     # a free address on your network
bistro ha status              # who holds it
bistro ha users sync admin    # the same sign-in on every member

Open https://192.168.1.50:2045/bistro and it keeps answering through a failover. This is failover, not balancing: one machine serves the dashboard at a time.