不错,ionice是不够的

我有一个脚本,启动大,CPU和内存消耗进程树。 在那里有Python和可执行文件,但是所有东西都以单个bash脚本和pythonsubprocess开始。

在执行过程中,系统的其余部分完全堵塞。 我试图通过$ nice -n10 ionice -c2 ./Script.sh来减轻$ nice -n10 ionice -c2 ./Script.sh ,但是这还不够 – 使用计算机非常滞后(这是开发桌面,但是在指定的服务器上的问题将是相同的)。

我怀疑,问题是使用了很多内存的进程 – 一切都结束了交换,变得呆滞。

有没有办法降低一个进程(及其recursion子)在访问物理内存时的优先级? 我更喜欢在后台执行速度较慢,对其他任务的影响有限。

你不能限制使用内存的“速度”,但是你可以通过各种不同的机制来限制它的总内存使用量。

1)安全限制通过/etc/security/limits.conf限制运行进程的用户的内存使用情况。 如果您正在以不同的方式工作的同一用户运行此过程,这可能无法正常工作。

例:

 username hard as 1000000 

2)控制组您可以使用cgroup创build一个组,并限制内存的使用。 只需创buildcgroup,如下所示:

 # cat >> /etc/cgconfig.conf << EOF group memlimit { memory { memory.limit_in_bytes = 1073741824; } } EOF # cat >> /etc/cgrules.conf <<EOF username memory memlimit/ EOF 

Offcourse – 在这两种情况下,你必须开发你的程序,以便它可以从没有分配更多的内存中恢复。

如果不行的话,你只需要增加更多的内存到系统中,这样就可以避免交换。 一旦交换开始,它就在内核的手中,你不能 – 例如 – 降低kswapd的优先级,即使你可以 – 也不能保证你使用的某些程序不会被交换从而导致系统响应速度更慢。 只是不要去那里。

虽然下一个将不会帮助你在内存交换,它应该帮助你在你的过程的IO影响。

看来你也应该明确地设定这个level

 ionice -c2 -n5 ./slowscript.sh 

单靠C2可能还不够,这取决于你的内核。

从联机帮助中findQoute( man ionice

  Note that before kernel 2.6.26 a process that has not asked for an I/O priority formally uses "none" as scheduling class, but the I/O scheduler will treat such processes as if it were in the best-effort class. The priority within the best-effort class will be dynamically derived from the CPU nice level of the process: io_priority = (cpu_nice + 20) / 5. For kernels after 2.6.26 with the CFQ I/O scheduler, a process that has not asked for an I/O priority inherits its CPU scheduling class. The I/O priority is derived from the CPU nice level of the process (same as before kernel 2.6.26). 

基本上:每个新启动的进程都会得到C2 N4,所以当你想把IO降到尽可能低的时候,或者只是空闲(C3)或者C2 N7。