Why using cgroup can’t restrict cpu resource?

Discussion in 'Installation/Configuration' started by carate, Apr 13, 2019.

  1. carate

    carate New Member

    I want using cgroup to restrict cpu resource for per-group under CentOS 7. I have added two groups in OS, one group of them has website – web2, another group has website – web3, I follow under command line step by step.

    1. yum install libcgroup-tools
    2.In the /etc/cgconfig.conf file

    group client0 {
    cpu {
    cpu.shares="250";
    }
    cpuacct {
    cpuacct.usage="0";
    }
    memory {
    memory.limit_in_bytes="2G";
    memory.memsw.limit_in_bytes="3G";
    }
    }

    group client1 {
    cpu {
    cpu.shares="500";
    }
    cpuacct {
    cpuacct.usage="0";
    }
    memory {
    memory.limit_in_bytes="4G";
    memory.memsw.limit_in_bytes="6G";
    }
    }
    1. in the /etc/cgrules.conf file
    @client0 cpu,cpuacct,memory client0
    @client1 cpu,cpuacct,memory client1
    4.

    service cgconfig restart; service cgred restart
    5.in the cpu.sh file

    x=0
    while [ True ];do
    x=$x+1
    done;
    I testing it to use this two command line:

    sudo -u web2 sh /tmp/cpu.sh &
    sudo -u web3 sh /tmp/cpu.sh &
    It does worked, one is twice than the another. But the other way, I wrote loop code to consume cpu resource and I visiting two websites in browser, then I go to OS and type command – top, I see two line, the command row is php-fpm, the %cpu row’s value is the same, It's incorrect, should be one is twice than the another. What's wrong?
     

Share This Page