Sponsor:

Server and Web Integrator
Link:
Kloxo-MR logo
6.5.0 or 7.0.0
Click for "How to install"
Donation/Sponsorship:
Kloxo-MR is open-source.
Donate and or Sponsorship always welcome.
Click to:
Click Here
Please login or register. 2024-04-29, 01:35:33

Author Topic: Limit CPU usage per each php-fpm instance  (Read 8185 times)

0 Members and 1 Guest are viewing this topic.

Offline Spacedust

  • Super Grand Master
  • ****
  • Posts: 4,050
  • Karma: +1/-0
    • View Profile
Limit CPU usage per each php-fpm instance
« on: 2014-02-17, 21:06:24 »
Is this possible ?

We have some customers using more than 300% of 8 threads :/

Offline insanity

  • Senior Member
  • *
  • Posts: 215
  • Karma: +0/-0
    • View Profile
Re: Limit CPU usage per each php-fpm instance
« Reply #1 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...

Offline Spacedust

  • Super Grand Master
  • ****
  • Posts: 4,050
  • Karma: +1/-0
    • View Profile
Re: Limit CPU usage per each php-fpm instance
« Reply #2 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.

Offline insanity

  • Senior Member
  • *
  • Posts: 215
  • Karma: +0/-0
    • View Profile
Re: Limit CPU usage per each php-fpm instance
« Reply #3 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.

Offline chrisf

  • Senior Master
  • **
  • Posts: 883
  • Karma: +11/-1
  • Gender: Male
  • Be the change that you wish to see in the world.
    • View Profile
    • Conviction's Hosting
Re: Limit CPU usage per each php-fpm instance
« Reply #4 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.
Christopher

Knowledge in: PHP, Perl, MySQL, Javascript, Actionscript, FLASH, HTML, CSS
Server Administrator / Developer: https://convictionshosting.com

Offline fossxplorer

  • Master
  • **
  • Posts: 640
  • Karma: +1/-0
    • View Profile
Re: Limit CPU usage per each php-fpm instance
« Reply #5 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 :)
Kloxo-MR!

Offline Spacedust

  • Super Grand Master
  • ****
  • Posts: 4,050
  • Karma: +1/-0
    • View Profile
Re: Limit CPU usage per each php-fpm instance
« Reply #6 on: 2014-02-18, 12:54:56 »
He is using probably CloudLinux which I hate.

Offline MRatWork

  • Administrator
  • The Elite
  • *****
  • Posts: 15,807
  • Karma: +119/-11
  • Gender: Male
    • View Profile
    • MRatWork Forum
Re: Limit CPU usage per each php-fpm instance
« Reply #7 on: 2014-02-18, 13:41:55 »
What about https://www.rfxn.com/projects/system-priority/ ?. Look like very simple.
..:: MRatWork (Mustafa Ramadhan Projects) ::..
-- Server/Web-integrator - Web Hosting (Kloxo-MR READY!) --

Offline insanity

  • Senior Member
  • *
  • Posts: 215
  • Karma: +0/-0
    • View Profile
Re: Limit CPU usage per each php-fpm instance
« Reply #8 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

Offline Spacedust

  • Super Grand Master
  • ****
  • Posts: 4,050
  • Karma: +1/-0
    • View Profile
Re: Limit CPU usage per each php-fpm instance
« Reply #9 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.

 


Top 4 Global Search Engines:    Google    Bing    Baidu    Yahoo
Click Here

Page created in 0.054 seconds with 19 queries.

web stats analysis