# Resource limits

> Cap memory, CPU, processes, restarts and logs per Falak service, with defaults per environment and a capacity view per server.

Source: https://falak.sh/docs/guides/resource-limits/

Since v0.10.0 every service can have resource limits, so one service that leaks memory or forks without end is stopped by its own limit, not by the server running out.

## Where to set them

- **Sites and Compose services:** the site's **Settings → Resources**. A Compose project is limited per service; its `*` entry is what services without their own limits get.
- **Workers and daemons:** their form in the site's **Processes**.
- **Database containers:** memory and CPUs in the database's **Limits & settings** (see [Create databases](/docs/databases/create-databases/#limits-and-settings)).
- **Functions:** their own memory and scaling settings.

Static sites have no limits. FrankenPHP sites run inside the shared edge, so they only take the restart policy, log caps and OOM preference.

## The limits

| Limit | Meaning |
|---|---|
| Memory limit | MB, at least 32. Bounded by the smallest server of the site |
| Memory reservation | MB, at most the limit; counted in the capacity view |
| CPUs | Cores, decimal (`0.5`, `2`) |
| Processes (`pids_limit`) | The most processes and threads the service may run |
| Restart policy | `always`, `unless-stopped` or `on-failure`, with **max restarts** for `on-failure` |
| Log size and files | MB per log file and number of files kept |
| OOM | `protect` (killed last) or `normal` |

Leave a field empty for no limit.

## How they are applied

| Service | Mechanism | Takes effect |
|---|---|---|
| Docker sites | Container limits | Live (`docker update`); log caps, OOM and removed limits at the next deploy |
| Compose services | A generated `compose.falak.yaml` override (`mem_limit`, `cpus`, `pids_limit` and the matching `deploy.resources`, logging) | Next deploy |
| Classic sites, workers, daemons | A systemd slice per service (`MemoryMax`, `MemoryHigh`, `CPUQuota`, `TasksMax`); the site's web process, Octane and Horizon share the site's slice | Live |

The panel says which applies after you save: **live**, **redeploy**, or nothing to do.

Pools of one PHP-FPM master share its cgroup, so a pool can't be limited on its own. A PHP-FPM site with memory, CPU or process limits moves into a PHP-FPM master of its own (`falak-fpm-<slug>.service`, a short restart of its pool); without limits it stays in the shared `phpX.Y-fpm`.

## Defaults per environment

Limits are written on a service **when it is created**, never merged later, so changing a default or moving a service never changes the limits of services that exist.

| Environment | Memory | CPUs | Processes | Logs |
|---|---|---|---|---|
| Production | none | none | none | none |
| Other environments | 512 MB | 1 | 512 | 20 MB × 3 |
| Previews | 384 MB | 0.5 | 256 | 10 MB × 2 |
| Fork previews | 256 MB | 0.25 | 128 | 5 MB × 2 |

The operator changes the non-production defaults with `FALAK_LIMITS_NONPROD_MEMORY_MB`, `_CPUS`, `_PIDS`, `_LOG_MB` and `_LOG_FILES` (and `FALAK_LIMITS_PREVIEW_*`, `FALAK_LIMITS_FORK_PREVIEW_*`) in `/opt/falak/custom.env`.

## Capacity per server

The server page's **Capacity** card adds up what every service on it may use — sites, Compose services, workers, daemons, database containers (their whole memory) and functions (`max_instances` × their memory) — against the server's RAM and cores, and warns when memory limits, reservations or CPU limits are **overcommitted**. The API has it as [`GET /api/v1/servers/{server}/capacity`](/docs/api/servers/#get-apiv1serversservercapacity--serversview).

## OOM kills and restart loops

Agents report out-of-memory kills and restarts of managed containers, slices and supervised programs. Two alerts follow:

| Alert type | When |
|---|---|
| `limits.oom_killed` | A service was killed for running out of memory |
| `limits.restart_loop` | A service restarted 5 times within an hour (`FALAK_LIMITS_RESTART_LOOP`) |

Both can trigger an automatic rollback while a release is [watched after deploy](/docs/guides/release-watch/).

## Next steps
