Limiting threads of ImageMagick - not getting limited

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?".
Post Reply
ramontayag
Posts: 5
Joined: 2011-10-09T07:13:31-07:00
Authentication code: 8675308

Limiting threads of ImageMagick - not getting limited

Post by ramontayag »

I'm on a virtual machine, and according to [this document in the Cache Storage and Resource Requirements section (http://www.imagemagick.org/script/architecture.php), if you're on a VPS you should probably limit the threads to two. I am. But before making changes, I checked to see what my settings (via `identify -list resource`) were:

Code: Select all

    File        Area      Memory         Map        Disk  Thread        Time
    ------------------------------------------------------------------------
     768   2.0004GiB   1.5003GiB   4.0009GiB       16EiB       4   unlimited
I then placed this in ~/.magick/policy.xml:

Code: Select all

    <policymap>
      <policy domain="resource" name="time" value="60"/>
      <policy domain="resource" name="thread" value="2"/>
    </policymap>
Then I checked my settings:

Code: Select all

    File        Area      Memory         Map        Disk  Thread        Time
    ------------------------------------------------------------------------
     768   2.0004GiB   1.5003GiB   4.0009GiB       16EiB       4          60
Howcome the thread isn't getting modified? I just copied and pasted the settings.

Note, I also asked this at http://superuser.com/questions/343648/l ... ng-limited but haven't gotten an answer :)
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Limiting threads of ImageMagick - not getting limited

Post by magick »

We got the expected results when we limited the threads in ~/.magick/policy.xml. We're using ImageMagick 6.7.2-10. You can also try setting OMP_NUM_THREADS or MAGICK_THREADS environment variable.
ramontayag
Posts: 5
Joined: 2011-10-09T07:13:31-07:00
Authentication code: 8675308

Re: Limiting threads of ImageMagick - not getting limited

Post by ramontayag »

magick wrote:We got the expected results when we limited the threads in ~/.magick/policy.xml. We're using ImageMagick 6.7.2-10. You can also try setting OMP_NUM_THREADS or MAGICK_THREADS environment variable.
Sorry for my ignorance, but I can't seem to find any document that specifies where I should set these variables. I've searched on Google and skimmed through documents on imagemagick.org. Could you point me to the right direction?

Thanks
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Limiting threads of ImageMagick - not getting limited

Post by magick »

These are environment variables, setting depends on your shell. Bash for example,
  • export OMP_NUM_THREADS=2
ramontayag
Posts: 5
Joined: 2011-10-09T07:13:31-07:00
Authentication code: 8675308

Re: Limiting threads of ImageMagick - not getting limited

Post by ramontayag »

Thank you!
ramontayag
Posts: 5
Joined: 2011-10-09T07:13:31-07:00
Authentication code: 8675308

Re: Limiting threads of ImageMagick - not getting limited

Post by ramontayag »

Hmm.. when I have these settings:

Code: Select all

File         Area       Memory          Map         Disk    Thread         Time
-------------------------------------------------------------------------------
 768     2.1479GB    1.0002GiB    2.0004GiB    unlimited         1           60
But in htop I still found two convert processes: http://is.gd/TQxAb0

Did I understand the threads parameter wrongly? How do I limit the number of convert calls that exist at a time?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Limiting threads of ImageMagick - not getting limited

Post by anthony »

Threads are not processes.

Each convert command has no knowledge of any other convert process that may be running on the system.
That is just the way UNIX and other computer system work, and is known as segmented architecture.

To limit the total number of convert command, you have to basically not run that many convert commands!
That requires some IPC communications between your launching applications.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
ramontayag
Posts: 5
Joined: 2011-10-09T07:13:31-07:00
Authentication code: 8675308

Re: Limiting threads of ImageMagick - not getting limited

Post by ramontayag »

You're absolutely right. I got confused after leaving this topic for several weeks. I'm back to my original problem then (which I thought limiting the threads would solve): http://serverfault.com/questions/313915 ... n-too-long

These commands are called but then they get stuck, and then just take up memory. Looks like I'll need to handle them manually.
Post Reply