
Overview
You have an app with services that’s configured to automatically start and stop Machines based on traffic demand. But the traffic to your app changes significantly during the day and you don’t want to keep a lot of stopped Machines during the period of low traffic. This guide will take you through the process of configuring thefly-autoscaler app in conjunction with
Fly Proxy autostop/autostart to
always keep a fixed number of Machines ready to be quickly started
by Fly Proxy.
Configure autostop/autostart
First, if you haven’t already done so, configure the app to allow Fly Proxy to automatically start and stop or suspend Machines based on traffic demand. The autostop/autostart settings apply per service, so you set them within the[[services]] or [http_service]
sections of fly.toml:
soft_limit and stop running
Machines when the traffic decreases. You can set Machines to "suspend" rather than
"stop", for even faster start-up, but with some limitations on the type of Machine.
In the next section you’ll configure
and deploy fly-autoscaler to ensure that the app always has a spare stopped
Machine for Fly Proxy to start.
Configuring and deploying fly-autoscaler
fly-autoscaler is a metrics-based autoscaler that scales an app’s Machines
based on any metric. You can configure it to ensure that there is always
additional Machine available for Fly Proxy to start if the traffic increases.
First, create a new Fly.io app that will run the autoscaler.
fly.toml like this:
FAS_INITIAL_MACHINE_STATE configuration option to work.
And finally, deploy the autoscaler, using the --ha option to deploy only one Machine: