carlos / carloku Public

Clone
git clone https://amadan.net/carlos/carloku

Plain git — no account needed to clone.

Download

Download this file

1# Restarting and sleeping
2
3Your app's process gets cycled for reasons that have nothing to do with new
4code. You ask for it, a config change forces it, or the platform puts a quiet
5app to sleep and starts it again when somebody turns up. This page covers the
6first and the last.
7
8```sh
9carlos restart -app hello
10```
11
12The reply says *restart requested*, which is the accurate word for what
13happened: the console wrote one small object, and every box serving the app
14notices it within seconds and cycles its own routes. No version moves, no
15channel is consulted, nothing is pushed at a box.
16
17What cycling looks like depends on how the instance runs. A long-running one
18stops and comes straight back. An on-demand one stops within seconds and
19starts again on the next request that needs it — for a quiet app, that may
20be a while. An instance that is already asleep is left asleep and
21starts fresh whenever it next wakes.
22
23Reach for restart when a process is wedged and you have no change to make. A
24deploy already cycles the app, and so does a config change — see
25[Deploying](/docs/deploying/) and [Env and secrets](/docs/config/) — so
26neither of those needs a restart after it.
27
28## What hibernation is
29
30An app nobody has talked to for a while is checkpointed to its bucket and its
31process stopped. The idle window belongs to the deployment; fifteen minutes
32is the default. The app's state was living in the bucket the whole time, so
33there is nothing to lose in the transition — the process was only ever the
34part that reads it.
35
36```sh
37carlos instances list -app hello
38```
39
40The health column reads `asleep` for those instances and `running` for the
41rest. For anything without steady traffic, `asleep` is the ordinary
42condition, not a fault to clear.
43
44## What a visitor sees
45
46A request for a sleeping app is held at the edge while the instance wakes,
47then handed to it. The visitor waits longer for that page and then gets it;
48there is no error page and nothing for them to retry. Requests that arrive
49together during a wake all join the same one instead of each starting their
50own.
51
52The exception is a wake that takes an unusual length of time. Past about
53thirty seconds the request is answered with a 503 and a `Retry-After`, and a
54wake that fails outright ends the same way. In
55both cases the reason is one line in the platform stream:
56
57```sh
58carlos logs -app hello -stream platform -since 15m
59```
60
61## Traffic that doesn't wake anything
62
63The edge keeps its own cache of responses and checks it before it goes
64anywhere near the wake path, so a crawler asking for the same public page all
65afternoon can be answered without your app running at all. What makes a
66response eligible is your app saying so: a 2xx GET with `Cache-Control:
67max-age=…` and no `Set-Cookie`. Whatever number you set, the edge caps the
68entry at five minutes, so this cannot strand a page for long. Setting that
69header on your public pages is the single most useful thing you can do for an
70app that hibernates.
71
72A TLS handshake by itself never wakes anything either — only a request that
73would reach your app does.
74
75## Work that still happens
76
77A timetable set with [carlos
78schedule](https://carlosframework.com/docs/cli/#carlos-schedule) survives
79hibernation. Before an instance goes to sleep the platform records when its
80next job falls due, and wakes it when that time arrives; the job runs, and the
81usual idle window puts it back. You do not have to keep the app awake to keep
82its schedule.
83
84Flags for [carlos restart](https://carlosframework.com/docs/cli/#carlos-restart)
85and [carlos instances](https://carlosframework.com/docs/cli/#carlos-instances)
86are in the CLI reference.
87