lizard sleep
Let a service sleep when it gets no traffic and wake on the next request (alias lizard serverless). It sleeps with its memory saved, so it wakes where it left off, usually in about a second.
Usage
lizard sleep [service] [flags]Without --on or --off, sleep shows the setting and how many times the service has slept and woken. Without a service argument, it uses the service linked to the folder. In the dashboard, the same setting is the Serverless switch in the service’s settings.
Flags
| Flag | Description |
|---|---|
-s, --service <name> | Service name or ID (same as the service argument) |
-p, --project <id> | Project name, slug, or ID |
--on | Sleep when idle. The service restarts once to apply this |
--off | Always on. A sleeping service wakes |
--idle <minutes> | Minutes with no traffic before it sleeps, 5 to 1440. --on without it sets 10. On its own, it changes the idle time of a service that already sleeps |
How it works
After the idle time with no traffic, Lizard saves the service’s memory and processes and stops its container. The first HTTP request to an app, or the first client connection to a database, wakes it: Lizard restores the saved state, usually in about a second, and then passes the request on. If Lizard can’t restore the saved state, the service starts fresh instead, which takes as long as a normal start.
A service only sleeps when nothing is connected:
- An app sleeps when it has had no requests for the idle time and no connection to it is open. An open WebSocket keeps it awake.
- A database sleeps when no client has been connected for the idle time. A connection pool that holds connections open keeps it awake.
A paused service neither sleeps nor wakes.
Which services can sleep
- Apps with one replica and a port. Workers (port
0) and apps scaled to more than one replica can’t sleep. - Managed Postgres 14 or newer, and Managed Redis.
An app on an older runtime needs a redeploy first; the command tells you when. Any member of the project can change the setting.
Billing
While a service sleeps, it uses no CPU and almost no memory, so its compute charges nearly stop until the next wake. Lizard can still bill the data it keeps as storage; see Billing.
JSON output
With --json, sleep prints id, name, kind (app or addon), enabled, idleMinutes, sleeps, wakes, lastSleptAt and lastWokeAt (Unix time in milliseconds, or null) and lastError. After --on, --off or --idle, restarted says whether the service restarted to apply the change.
Examples
Show the setting
lizard sleep apiSleep after 30 idle minutes
lizard sleep api --on --idle 30Let a database sleep
lizard sleep --service my-db --onChange the idle time
lizard sleep api --idle 60Keep a service always on
lizard sleep api --offSee also
- lizard pause — stop a service until you resume it
- lizard scale — replicas, CPU and memory
- Managed Postgres and Managed Redis
- Billing — rates for compute and storage
Updated