I keep getting a sporadic error from Cloud Functions for Firebase when converting a relatively small image (2mb). When successful, the function only takes about 2000ms or less to finish, and according to Image Magick documentation should I should not see any problems.
I tried increasing the buffer size for the command, which isn't allows from within Firebase, and I tried to find alternatives to .spawn()
as that could be overloaded with garbage and slow things down. Nothing works.
You can set this from within your Cloud Function file on Firebase.
const runtimeOpts = {
timeoutSeconds: 300,
memory: '1GB'
}
exports.myStorageFunction = functions
.runWith(runtimeOpts)
.storage
.object()
.onFinalize((object) = > {
// do some complicated things that take a lot of memory and time
});
Taken from the docs here: https://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation
Don't forget to then run firebase deploy
from your terminal.
I was lost in the UI, couldn't find any option to change the memory, but finally found it:
[update] As one commenter suggested, this should no longer be an issue, as firebase functions now maintain their settings on re-deploy. Thanks firebase!
Turns out, and this is not obvious or documented, you can increase the memory allocation to your functions in the Google Functions Console. You can also increase the timeout for long-running functions. It solved the problem with memory overload and everything is working great now.
Edit: Note that Firebase will reset your default values on deploy, so you should remember to login to the console and update them right away. I am still looking around for a way to update these settings via CLI, will update when I find it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With