限制Imagemagick使用的空间和内存 [英] Limit space and memory used by Imagemagick

查看:243
本文介绍了限制Imagemagick使用的空间和内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Rails应用程序(带有rmagick)上使用了Imagemagick,但是我的服务器(Ubuntu)不是很大,当我启动转换过程时,Imagemagick占据了服务器的所有位置/内存(30GB硬盘).

I'm used Imagemagick on a rails application (with rmagick) but my server (Ubuntu) it's not very big and when i launch my convert process Imagemagick take all place/memory of my server (30GB HDD).

我想限制内存和tmp文件的大小,我该怎么办?

I would like limit the memory and the tmp file size, how can i do it ?

推荐答案

尝试运行命令

identify -list resource

查看可以控制/限制的资源.它给出了这个:

to see the resources you can control/limit. It gives this:

Resource limits:
  Width: 214.7MP
  Height: 214.7MP
  Area: 4.295GP
  Memory: 2GiB       <--- Default is 2 GiB
  Map: 4GiB
  Disk: unlimited
  File: 1920
  Thread: 1
  Throttle: 0
  Time: unlimited

然后您可以对convertidentifymogrify

identify -limit memory 1GiB -list resource
Resource limits:
  Width: 214.7MP
  Height: 214.7MP
  Area: 4.295GP
  Memory: 1GiB         <--- 1 GiB for duration of this command
  Map: 4GiB
  Disk: unlimited
  File: 1920
  Thread: 1
  Throttle: 0
  Time: unlimited

因此,如您在上面看到的,我将一个命令的内存限制为1GB.

So, as you can see above, I limited memory to 1GB for the one command.

同样,您可以通过

限制convert的内存

Equally, you can limit memory for convert with

convert -limit memory 1GiB -size ... file.png

您还可以在环境变量单次设置中设置内存限制,如下所示:

You can also set the memory limit in an environment variable, single-shot, like this:

MAGICK_MEMORY_LIMIT=30000 identify -list resource
Resource limits:
  Width: 214.7MP
  Height: 214.7MP
  Area: 4.295GP
  Memory: 29.3KiB
  Map: 4GiB
  Disk: unlimited
  File: 1920
  Thread: 1
  Throttle: 0
  Time: unlimited

或在其余的会话中这样:

or like this for the rest of the session:

export MAGICK_MEMORY_LIMIT=500000
identify -list resource

Resource limits:
  Width: 214.7MP
  Height: 214.7MP
  Area: 4.295GP
  Memory: 488KiB
  Map: 4GiB
  Disk: unlimited
  File: 1920
  Thread: 1
  Throttle: 0
  Time: unlimited

库尔特(Kurt)在此处也提供了一些很好的建议.

Kurt also offers some great advice here.

这篇关于限制Imagemagick使用的空间和内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆