Page 1 of 1
Is it possible to control cpu usage?
Posted: 2012-01-07T18:39:51-07:00
by agriz
I checked the cpu usage. It is reaches 100% with some convert scripts. Memory is free. But CPU usage become full.
Can we control the CPU usage?
Thanks
Re: Is it possible to control cpu usage?
Posted: 2012-01-08T06:48:55-07:00
by magick
CPU should be 100% otherwise its idle and not working. However, to reduce CPU usage, set the throttle resource policy in policy.xml or set the MAGICK_THROTTLE environment variable. See
http://www.imagemagick.org/script/resou ... nvironment.
Re: Is it possible to control cpu usage?
Posted: 2012-01-08T06:54:41-07:00
by agriz
i read that link. But I am not sure how to change the environment variable.
Can you guide me how to do it?
I am using centos.
Re: Is it possible to control cpu usage?
Posted: 2012-01-08T19:04:38-07:00
by anthony
Environment variables are just set of sting variables that are passed from parent programs to children
To set it for just one command put it before the command...
The number is in milli-seconds and it means go to sleep this long at selected (convenient) points in the programs image processing to allow other programs to run.
However 100% usage should not be a problem. Other programs at an equal 'nice' level should also run.
Usually the worse problem is the use of multiple threads on a mutli-core processor. You can turn of multi-threading using...
Code: Select all
MAGICK_THREAD_LIMIT=1 convert ....
or more permanently set the variable using
You can list environment variables using the command
env
For more on thread problems see IM Examples, Making IM Faster (in general)
http://www.imagemagick.org/Usage/api/#speed
Re: Is it possible to control cpu usage?
Posted: 2012-01-10T09:05:29-07:00
by agriz
/var/log/message is giving me the following warning
Code: Select all
kernel: possible SYN flooding on port 80. Sending cookies.
I hired a freelance to fix this problem.
But he is telling that convert command is using higher cpu usage.
The website is hardly running. It took very long time to load.
Top command gives something like this.
Code: Select all
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
10939 apache 20 0 204m 5824 2452 R 201.3 0.1 0:06.06 convert
10947 apache 20 0 135m 3828 2016 R 51.5 0.0 0:01.55 convert
10955 apache 20 0 198m 6064 2020 R 43.5 0.1 0:01.31 convert
10972 apache 20 0 198m 3732 2016 R 4.6 0.0 0:00.14 convert
I have already added
Re: Is it possible to control cpu usage?
Posted: 2012-01-10T10:26:00-07:00
by magick
To reduce the load ImageMagick puts on a server you can single thread it by building without OpenMP support or as you did, or limit the number of threads to 1 or 2. You can do this with the policy.xml configuration file, for example,
- <policy domain="resource" name="thread" value="2"/>
<policy domain="resource" name="throttle" value="1"/>
or use environment variables. In addition you can limit memory so that if a large image is processed its cached to disk rather than memory.
There is typically more overhead when using ImageMagick from the command-line. Instead use it from a scripting language, Perl or PHP, for example.
We have an ImageMagick web site @
http://www.imagemagick.org/MagickStudio/ that has supported thousands of image manipulations each day and the host computer is never overwhelmed. You can download the source @
http://www.imagemagick.org/download/per ... 9.3.tar.gz and see the sorts of things we do to ensure our host server runs efficiently.
Re: Is it possible to control cpu usage?
Posted: 2012-01-10T10:53:19-07:00
by agriz
I have downloaded and going to check it out.
Memory is not much used.
Only CPU is used a lot.
But i am quite confused whether it is an attack or overload which slows down the site.
Where is policy.xml file located?
/usr/bin/convert is the convert path on my computer
Re: Is it possible to control cpu usage?
Posted: 2012-01-10T10:58:18-07:00
by agriz
Also, I am using exec to process images with imagemagick.
How do i use PHP module? Do i need to install anything?
Will everything work in the same way as it is working in exec?
Re: Is it possible to control cpu usage?
Posted: 2012-01-10T12:14:19-07:00
by fmw42
I believe that exec is a PHP command, so you are likely already using PHP, but it essentially is just an interface to the command line. But Magick was suggesting that you use something like Perlmagick or MagickWand for PHP or Imagick. See the various IM APIs at
http://www.imagemagick.org/script/api.php
Re: Is it possible to control cpu usage?
Posted: 2012-01-10T12:20:43-07:00
by agriz
Using exec and imagic differs in performance?
Re: Is it possible to control cpu usage?
Posted: 2012-01-10T12:32:01-07:00
by fmw42
User Bonzo and I did some limited timing tests for command line, PHP exec and Imagick and did not find that much difference. However, I suspect that Perlmagick may be different and faster.
Our timing tests are at:
viewtopic.php?f=4&t=16779
Re: Is it possible to control cpu usage?
Posted: 2012-01-11T06:15:44-07:00
by agriz
You have done nice work!!!
Code: Select all
convert -font Ravie -pointsize 72 label:'Get Wet!' -border 10 \
-tile tile_aqua.jpg -draw "color 0,0 reset" \
-tile tile_water.jpg -gravity center -annotate +0+0 'Get Wet!' \
autosize_wet.jpg
from this page --
http://www.imagemagick.org/Usage/text/
Will it use more cpu memory than the following?
Code: Select all
convert -size 800x120 xc:black -font Corsiva -pointsize 100 \
-tile tile_disks.jpg -annotate +20+80 'Psychedelic!' \
-trim +repage -bordercolor black -border 10 funfont_groovy.jpg
I just am asking because the first one is not using any size.
Re: Is it possible to control cpu usage?
Posted: 2012-01-11T11:05:29-07:00
by fmw42
label: creates its own size image to match the pointsize and have no extra space around it. see
http://www.imagemagick.org/Usage/text/#label
Re: Is it possible to control cpu usage?
Posted: 2012-01-11T18:20:11-07:00
by anthony
The first uses label to create a canvas of about the right size. This is then cleared (tiled) and the font again re-drawn using -annotate so that we can use a tiling fill.
The other method is to just create a label using black and white only. Then use that as a composite mask operator to select different background foreground tile patterns. See... Coloring a Gray-scale Text Image
http://www.imagemagick.org/Usage/text/#coloring_text
and the sections this links to.
There are lots of ways to skin a cat, and what method you use depends
on what you want that skin for, and how messy you like the results!
-- Anthony Thyssen