How To Limit Cpu Usage For Specified Processes

Home » CentOS » How To Limit Cpu Usage For Specified Processes
CentOS 2 Comments


Is there some tool or method in CentOS that can limit cpu usage to some percentage for specified processes that consume large cpu resource?

I found cpulimit which is only able to limit one process. what I want is one tool that can limit several same processes’ cpu usage. Thanks!



2 thoughts on - How To Limit Cpu Usage For Specified Processes

  • hello, In the past I mainly used blkio controller in control groups, to limit disk I/O bandwidth of a process. Just to notice that the cpu controller also has the cfs_quota_us and cfs_period_us which can provide absolute limits, in respect with relative ones of the shares parameter. In Red Hat manual I only see the shares parameter, but you can find more info about the other two installing kernel-doc package and reading

    A rapid test on a CentOS 6.5 system with 2 physical cpus, 8 cores each and HT enabled

    yum install libcgroup

    service start cgconfig

    cgcreate -g cpu:/half_cpu

    echo “2000” > /cgroup/cpu/half_cpu/cpu.cfs_quota_us echo “4000” > /cgroup/cpu/half_cpu/cpu.cfs_period_us

    You can tune latency/burst working on period value… see the doc I use a program that makes matrix multiplication (1024×1024 in example below) and fully uses one cpu

    ./bmm 1024
    elapsed 10 seconds using top during execution I see line detail of this type around the 32
    Cpu18 :100.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si,

    cgexec -g cpu:half_cpu ./bmm 1024
    elapsed 20 seconds using top I see line detail of this type during execution:
    Cpu0 : 49.8%us, 0.0%sy, 0.0%ni, 50.2%id, 0.0%wa, 0.0%hi, 0.0%si,

    HIH, Gianluca