1
votes

Not sure if it's in Firebase scope but it's in Firebase official docs.

I tried to implement a moderate-image example which worked quite well https://github.com/firebase/functions-samples/blob/Node-8/moderate-images/functions/index.js

It took about 1 minute to get the download url of a blurred image. Then I tried quite the same ImageMagick function with partial blur:

await spawn('convert', [tempLocalFile, '-region', '10x10+5+5', '-blur', '0x8', tempLocalFile]);

It also worked without issues and took the same time.
Then I tried to perform a sequence of this operation like this:

 for (const i in regions) await spawn('convert', [tempLocalFile, '-region', i, '-blur', '0x8', tempLocalFile]);

There were 8 elements in regions, so convert operation was performed 8 times. On the 2nd minute the console showed Function execution took 60003 ms, finished with status: 'timeout'. On the 9th minute I received the image with 8 blurred regions as intended.

So the questions are:

  1. Is it normal time for such a basic image manipulation?
  2. Could it be somehow accelerated?
  3. What workflow could it be if one decide to get Cloud Vision result JSON, perform all image manipulations client-side and then re-upload the final image back to Firebase?
1
How big is the image? How long does it take if you run the conversion on your local machine? - Doug Stevenson
@DougStevenson Thanks for the question! It's 850x573 and hardly 1 minute in total from A to Z. Tested on Ubuntu 18.04. Is there a way for Q#3? - Igniter

1 Answers

0
votes

My current personal experience says that you don't want such loops in your Functions.

If you have to perform some basic image manipulations you'd better do it locally.
In worst scenario do it manually less than 10 operations in a row max, depending on a manipulation type:

await spawn('convert', [tempLocalFile, 
    '-region', '100x100+50+50', '-whatever',
    '-region', '100x100+50+50', '-whatever',
    ...
]);

If we talk about applying blur, then you'd better use this command with options around or equal to '0x8'. Less gives insufficient blurring and values more give you exponentially longer time of overall execution.

Thereby I was able to receive the legit looking partially blurred output image before the Functions timeout.