How to optimize ImageMagick

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
gregory
Posts: 67
Joined: 2009-08-02T17:20:23-07:00
Authentication code: 8675309

How to optimize ImageMagick

Post by gregory »

Hi,

My web server uses ImageMagick intensively (image resize, animations). I still use IM 6.2.8. Today I tried the latest version but it seems that new IM needs more resources. I'm thinking about IM optimization. I tried to disable OpenMP -- no luck. Still high load. Is there any options I can disable with "configure" to reduce memory/cpu consumption?

Thanks in advance.
Greg.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to optimize ImageMagick

Post by fmw42 »

install as Q8 rather than Q16 may help
gregory
Posts: 67
Joined: 2009-08-02T17:20:23-07:00
Authentication code: 8675309

Re: How to optimize ImageMagick

Post by gregory »

Will it reduce the quality of images? What is the difference?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How to optimize ImageMagick

Post by magick »

After you disabled OpenMP, did you verify it was turned off:
  • identify -version
Should not mention OpenMP. Otherwise do you have a specific image and command sequence we could download and do some timing tests. Recent releases of ImageMagick have had a number of performance improvements to reduce overhead and increase speed so in general we expect comparable performance between ImageMagick 6.6.0-10 and ImageMagick 6.2.8.
gregory
Posts: 67
Joined: 2009-08-02T17:20:23-07:00
Authentication code: 8675309

Re: How to optimize ImageMagick

Post by gregory »

Yes, OpenMP is disabled.
The problem is not in the version of IM. I just want to reduce the memory/cpu consumption as much as possible because of intensively using of IM.
That's why I'm asking about some options I can disable to improve the perfomance of IM.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How to optimize ImageMagick

Post by magick »

Add --with-quantum-depth=8 to your configure script command line. It will create a Q8 version of ImageMagick which uses half the memory and is about 20% faster than the Q16 version. Q8 processes all images as 8-bit whereas Q16 processes at 16-bits. The extra precision may not be necessary if most of your images are 8-bit (e.g. most JPEG images are 8-bit).
gregory
Posts: 67
Joined: 2009-08-02T17:20:23-07:00
Authentication code: 8675309

Re: How to optimize ImageMagick

Post by gregory »

Can you please tell me which types of images are 16-bit? PNG 24-bit? The problem is that my web server creates animations from any image sources so it's not okay to exclude some types of images.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How to optimize ImageMagick

Post by magick »

ImageMagick can read any format its supports whether its 8-bit or 16-bit. That's 8-bit per pixel component, each of read, green, blue, and alpha. 16-bit is generally only needed for high-end production systems. However, 16-bit is becoming more prevalent now-a-days. PNG and Photoshop formats for example support 16-bit per pixel component.
gregory
Posts: 67
Joined: 2009-08-02T17:20:23-07:00
Authentication code: 8675309

Re: How to optimize ImageMagick

Post by gregory »

I've installed latest IM in /usr/local. Also I have 6.2.8 in /usr.
I've tested each version of IM within 5 minutes. 6.2.8 makes an 0.86 average server load while 6.6.0-9 makes 1.5-1.8.
I've just edited the config file in my project from /usr/bin/convert to /usr/local/bin/convert.
I still have to use 6.2.8. :-( Is there any reason why new version generates high server load?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How to optimize ImageMagick

Post by magick »

Server loads are too nebulous to address what the problem could be. Instead is there a command line or set of command lines that you generally use. We'll profile them in 6.2.8 and 6.6.0. Profiling identifies exactly which methods are consuming the most time and will help us identify any bottleneck. We use ImageMagick 6.6.0 @ http://www.imagemagick.org/MagickStudio ... Studio.cgi and service load is seldom above 1 (and we get thousands of users each day).
gregory
Posts: 67
Joined: 2009-08-02T17:20:23-07:00
Authentication code: 8675309

Re: How to optimize ImageMagick

Post by gregory »

Why did you compare server load on 2 different servers?

I use this commands:
/usr/bin/convert sourceimage.gif -strip -resize SIZE image.gif
/usr/bin/convert -delay SPEED -page HxW -dispose background /path/to/img*.gif -loop 0 /path/to/result/image.gif

Nothing more.

P.S.: I have approx. 15-20 thousand of users per day.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How to optimize ImageMagick

Post by magick »

We'll take a look at the problem and report back. Some immediate optimizations are to combine your work into one command instead of 2. That will reduce process overhead by only invoking the convert program once. Another optimization is to use a scripting language rather than the command line. We use Imagick for PHP and PerlMagick for Perl and get improved performance.
gregory
Posts: 67
Joined: 2009-08-02T17:20:23-07:00
Authentication code: 8675309

Re: How to optimize ImageMagick

Post by gregory »

I'll try to use IMagick.
Do you need any additional information? Maybe IM configs or something else?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How to optimize ImageMagick

Post by magick »

For our testings, tell us generally how many images are processed with /path/to/img*.gif and what is there average size (e.g. 320x240)?
gregory
Posts: 67
Joined: 2009-08-02T17:20:23-07:00
Authentication code: 8675309

Re: How to optimize ImageMagick

Post by gregory »

how many images are processed with /path/to/img*.gif
Typically, from 1 to 6.
what is there average size (e.g. 320x240)
The maximum width is 450 pixels (when IM makes an animation; not when it resizes source photos). I can't tell you an average size because users define the size manually but many users choose 300px wide.
Post Reply