# Autoscale from metrics

**URL:** <https://community.fly.io/t/autoscale-from-metrics/7777>\
**Category:** General\
**Created:** [October 11, 2022, 12:44am UTC](https://community.fly.io/t/autoscale-from-metrics/7777 "2022-10-11T00:44:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rupurt](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/rupurt/32/5222_2.png) [@rupurt](https://community.fly.io/u/rupurt)\
**Post date:** [October 11, 2022, 12:44am UTC](https://community.fly.io/t/autoscale-from-metrics/7777/1 "2022-10-11T00:44:23Z")

</div>

Currently the autoscaler is based on the number of connections.

Do you have any plans to support alternative means of autoscaling? It would be awesome if there were options to scale horizontally (more instances) and vertically (more CPU/MEM).

For data ingestion workloads this would be super helpful and make them more elastic. Something along the lines of [Kubernetes pods autoscaling with Kafka metrics | by Roman Noze | Engineering at Palo Alto Networks | Medium](https://medium.com/engineering-at-palo-alto-networks/kubernetes-pods-autoscaling-with-kafka-metrics-9b7d5ec3c1d3)

---

<div class="post-metadata">

**Author:** ![kurt](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/kurt/32/43757_2.png) [@kurt](https://community.fly.io/u/kurt)\
**Post date:** [October 11, 2022, 1:43am UTC](https://community.fly.io/t/autoscale-from-metrics/7777/2 "2022-10-11T01:43:46Z")

</div>

We vaguely plan to bake this in. The current autoscaler is actually not what most people want, so we’re starting by tackling that. What they usually want is for machines to start on demand when there are a certain number of connections.

Scaling with different strategies is something I think people might end up building with the machines API. You can run a machine that wakes up every so often, and then starts other machines for you. Or run one that continuously polls metrics and starts and stops other things.

---

<div class="post-metadata">

**Author:** ![ignoramous](https://avatars.discourse-cdn.com/v4/letter/i/a9adbd/32.png) [@ignoramous](https://community.fly.io/u/ignoramous)\
**Post date:** [October 11, 2022, 5:09am UTC](https://community.fly.io/t/autoscale-from-metrics/7777/3 "2022-10-11T05:09:15Z")

</div>

> [@kurt](#):
>
> You can run a machine that wakes up every so often, and then starts other machines for you.

I experimented with a Machine that didn’t run a server, but just a process (ie, no `[[services]]`). I don’t remember being able to start it with the `fly m start` command. It was tore down everytime. But if I understand you right, this usecase is supported (but it doesn’t / didn’t work…)?

> [@kurt](#):
>
> The current autoscaler is actually not what most people want, so we’re starting by tackling that.

Autoscale, believe it or not, is/was one of the most interesting among Fly’s features which sadly isn’t getting the eng love it deserves.

In fact, the Fly proxy needs to observe and react in-time to (an app’s / a process’ / a machine’s) increasing / decreasing requests / connections wrt `soft_limit` and `hard_limit`s, which in my experience, it doesn’t quite do so. I imagine it is a hard problem (and relates to autoscaling in some sense) no doubt… but one that needs solving.

---

<div class="post-metadata">

**Author:** ![rupurt](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/rupurt/32/5222_2.png) [@rupurt](https://community.fly.io/u/rupurt)\
**Post date:** [October 12, 2022, 5:29am UTC](https://community.fly.io/t/autoscale-from-metrics/7777/4 "2022-10-12T05:29:45Z")

</div>

@kurt glad to hear improvements are on the radar.

@ignoramous very much agree here. It feels super close to being what people naturally expect + adaptable to other contexts like stream processing.

> Autoscale, believe it or not, is/was one of the most interesting among Fly’s features which sadly isn’t getting the eng love it deserves.

---

<div class="post-metadata">

**Author:** ![goncalo-oliveira](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/goncalo-oliveira/32/13429_2.png) [@goncalo-oliveira](https://community.fly.io/u/goncalo-oliveira)\
**Post date:** [November 9, 2023, 4:35pm UTC](https://community.fly.io/t/autoscale-from-metrics/7777/5 "2023-11-09T16:35:37Z")

</div>

@kurt 👍

I was about to post a question regarding this. When we’re dealing with worker apps, that have no public connection to the outside work, the requirements to scale these worker apps have nothing to do with the number of connections or requests.

A stream processing worker for instance, might need to scale up if the number of unprocessed messages in the stream suddenly increases. It seems the only way to do something near this is to write a worker app that periodically checks these conditions and uses machines api to scale up or down, though, this seems like a lot of trouble.

Since custom metrics are already baked in, I think that it would make sense to use them. Maybe being able to define thresholds based on custom metrics.

---

<div class="post-metadata">

**Author:** ![wjordan](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/wjordan/32/1280_2.png) [@wjordan](https://community.fly.io/u/wjordan)\
**Post date:** [November 9, 2023, 4:55pm UTC](https://community.fly.io/t/autoscale-from-metrics/7777/6 "2023-11-09T16:55:16Z")

</div>

Yes, we hear you on this, I think the use case you described is very clear. Autoscaling based on prometheus metrics is something we’d like to eventually support in the platform.

> [@goncalo-oliveira](#):
>
> It seems the only way to do something near this is to write a worker app that periodically checks these conditions and uses machines api to scale up or down, though, this seems like a lot of trouble.

Yeah, that’s the current do-it-yourself approach that works today. It’s not ideal, but if you want to go this direction here’s a pointer to a Bash-script example of this that could help you get started:

> [@Autoscaling on CPU utilization?](https://community.fly.io/t/autoscaling-on-cpu-utilization/12797/22):
>
> Hi @akutruff, it’s probably not what you’d like or ideally want but here’s an basic example of what you could do to scale based on CPU: #!/bin/bash ​ if [-z $FLY\_API\_TOKEN]; then echo "missing required FLY\_API\_TOKEN environment variable" exit 1 fi ​ api\_base=https://api.machines.dev ​ while getopts a:c: flag do case "${flag}" in a) app\_name=${OPTARG};; c) cpu\_threshold=${OPTARG};; \?) # Invalid option echo "Error: Invalid option" echo "usa…

---

<div class="post-metadata">

**Author:** ![goncalo-oliveira](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/goncalo-oliveira/32/13429_2.png) [@goncalo-oliveira](https://community.fly.io/u/goncalo-oliveira)\
**Post date:** [November 9, 2023, 5:12pm UTC](https://community.fly.io/t/autoscale-from-metrics/7777/7 "2023-11-09T17:12:40Z")

</div>

Thanks for the quick reply @wjordan

I was actually thinking that since I already have a worker app running that has access to these metrics (since it produces them), I might try to connect to the machines api directly - the app scaling itself 👻  
It’s not ideal, for sure, but until custom metrics are supported, it might be an option.
