I see the amount of ram available as a env var (The Machine Runtime Environment · Fly Docs) but i don’t see a way to know the type of cpu, or the number of cpus. My planned workaround is to use nproc in the shell startup to set an environment variable that my app can use, but I don’t know how the app could know if its machine is shared or performance. Is there a way?
Hm… The full configuration details, including the cpu_kind, can be retrieved at runtime from the Machines API, although that’s rather heavyweight:
https://fly.io/docs/machines/api/machines-resource/#get-a-machine
(You would need both an HTTP client and a JSON parser.)
The Machine can be given a read-only token that’s limited to just that one app.
(It can actually be attenuated all the way down to only being able to access the information about that single Machine, if you want,
.)
Personally, I would instead just specify this kind of hint ahead of time under [env] in fly.toml—or as an entry in the corresponding section of the Machines API call, if the instance is being created dynamically.
If you could say a little more about why it helps to know shared vs. performance and some of the context about why that couldn’t be set statically, people might think of other suggestions…
I was thinking about adding one beefy machine to a running erlang cluster when doing a data import, and wanting that machine to tell its nodemates that it’s able to take more work (eg. HashRing has the ability to set a weight). I will probably not be mixing shared and performance machines, but realized that nproc returning ‘8’ isn’t enough to claim ‘i can handle more work’. The reference to the API is enough of a solution if one wanted to go that route, so I’ve marked it as such, thanks.
I would recommend, in this case, to use a different process group for this. it is exposed to the app as FLY_PROCESS_GROUP environment variable. (this is set by flyctl into a machine metadata key whose name I don’t recall off the top of my head; but if you are deploying outside of flyctl you should be able to set the metadata yourself and it will still show up in the environment)
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.