2

This is the situation:

I have a PHP/MySQL web application that does some PDF processing and thumbnail creation. This is done by using some 3rd party command line software on the server. Both kinds of processing consume a lot of resources, to the point of choking the server. I would like to limit the amount of resources these applications can use in order to enable the server to keep serving users without too much delay, because now when some heavy PDF is processed my users don't get any response.

Is it possible to constrain the amount of RAM and CPU an application can use (all processes combined)? Or is there another way to deal with these kinds of situations? How is this usually done?

2 Answers 2

4

Run it with nice -n 20 ionice -c 3

That will make it use the remaining CPU cycles and access to I/O not used by other processes.

For RAM, all you can do is kill the process when it uses more than the amount you want it to use (using ulimit).

3
  • And is it possible to do this when starting the process from php? Or to config this somewhere so the applications I'm using always execute using nice? Killing RAM sounds like it can cause errors in the process? Commented Aug 29, 2012 at 11:12
  • @JeroenMoons It's not about "killing RAM", it's about killing the process. Commented Aug 29, 2012 at 13:18
  • Ahhh ok, big difference :) Commented Aug 29, 2012 at 13:20
0

You can run it from php, but ionice needs to be run as root, so either use sudo to run the ionice or run that php script(s) under a server process that was run with ionice.

If you use fastcgi you could have two different engines running and give the high resources work to the lower priority one.

If you use Apache without fastcgi, you'll have to use sudo to run the command, make sure to make the sudo permission as specific as possible, otherwise you're risking a security breach.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.