Scaling¶
One binary runs in one of three roles (server.role, or hangar server --role):
| Role | Serves | Runs Jobs | Scale |
|---|---|---|---|
all (default) |
Web UI, native API, Hub API, git, Ollama | Yes | The only role for SQLite. |
web |
Everything HTTP | No | Any number of replicas behind a load balancer. |
worker |
Health and metrics only | Yes | Any number of replicas. |
web processes are stateless: everything shared lives in Postgres or the Blob store, so any request can reach any replica, including each request of a git push or a multipart upload. Run them behind a load balancer that does not buffer request or response bodies and has no total request timeout, because uploads and downloads stream.
What a scaled-out Instance needs¶
- Postgres and an S3-compatible bucket (or a shared filesystem path).
- The same
security.instance_keyon every process. Hangar generates a key only in roleall. A process in roleweborworkerrefuses to start without one, unless it shares aserver.data_dirwhosesecrets.yamlalready holds a key. Make a key withopenssl rand -base64 32and give it to every process asHANGAR_SECURITY_INSTANCE_KEY. The Helm chart generates one into a Secret, or reads it fromexistingSecret. hangar admin migratebefore new versions start.- Each worker process runs up to
jobs.workersJobs at once (4 by default).pull.concurrencyalso caps Pull transfers across the Instance.
Shutting down¶
On SIGTERM, a process answers 503 on /readyz at once, and its worker stops claiming new Jobs. It keeps serving for server.drain_delay (0 by default), so a load balancer that checks /readyz stops sending requests before the listener closes. Then in-flight requests get up to server.shutdown_timeout (30 seconds) to finish, and the worker waits as long for its Jobs. A Job whose handler is still running after that goes back to the queue when its lease expires.
Behind a load balancer outside Kubernetes, set server.drain_delay to a little more than the load balancer's health check interval, such as 5s. The Helm chart adds a 5-second preStop sleep (drainDelaySeconds), or sets server.drain_delay on Kubernetes 1.29, which has no sleep action.
The scaled Compose example and the Helm chart show complete setups.
Targets¶
On the reference setup (two web replicas with 2 vCPU and 1 GiB each, one worker, Postgres and MinIO), Hangar aims for:
| Measure | Target |
|---|---|
| Repos per Instance | 100,000 |
| Files per Repo | 100,000 |
HEAD /resolve p99 at 200 requests per second per replica |
under 50 ms |
| Memory during a 50 GiB upload or download | flat, under 256 MiB per replica |
| Web replica start to ready | under 5 seconds |
The load tests in loadtest/ measure them.