在后台运行任务,CPU优先级较低

时间:2023-02-05 20:34:43

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.

我的CMS中有一个功能,允许用户上传一个包含图像的zip文件,服务器将提取它们并将每个文件插入图像库。我注意到这会严重影响CPU并导致其他请求减慢。

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.

我正在考虑使用delayed_job插件将每个图像添加委托给后台,但我也想让该进程具有较低的CPU优先级,这样它就不会让服务器陷入困境。

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.

这是调整大小导致CPU咀嚼的图像。

Any ideas welcome :)

欢迎任何想法:)

1 个解决方案

#1


6  

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

如果您的CMS在Linux系统上运行,那么您可以使用“nice”命令执行此操作。 “nice”将以较低优先级启动进程。最简单的使用方法就是在你的命令面前放好。所以如果你正在运行这样的命令

unzip uploaded-images.zip

instead run

nice unzip uploaded-images.zip

很好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.

这将导致解压缩进程获得较低的CPU优先级,让其他进程先运行。有关更多选项的信息,请参见手册页,例如如何调整优先级。

#1


6  

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

如果您的CMS在Linux系统上运行,那么您可以使用“nice”命令执行此操作。 “nice”将以较低优先级启动进程。最简单的使用方法就是在你的命令面前放好。所以如果你正在运行这样的命令

unzip uploaded-images.zip

instead run

nice unzip uploaded-images.zip

很好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.

这将导致解压缩进程获得较低的CPU优先级,让其他进程先运行。有关更多选项的信息,请参见手册页,例如如何调整优先级。