Page 1 of 2

convert causes 100% CPU. Can it be decreased?

Posted: 2008-03-17T08:44:03-07:00
by Dennis Karlberg
Hi,
I have problem when using ImageMagick COM object from my application. When it is called from my code it causes a CPU load of 100% during conversion. I use IM to convert TIFF:s to fax comliant TIFF:s.
The command I use is

Code: Select all

ImageMagickObject.MagickImage magick = new ImageMagickObject.MagickImage();
object[] conversionString = { inFileName, "-quiet", "-scale", size, "-density", "200", "-monochrome", "-compress", "fax", outFileName };
object result = magick.Convert(ref conversionString);
I have streaming voice applications on the same server and the high CPU load causes the voice to be chopped and interupted.
My questions is if there is any way to configure convert.exe not to use all CPU? I have no problem to wait for the conversion to take longer time. More important is for my voice application to have some CPU..

Re: convert causes 100% CPU. Can it be decreased?

Posted: 2008-03-17T09:00:37-07:00
by giso
While using convert from the commandline on a linux system you could use "nice"

nice -n 19 convert [...]

Re: convert causes 100% CPU. Can it be decreased?

Posted: 2008-03-17T11:44:11-07:00
by Dennis Karlberg
Ok.. I'm using Windows and the ImageMagick COM-object. So if the -nice option only works in Linux and from commandline I cant use it. Is there another way for me to solve the issue?

Re: convert causes 100% CPU. Can it be decreased?

Posted: 2008-03-17T15:04:27-07:00
by magick
Add -limit memory 1mb -limit map 2mb to your command line to trade off I/O usage for CPU usage.

Re: convert causes 100% CPU. Can it be decreased?

Posted: 2008-03-18T02:08:38-07:00
by giso
Sorry you can't use "nice" indeed

nice is not an option, but a Linux program you can use to set processor priority

Re: convert causes 100% CPU. Can it be decreased?

Posted: 2008-10-16T15:27:34-07:00
by gsprague
My server is crashing from the convert command, sometimes one process will run up to 1GB of Real Memory while other converts are running. There is 2GBs of RAM in this server and the convert command can be running multiple times sucking up RAM. Right now there is 3 convert processes running and taking up 1.5GB of memory right now.

convert -size 150x150 -delay 200

I have tried setting this with multiple amounts of RAM but keep getting the same outcome/crashing server:
-limit memory 200mb -limit map 400mb but this also crashed my server.

Do you have any recommendations as to how to set this, should it be set way lower?

Thank you very much! :D

Re: convert causes 100% CPU. Can it be decreased?

Posted: 2008-10-31T08:43:08-07:00
by gsprague
This is still causing my server to crash daily...does anyone have any recommendations?

Thank you!

Re: convert causes 100% CPU. Can it be decreased?

Posted: 2008-10-31T09:55:53-07:00
by gsprague
I have set the following:
nice -n 19 /Volumes/Server\ HD/ImageMagick-6.4.5/bin/convert -size 150x150 -delay 200 -limit memory 1mb -limit map 2mb \"$pdf\" -resize 150x150 \"$thumbsdir$inode.gif\"";

but the converts are averaging around 3mb to 5mb and some even shoot up to 30mb+!!!

Also ghostscript is eating all of memory and splitting up the memory between all of its processes!!

Please help!

Re: convert causes 100% CPU. Can it be decreased?

Posted: 2008-11-02T15:50:57-07:00
by StephenP
Try reading:
http://www.imagemagick.org/script/resources.php

Especially the part regarding MAGICK_MAX_MEMORY and environment variables.

Re: convert causes 100% CPU. Can it be decreased?

Posted: 2008-11-04T09:09:22-07:00
by gsprague
I have tried adjusting these variables over and over again, doesn't seem to help. I must be doing something wrong!!

Re: convert causes 100% CPU. Can it be decreased?

Posted: 2011-02-24T07:24:23-07:00
by mitma
Dennis Karlberg wrote:Ok.. I'm using Windows and the ImageMagick COM-object. So if the -nice option only works in Linux and from commandline I cant use it. Is there another way for me to solve the issue?
Indeed there is a way to use the command "nice" even under Windows, I just used it now...I installed Cygwin (a compiler with its own bash shell) in Windows, and I used it as shell for ImageMagick, and in this way I'm able to use the command "nice" as giso said:

Code: Select all

nice -n 19 convert [...]

Re: convert causes 100% CPU. Can it be decreased?

Posted: 2011-02-24T07:33:38-07:00
by magick
See http://www.imagemagick.org/script/resou ... nvironment for the MAGICK_THROTTLE environment variable to periodically yield the CPU for at least the time specified in milliseconds.

Re: convert causes 100% CPU. Can it be decreased?

Posted: 2011-02-24T15:54:42-07:00
by anthony
giso wrote:While using convert from the command line on a linux system you could use "nice"

nice -n 19 convert [...]
Note that using 'nice' will not prevent a command from using 100% CPU. What it does do is say that if any other process needs CPU, it will get a higher priority than the 'nice' processes. At nice 19, that means the niced process will generally not run unless no other process needs the CPU, that it it uses 'idle' time.

None of these stop or slow down the getting the maximum usage out of the CPU, only IO and CPU clock cycle reduction will do this.

So the question becomes.. WHY do you not want a process using 100% CPU, if the CPU is not doing anything?
Is this on a laptop with battery limits or heat problems?

Re: convert causes 100% CPU. Can it be decreased?

Posted: 2015-03-11T03:34:31-07:00
by frank87
Any more thoughts on this?

- there seems to be a tool called `cpulimit`
- FreeBSD `jails` are able to limit both mem and CPU

Re: convert causes 100% CPU. Can it be decreased?

Posted: 2015-03-11T04:48:56-07:00
by magick
See -limit throttle @ http://www.imagemagick.org/script/resources.php: ImageMagick periodically yields the CPU.