Restrict ImageMagick memory consumption in AEM DAM
This article helps you learn how to restrict memory consumption in the ImageMagick conversion process. ImageMagick provides several options to control resource usage, including memory, map, disk, and file limits. These can be set using the -limit option.
Description description
Environment
- ÃÛ¶¹ÊÓƵ Experience Manager (AEM)
Issue/Symptoms
ÃÛ¶¹ÊÓƵ Experience Manager’s DAM (Digital Asset Management) ImageMagick consumes a lot of memory. When .ai assets are uploaded (MIME type application/postscript), the ingestion workflow calls the ImageMagick process to generate thumbnails. ImageMagick consumes a lot of memory (for example, a minimum of 15% of memory per process).
If five assets of type .ai are uploaded, ImageMagick consumes all the memory in the system and brings AEM down.
Is there any way to restrict memory consumption in the ImageMagick conversion process?
Resolution resolution
ImageMagick provides several options to control resource usage, including memory, map, disk, and file limits. These can be set using the -limit option.
The -limit option allows you to set various resource limits for the conversion process. The syntax for setting a memory limit is as follows:
convert -limit memory <
value>
input_image output_image
Where *<
value>
*is the maximum amount of memory (in bytes) that the process is allowed to use. You can use suffixes like MB for megabytes or GB for gigabytes to make it more readable.
Example:
To limit memory usage to 500MB, you would run:
convert -limit memory 500MB input_image.jpg output_image.jpg
In addition to memory, you can also limit other resources:
- Map: Limits the amount of memory map usage.
- Disk: Limits the amount of disk space usage.
- File: Limits the number of open files.
The syntax is similar to the memory limit:
convert -limit map 1GB -limit disk 2GB -limit file 50 input_image.jpg output_image.jpg
You can also set default resource limits by modifying the ImageMagick policy configuration file, typically located at /etc/ImageMagick-6/policy.xml or /etc/ImageMagick-7/policy.xml depending on your version.
Here’s an example of how to set these limits in the configuration file:
<policymap>
<policy domain="resource" name="memory" value="500MB"/>
<policy domain="resource" name="map" value="1GB"/>
<policy domain="resource" name="disk" value="2GB"/>
<policy domain="resource" name="file" value="50"/>