How do I limit the memory so that it doesnt exceed it preventing a crash?

I have a discord bot, and I’m trying to implement ffmpeg, letting users convert videos to mp4, but as soon as a big video or webm is sent, it crashes the server due to memory consumption. I don’t mind it taking long, just as long as it doesn’t crash and eventually sends.

Hey there,

When the app crashes, does it crash with an out of memory error?

yep, out of memory error

I would check out this article when you get a chance about scaling your apps memory- Scale Machine CPU and RAM · Fly Docs.

ha that’s the issue, i scaled once to 1gb ram and it would still crash, so im just looking for a way to hard limit just under the max ram using maybe some Linux package or something. i know something like this exists because I launched ffmpeg on a Google shell cloud instance and it didn’t crash but was slow, which is the effect i kinda want to replicate

I’ve used cgroups on “regular” VM’s to do this - I’m not sure if there are any weird things that crop up if you do that in a Fly VM (the weirdest part is likely trying to get the config to take effect when the VM boots up - perhaps via ENTRYPOINT script).

How to install them depends on the base container used. (cgroups, kind)

(I’m not really the expert on this topic, so take this with a grain of salt).

An alternative take I think I like better is to setup some swap when the VM boots via ENTRYPOINT script. Searching this forum can get you some pointers on doing that, such as this : Swap memory - #8 by rubys

You can’t limit a process’s RAM without crashing it - either memory allocation succeeds or fails. Swap will do what you’re looking for, up to a point (up to however much swap you configure).

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.