Three weeks ago, we announced suspend/resume support for Machines. Back then, we noted that there was no “autosuspend” feature analogous to autostop. No longer!
You can now ask our proxy to automatically suspend, rather than fully stop, your Machines when there is no traffic for them. Like autostop, you’ll save money by not running Machines when they aren’t needed, but your Machines will be able to resume from a snapshot to handle requests rather than doing a cold boot. This means that your users should get a much quicker experience when your Machines autostart.
A few caveats to be aware of:
- If your Machines are not eligible for suspension—for example, if they exceed the memory limit for the feature—then we’ll fall back to autostopping them. (Check the original Fresh Produce for information about what Machines can be suspended right now.)
- This is still a new feature, and we don’t have great data yet on how well this works for all apps/frameworks (e.g., how apps with persistent database connections will behave when they’re resumed). So give it a try, but with caution, and do let us know how it goes!
Additionally, we’ve now enabled Machine suspension in all regions, so you can suspend Fly Machines across the globe.
Enabling autosuspend
In fly.toml
This requires flyctl v0.2.94, which was released on 22 July 2024.
We’ve extended the auto_stop_machines
field associated with services in fly.toml
. In addition to the existing boolean values true
and false
, it now supports the following:
"off"
(equivalent tofalse
): your Machine will not be automatically stopped"stop"
(equivalent totrue
): your Machine will be fully stopped when idle"suspend"
: your Machine will be suspended when idle
A quick example:
[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = "suspend"
auto_start_machines = true
After updating your fly.toml, redeploy your app and enjoy!
Using fly machines
commands
This requires flyctl v0.2.94, which was released on 22 July 2024.
The fly machines create
, fly machines run
, and fly machines update
flags have an --autostop
flag. In addition to the existing boolean values true
and false
, the flag now supports the values off
, stop
, and suspend
with the same meanings as described above, e.g.:
fly machines run --autostop=suspend --port 80/tcp nginx
If you don’t specify a value (--autostop
alone), it’s equivalent to --autostop=stop
, as it was before.
Through the Machines API
We’ve extended the "autostop"
field associated with services in Machine configurations. In addition to the existing boolean values true
and false
, it now supports the string values "off"
, "stop"
, and "suspend"
with the same meanings as described above.
Here’s a full example of a typical services configuration for a Machine:
{
"services": [
{
"protocol": "tcp",
"internal_port": 8080,
"autostop": "suspend",
"autostart": true,
"min_machines_running": 0,
"ports": [
{
"port": 80,
"handlers": [
"http"
],
"force_https": true
},
{
"port": 443,
"handlers": [
"http",
"tls"
]
}
]
}
]
}
As always, let us know what you think or if you have any questions!