timvisee / lazymc

💤 Put your Minecraft server to rest when idle.
GNU General Public License v3.0
573 stars 15 forks source link

Would this code/pattern be usable in a cloudflare worker? #13

Closed garrettjoecox closed 2 years ago

garrettjoecox commented 2 years ago

Really cool project, only downside is in its current state I’d still have to pay for something always, I’m wondering if this pattern could be used in cloudflare workers or AWS lambdas so that you are only charged on invocations. (Granted I’m not super familiar with either of those technologies and their limitations)

timvisee commented 2 years ago

I'm not sure about Lambda or Cloudflare Workers, since I have no real experience with them.

However, if spawning an instance running your Minecraft server can be arranged through a script, this likely is possible. You'd simply provide the script as 'server command' to lazymc after which it should bring up the instance. In this case it doesn't matter on what sort of platform you run.

Another user suggested to implement Terraform support, which would probably streamline this process. Though this isn't implemented, you can read about it here: https://github.com/timvisee/lazymc/discussions/5

The hard part is that you need persistent storage to store the server data. I'm not sure how this is arranged with Lambda or Cloudflare Workers. Most cloud instance providers provide a 'volume' for this to attach to an instance.

Note that when using such configuration, you'd still a machine that's always active to run lazymc itself.

garrettjoecox commented 2 years ago

My thought is to combine this pattern with https://github.com/doctorray117/minecraft-ondemand which runs the server on fargate and EFS.

That repo has a similar setup in that it doesn’t run until you want it to, but simply pinging the server in the server list will spin it up and it shows as offline for the 5 or so minutes it takes to spin up, rather than displaying a friendly message that it is spinning up.

garrettjoecox commented 2 years ago

Initially glancing through the cloudflare workers documentation had me doubting the possibility of this working, as they are focused more on HTTP connections, then I came across this from 15 days ago, how convenient! :D

https://blog.cloudflare.com/introducing-socket-workers/

Edit: Womp womp, not quite yet

"Many of the details are still being worked through"

timvisee commented 2 years ago

Thanks for looking into it.

That repo has a similar setup in that it doesn’t run until you want it to, but simply pinging the server in the server list will spin it up and it shows as offline for the 5 or so minutes it takes to spin up

If lazymc is put in between the server will probably respond much quicker as it starts instantly, without the need for the Minecraft server to be running. It could in turn start the Minecraft server on launch with wake_on_start = true.

In any case, these services handle listening on a part and starting the service up for you on socket activity. With lazymc you likely want to keep it running all the time and arrange starting an instance yourself, as it's much more user friendly. In such configuration you could also use traditional cloud services.

Sadly I don't have time right now to experiment with this to create a proof of concept.

garrettjoecox commented 2 years ago

Will revisit this issue to experiment once cloudflare releases their socket worker functionality.