Limiting CPU on some processes on web server

Roland Smith rsmith at xs4all.nl
Wed Mar 11 19:47:42 UTC 2015


On Wed, Mar 11, 2015 at 12:26:56PM +0000, opendaddy at hushmail.com wrote:
> Hi!
>
> I run this web app that depends on ImageMagick to process images and ffmpeg
> to process videos. These processes, unfortunately, consume 100% of my CPU,
> rendering my web app unusable (gateway timeout).

*How* does the web app actually start those programs?

E.g. if the web app is written in Python, it should use subprocess.Popen()
instead of subprocess.call or subprocess.check-output(), because the latter
two would block the calling program.

As far as I can tell, ImageMagick only uses one core.  And whether ffmepg can
use multiple cores depends on the encoder. X264 can use multiple cores, but
Theora can´t.
So on a relatively modern (multi-core) CPU launching one or two CPU intensive
programs should leave enough cores for your web-app.

> Tried `nice -n 19` but to no avail.

Have you verified with `ps -l` (or `ps -xal`) that the ffmeg and convert
processes are actually running at a lower priority?

Try using /usr/bin/nice directly instead of using the shell's built-in nice (assuming the web app starts the commands from a shell?).

> What other options do I have?

Run you web app stack with a higher priority.

Roland
-- 
R.F.Smith                                   http://rsmith.home.xs4all.nl/
[plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
pgp: 5753 3324 1661 B0FE 8D93  FCED 40F6 D5DC A38A 33E0 (keyID: A38A33E0)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20150311/dbcba876/attachment.sig>


More information about the freebsd-questions mailing list