Self-hosting

Scaling

Splitting the worker across containers with worker roles, CPU limits, and what to tune for large libraries.

One worker container does everything by default, and that suits most libraries. For a large library, or several machines, you can split the work up.

Worker roles

WORKER_ROLES says what a worker container runs. By default it's all. Otherwise it's a comma-separated list:

RoleRuns
stepsEvery processing step
step:<name>One step, such as step:tagging or step:description
albumsKeeping albums' rule picks current
peoplePlacing faces with people
placesPutting media in places by where they were taken
allEverything (the default)

The full list of step names is in the worker roles reference. An unknown role stops the worker at start with a message listing the valid ones.

Several workers

Run several worker containers, each with its own roles. Any number can share a role: taking work is race-safe, so two workers never do the same media, and leases keep longer runs apart. For example, to give tagging its own container, using a models server on another machine with a GPU:

compose.override.yml
services:
  worker:
    environment:
      WORKER_ROLES: steps,albums,people,places
  worker-tagging:
    extends: worker
    environment:
      WORKER_ROLES: step:tagging,step:nsfw
      MODELS_URL: http://gpu-box.lan:8090

CPU limits

Every service has a CPU limit from .env, so one busy service can't take the whole machine:

VariableDefaultService
POSTGRES_CPUS6The database
MODELS_CPUS6The models server
VISION_CPUS8The vision service (and its threads per model)
WORKER_CPUS6The worker
API_CPUS3The API
WEB_CPUS2The app
STORAGE_CPUS2Storage
MIGRATOR_CPUS2The migrator

The defaults suit an 8 to 16 core machine. On a smaller one, lower POSTGRES_CPUS, WORKER_CPUS and VISION_CPUS so the app stays responsive while the worker is busy.

Large libraries

With hundreds of thousands of media:

  • Give PostgreSQL memory. Search and duplicate checks use vector indexes that are fastest in memory. Raise shared_buffers and effective_cache_size with a command: on the postgres service.
  • Put the database on an SSD.
  • Tune step concurrency for your hardware in Settings → Processing.
  • Give the models server a card that fits every model at once, so it never has to stop one to start another. See Sharing one GPU.
  • Expect the first pass to take days, not hours: every media goes through a dozen steps. The dashboard's work queue shows each step's pace and how long the rest will take.