I’ve been following the FaaS tutorial. So far I’ve gotten a machine up and running. However, I have a few questions.
- Who’s job is it to exit during inactive periods?
Reading the tutorial, it says:
Here we’ll use a simple Fastify server running behind a small Golang HTTP proxy that exits after a few minutes of inactivity.
Does that mean the Golang proxy exits after a few minutes? Or is the fly machine doing that? I think it’s the Golang proxy but if so, I could use a little clarification on how that inactivity monitor works.
- How do I call a specific function/machine?
I’m not creating a platform where users can actually write functions, but I am associating functions to a specific user. In which case, when a user triggers a function, I should be calling a specific machine associated with a user, no? How can I do this?
Or should I separate this at the app level and give each user an app?
Thanks so much for your help! It’s been very fun learning fly so far.
You are responsible for exiting on inactivity. The Golang proxy is an example of how you might do that. It runs in the container then exits when there aren’t any connections. You could monitor for inactivity externally, but we think it’s simpler to build that into the container itself.
One problem here is this is probably dumber than you think. There’s no inactivity monitoring, really. You just make your process exit. This is what the Go proxy example is doing. It runs as a process supervisor and kills your app process on idle.
You can run per user machines a couple of ways. It mostly depends on how unique the execution environments need to be.
In some cases, you will want to build a whole new Docker image per user. If you’re doing that, it’s probably best to put each user in their own Fly app, keep a list of
Machines <-> Users, and start them by ID.
In other cases, the execution environment is very similar, you may just want to run a small script on behalf of a user. If you can encode what you need in the URL, you can have us route you to a machine to run that command. I’ve been working on a demo of this general pattern here: GitHub - superfly/bfaas: Bash functions-as-a-service
I love that you’re working on this so early. Our docs will get a lot better the more we can learn what you’re doing. If you’re interested in describing your use case here we can give some pretty precise recommendations.
Thanks for this info.
I was also looking at using machines and didn’t find any info about this on the docs. I thought maybe there was an API or something I needed to call but just ending the process is actually so much more elegant.
As soon as I have a bit of time I will try to move my audio encoding service to machines. One big advantage machines have is that they have real storage available, unlike Google Cloud Run where the whole thing runs in memory. You can’t have more storage (eg: to process large files) without adding more expensive memory.