Limit Threads to Reduce Memory Usage?
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
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?
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?
I submitted a request to Rstudio.