convert causes 100% CPU. Can it be decreased?

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?".
Dennis Karlberg

convert causes 100% CPU. Can it be decreased?

Post 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..
giso

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

Post by giso »

While using convert from the commandline on a linux system you could use "nice"

nice -n 19 convert [...]
Dennis Karlberg

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

Post 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?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

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

Post by magick »

Add -limit memory 1mb -limit map 2mb to your command line to trade off I/O usage for CPU usage.
giso

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

Post 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
gsprague

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

Post 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
gsprague

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

Post by gsprague »

This is still causing my server to crash daily...does anyone have any recommendations?

Thank you!
gsprague

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

Post 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!
StephenP

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

Post by StephenP »

Try reading:
http://www.imagemagick.org/script/resources.php

Especially the part regarding MAGICK_MAX_MEMORY and environment variables.
gsprague

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

Post by gsprague »

I have tried adjusting these variables over and over again, doesn't seem to help. I must be doing something wrong!!
User avatar
mitma
Posts: 1
Joined: 2011-02-24T06:53:50-07:00
Authentication code: 8675308
Location: Italy

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

Post 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 [...]
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

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

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
frank87
Posts: 3
Joined: 2014-10-31T09:08:44-07:00
Authentication code: 6789

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

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

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

Post by magick »

See -limit throttle @ http://www.imagemagick.org/script/resources.php: ImageMagick periodically yields the CPU.
Post Reply