MRatWork Forum by Mustafa Ramadhan

Sawo Project - Kloxo-MR Discussions => Kloxo-MR Development => Topic started by: Spacedust on 2014-02-17, 21:06:24

Title: Limit CPU usage per each php-fpm instance
Post by: Spacedust on 2014-02-17, 21:06:24
Is this possible ?

We have some customers using more than 300% of 8 threads :/
Title: Re: Limit CPU usage per each php-fpm instance
Post by: insanity on 2014-02-17, 21:38:45
Use cgroups and create group only for these clients.
We use it for apache, because sometimes apache use more than 600% cpu and everything freeze...
Title: Re: Limit CPU usage per each php-fpm instance
Post by: Spacedust on 2014-02-17, 23:36:10
Use cgroups and create group only for these clients.
We use it for apache, because sometimes apache use more than 600% cpu and everything freeze...

I use some anti overload scripts when load is getting too high ex. 70 or more than apache and all php-fpm processes are killed to prevent server freeze :) I leave it on screen to check each second.
Title: Re: Limit CPU usage per each php-fpm instance
Post by: insanity on 2014-02-17, 23:46:37
:D If we kill apache and fpm all customers will start call us :D
Thats why we use cgroups for all these process. eg, Apache, nginx, qmail, fpm, mysql
Yes sometimes its slower than usual but it is stable.
Title: Re: Limit CPU usage per each php-fpm instance
Post by: chrisf on 2014-02-18, 07:44:20
@insanity, could you give a detailed description on how to setup cgroups for Apache, or whatever process, how to add users to that group, etc.
Title: Re: Limit CPU usage per each php-fpm instance
Post by: fossxplorer on 2014-02-18, 09:47:25
Yes, i would be interested to test out resource limiting by cgroups as well.
IIRC, cgroups is indeed used by LInux containers :)
Title: Re: Limit CPU usage per each php-fpm instance
Post by: Spacedust on 2014-02-18, 12:54:56
He is using probably CloudLinux which I hate.
Title: Re: Limit CPU usage per each php-fpm instance
Post by: MRatWork on 2014-02-18, 13:41:55
What about https://www.rfxn.com/projects/system-priority/ ?. Look like very simple.
Title: Re: Limit CPU usage per each php-fpm instance
Post by: insanity on 2014-02-18, 16:24:18
Actually i'm not using cloudlinux. Only cgroups

Its simple. Install cgroups: yum install libcgroup

Here is my limit for apache:
/etc/cgconfig.conf
Code: [Select]
mount {
cpuset = /cgroup/cpuset;
cpu = /cgroup/cpu;
cpuacct = /cgroup/cpuacct;
}
group apache {
cpu {
cpu.cfs_quota_us="25000";
cpu.cfs_period_us="10000";
}
cpuacct {
cpuacct.usage="0";
}
cpuset {
cpuset.cpus="0,1,2,3,4,5,6,7";
}
}

/etc/cgrules.conf
Code: [Select]
apache cpu,cpuacct,cpuset apache/

Code: [Select]
/etc/init.d/cgconfig start
/etc/init.d/cgred start

This conf limit my apache at 250% and allow to use 8 cpu cores
Title: Re: Limit CPU usage per each php-fpm instance
Post by: Spacedust on 2014-02-18, 16:59:01
Good idea, but I think it's a bit useless. I do not wan't to limit Apache itself but to lock some users from hogging all my CPU power.