magick icon indicating copy to clipboard operation
magick copied to clipboard

Limit Threads to Reduce Memory Usage?

Open dcaud opened this issue 4 years ago • 3 comments

I'm running out of memory using functions, like image_read() and image_resize(), especially with GIFs. I'm hypothesizing that magick is using multiple threads and thus exceeding the memory on the machine. Do you think that is possible? If so, would a work-around be to limit the threads that magick uses?

This link says limiting threads is possible in some versions of ImageMagick: https://imagemagick.org/script/openmp.php

dcaud avatar Mar 09 '22 23:03 dcaud

There is an (unexported) function that you can use to set the threads:

magick:::magick_threads(2)

You can also look at the current resource (memory) limits:

magick:::magick_resource_limits()

Iirc you can set resource limits via environment variables?

jeroen avatar Mar 10 '22 07:03 jeroen

I was able to successfully set the threads using that function. However, it didn't solve the OOM problem.

But, cat("\n memory in GB:", magick:::magick_resource_limits()$memory/1e9) shows only ~0.26 GB. So that's likely the problem!

I'm facing this problem on shinyapps.io. Is the solution contacting Rstudio and asking them to adjust the policy.xml file?

Maybe change: <policy domain="resource" name="memory" value="256MiB"/> to <policy domain="resource" name="memory" value="8GiB"/>

I'm surprised that I'm seeing such a low memory availability on shinyapps.io (where I've set the instance size there to 8GB).

Any ideas?

dcaud avatar Mar 10 '22 19:03 dcaud

I submitted a request to Rstudio.

dcaud avatar Mar 10 '22 20:03 dcaud