views:

57

answers:

1

I have a feature in my CMS that allows a user to upload a zip file full of images and the server will extract them and insert each one into an image gallery. I've noticed that this grinds up the CPU quite severely and causes other requests to slow down.

I'm thinking of using the delayed_job plugin to delegate each image addition into the background, but I also want to give that process a lower CPU priority so that it doesn't bog down the server.

I'm pretty confident in the delaying part of the exercise, but the throttling part is where I'm stuck. Is there a ruby way of lowering the priority of a method call?

It's the image resizing that causes the CPU chew.

Any ideas welcome :)

+2  A: 

If your CMS is running on linux system, then you can do this using the "nice" command. "nice" will start a process at a lower priority. Easiest way to use it is to just put nice in front of your command. So if you were running the command like

unzip uploaded-images.zip

instead run

nice unzip uploaded-images.zip

This will cause the unzip process to get lower CPU priority, letting other processes run first. See the man page for more options, like how to adjust the priority level.

muudscope
Thanks for that, I also stumbled upon this with google: http://stackoverflow.com/questions/1340142/preventing-delayed-job-background-jobs-from-consuming-too-much-cpu-on-a-single-se
Brendon Muir