superfly / fly-autoscaler

A metrics-based autoscaler for Fly.io
Apache License 2.0
28 stars 4 forks source link

Scale via create/destroy #23

Closed benbjohnson closed 8 months ago

benbjohnson commented 8 months ago

This pull request implements autoscaling by creating & destroying Fly Machines. Previously, existing machines could be started or stopped but there was always a fixed pool to scale within. With this change, users can set a single threshold (created-machine-count) or a threshold range (min-created-machine-count & max-created-machine-count) to scale their machines by creating & destroying.

One limitation of this approach is that creation is performed by cloning an existing machine in the app so this scaler does not support scale to zero. You can still scale down your last machine by stopping it by using max-started-machine-count.

Fixes https://github.com/superfly/fly-autoscaler/issues/18

Usage

To enable create/destroy scaling, you can set the related environment variables to an expression representing the desired number of machines:

FAS_CREATED_MACHINE_COUNT="queue_count / 10"

or specify a range:

FAS_MIN_CREATED_MACHINE_COUNT="queue_count / 10 - 1"
FAS_MAX_CREATED_MACHINE_COUNT="queue_count / 10 + 1"

or you can specify these in your fly-autoscaler.yml file:

created-machine-count: "queue_count / 10"

or

min-created-machine-count: "queue_count / 10 - 1"
max-created-machine-count: "queue_count / 10 + 1"