DocsRunning your app
Scaling and health checks
Size of a VM
Each VM of an app gets one virtual CPU and the memory you set:
snapwake deploy . --mem 1024The default is 512 MB. The range is 64 MB to your plan's limit (2 GB per VM in the beta; see Usage and limits). Memory is a ceiling, not a charge: you pay for the memory the app actually uses while it is awake.
If the app uses more than its memory, the kernel inside the VM kills its process. The VM itself keeps running; see When your process exits.
Choosing memory automatically (memory = "auto") is planned; today auto means 512 MB.
More than one VM
By default an app runs at most one VM. To let it handle more load:
snapwake scale shop --max 4 # up to 4 VMs
snapwake scale shop --max 4 --concurrency 10 # add a VM at 10 requests in flight per VM| Setting | Meaning | Default | Range |
|---|---|---|---|
--max |
the most VMs the app may run | 1 | 1 to 64, within your plan |
--concurrency |
requests in flight per VM before another VM is woken | 4 | 1 to 1000 |
--min |
VMs kept awake even with no traffic | 0 | 0 to max |
How it works:
- Each request goes to the VM with the fewest requests in flight.
- When every VM has at least
concurrencyrequests in flight and the app is belowmax, Snapwake wakes another VM from the same snapshot in the background. The request that triggered it doesn't wait for it. - A VM beyond the first goes back to sleep after 20 seconds without requests. The whole app sleeps 10 seconds after its last request, as usual.
- All VMs of an app currently run on its home server.
Apps with a volume always run one VM.
Always-on instances
snapwake scale shop --min 1With --min 1 one VM stays awake with no traffic, so no request ever waits for a wake. If the VM stops, it is started again. If only your app's process exits inside it, nothing notices unless the app has a health check, so set one for always-on apps (see below). You pay for the VM's memory all the time, as on a platform without sleep. Not available on the Hobby plan.
--min 0 returns the app to sleeping.
Health checks
snapwake health shop --path /healthz # every 10 seconds
snapwake health shop --path /healthz --every 30
snapwake health shop --offSnapwake sends GET <path> to every awake VM of the app at the interval you set (10 seconds by default, at most 3600). The check passes on any 2xx or 3xx answer within 3 seconds. The request carries User-Agent: flare-health.
Health checks are not traffic: they go to the VM over an internal channel, don't wake a sleeping app, and don't keep an awake app from going to sleep. A sleeping app is not checked.
What counts as a failure
- three failed health checks in a row (the VM is then stopped);
- the VM stopping on its own (a crash of the VM, not of your process);
- a wake that didn't succeed.
When your process exits
If your app's process crashes, exits or is killed for using too much memory, the VM keeps running without it. Snapwake doesn't restart the process and, without a health check, doesn't count it as a failure. Requests reaching that VM get an empty reply, because nothing accepts the connection.
- An app that sleeps recovers once it gets 10 seconds without requests: it goes to sleep, and the next wake restores the running process from the snapshot. While requests keep arriving more often than that, it stays broken.
- An app with
minabove 0 stays without its process. Give it a health check: three failed checks stop the VM, and Snapwake wakes a fresh one. - A web app under steady traffic is in the same position: set a health check for any app that matters.
- A worker has no health checks. A queue worker whose process exited sleeps once its queue has been empty for 30 seconds, and the next job wakes it fresh; while jobs are waiting it stays awake without taking them. An always-on worker stays without its process until you redeploy. Run workers under a restart loop, for example
--worker "sh -c 'while true; do node worker.js; sleep 1; done'".
What happens after a failure
The next request wakes a fresh VM from the snapshot, after a pause that grows with each failure in a row: none after the first, then 1, 2 and 4 seconds. While the app is waiting, requests get 503 with a Retry-After header and a message such as:
shop is restarting after a failure (health); next try in 2 sAfter five failures in a row the app is broken. Requests get 503 at once:
shop is broken: 5 failures in a row, the last: health. flare tries again in 300 s, or at once when another version goes liveSnapwake tries again every 5 minutes. It also tries at once when you deploy, roll back, or change the health check. snapwake status shop shows broken and the last failure.
The count goes back to zero after a passed health check, or, for an app without one, after a VM has run for 30 seconds.