Lots of memory and processor usage with no result

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
ahmed.eldawy

Lots of memory and processor usage with no result

Post by ahmed.eldawy »

Hello,
I'm trying to resize a large gif file using ImageMagick. The file dimensions are 14400x9600. I am trying to resize it to (8190x8190>) which means both width and height should be less than or equal 8190 with aspect ratio maintained.
The result is very high memory usage (my 2gb memory is 100% in use + swapping), the cpu is 100% used which results in a very slow response. I can't even kill the process or cancel the operation.
After a long time (>15 minutes) I find a resulting gif file with dimensions 14400x9600. No resize has occured. I tried "8190x8190!" with the same result.
The file can be found at http://www.badrit.com/9.gif
Is this behavior normal with large gif files?


I'm using ImageMagick 6.4.5 2009-06-04 Q16 OpenMP
OS is ubuntu 9.04
CPU is Intel DualCore 1.83 T5600
Memory is 2GB
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Lots of memory and processor usage with no result

Post by magick »

See http://www.imagemagick.org/script/architecture.php. Chances are your image pixels are being cached to disk which is orders of magnitude slower than caching pixels to memory. We're using ImageMagick 6.5.4-2 and your script ran in 41 seconds when pixels are processed in memory. We added -limit area 1mb to the command line to force the pixel processing to disk and it ran for a long time but it did complete. To track progress, add -debug cache to your command line. Or add -monitor.

You can speed up the process considerably with -sample rather than -resize.
ahmed.eldawy

Re: Lots of memory and processor usage with no result

Post by ahmed.eldawy »

Thanks magick for the help. I read the architecture and I decided the following
Installing Q8 version instead of Q16 version. I have nothing to lose because my server works with b/w images only.
I used sample instead of resize.

I installed ImageMagick from the source with q8 and tried to convert with -sample option and it finished in few seconds. (few=3..9).

I use rmagick to access magick functions from my ruby program. When I tried to convert the same file using rmagick it used a lot of memory. Do you think using the command line for resizing images is faster than loading an image in the memory, converting it then writing it back to disk?
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

Re: Lots of memory and processor usage with no result

Post by rmagick »

If you're using the same version of ImageMagick with RMagick that you're using from the command line, then the same image occupies the same amount of memory no matter how you access it. The difference is that when the command completes and the process terminates all memory associated with the process is deleted. With RMagick, the Ruby process doesn't terminate until your script does. Until recently you had to destroy the image with the #destroy! method if you wanted to free the image memory faster than Ruby's GC would do it. See my post on the RMagick Hints & Tips forum here: http://rubyforge.org/forum/forum.php?th ... um_id=1618.

All that changed with RMagick 2.10.0. Starting with this release you can tell Ruby to do all the memory management for you. It won't use any less memory per image but Ruby will be more aggressive about freeing the image when you're done with it. See my post on the RMagick Hints & Tips forum here: http://rubyforge.org/forum/forum.php?th ... um_id=1618.

Regarding relative speed, using the command line means that you have to start a new process for each image. If you're processing multiple images using RMagick means that you can avoid that. If you're just doing one image then it doesn't matter.
Post Reply