sharp icon indicating copy to clipboard operation
sharp copied to clipboard

Memory use: what should I expect while processing large image files?

Open dmitrizzle opened this issue 1 year ago • 4 comments

I need help understanding what to expect in terms of memory usage.

For some reason, I thought that using streaming and Jemalloc (on Node Alpine-18) would let me make transformations to image files that are larger than available RAM. #179 appears to be proving me wrong. (?)

What should I expect in terms of memory usage for the following:

  • Download a large image file 250MB.
  • Convert the downloaded image into an uncompressed PNG. All the below pipelines except the last stream to PNG files.
  • Create a small copy of that file for analysis.
  • Split the large image file into 3 channels (R, G, B) and perform transformations on those channels individually (using linear).
  • Assemble transformed R, G, B channels into a complete image.
  • Convert the completed image to JPEG or another format based on user input.

My (Dockerised) app on Heroku needs about 2.5GB of RAM to safely complete the above tasks. Is this reasonable?

dmitrizzle avatar Dec 21 '24 05:12 dmitrizzle

Did you see the recomb operation? That should allow you to apply separate linear multiplications to 3 channels at once, avoiding splitting/joining channels.

lovell avatar Dec 22 '24 12:12 lovell

Will try that, thanks! I should add that the memory use jumps before the process gets to channel splitting (so, if I were to comment that part out, memory usage would still be this high).

dmitrizzle avatar Dec 26 '24 18:12 dmitrizzle

@dmitrizzle Were you able to make any progress with this?

lovell avatar Jan 27 '25 08:01 lovell

Hi @lovell ,

It's been integration hell for the past couple of months here so I wasn't able to try recomb to replace my current operations.

However, I moved from Heroku onto DigitalOcean with CapRover manging my container on a droplet with 2GB of RAM. I also enabled swap memory on that container. The graph below shows the spikes during processing 155.7MB and a 155.9MB TIFF files. It appears that the delta is about 1GB of RAM. Swap memory didn't seem to have been affected during the process at all.

There are no more incidents that crash my app due to high RAM usage but I'm still not 100% confident I'm optimizing it correctly.

Image

dmitrizzle avatar Feb 03 '25 19:02 dmitrizzle