MRatWork Forum by Mustafa Ramadhan

Sawo Project - Kloxo-MR Discussions => Kloxo-MR Tips and Tricks => Topic started by: lupetalo on 2012-12-28, 04:30:24

Title: Php-fpm
Post by: lupetalo on 2012-12-28, 04:30:24
What is optimal template for using with large number of users (150+)? My memory always get swamped and all domains are always using some part of it...
Title: Re: Php-fpm
Post by: MRatWork on 2012-12-28, 19:01:33
Better use small users (with large domains) rather than large users (with small domains).

It's because (by default) php-fpm refer to user rather than to global or domains.

You can see setting for every user inside /etc/php-fpm.d
Title: Re: Php-fpm
Post by: lupetalo on 2012-12-28, 19:08:33
I know that, but question is how to optimise current situation :)
I tried lowering:
Code: [Select]
pm.max_requests = 200but it not help a lot...
Is it possible to kill those process that are not active but taking memory? I only have ~20 regulary active users at all times.
Title: Re: Php-fpm
Post by: MRatWork on 2012-12-28, 19:19:01
This is example for my modified for /home/php-fpm/tpl/custom.php53-fpm-pool.conf.tpl
Code: [Select]
<?php
    $userinfo 
posix_getpwnam($user);

    if (
$userinfo) {
        
$fpmport = (50000 $userinfo['uid']);
    } else {
        return 
false;
    }

    if (
$user == 'apache') {
        
$pool 'default';
    } else {
        
$pool $user;
    }

    if (
$user === 'riginta') {
        
$startserver '20';
        
$minspareserver '20';
        
$maxspareserver '40';
        
$maxchildren '200';
    } else {
        
$startserver '2';
        
$minspareserver '2';
        
$maxspareserver '4';
        
$maxchildren '10';
    }


?>

[<?php echo $pool?>]
listen = 127.0.0.1:<?php echo $fpmport?>

listen.backlog = -1
listen.allowed_clients = 127.0.0.1
user = <?php echo $user?>

group = <?php echo $user?>

pm = dynamic
pm.max_children = <?php echo $maxchildren?>

pm.start_servers = <?php echo $startserver?>

pm.min_spare_servers = <?php echo $minspareserver?>

pm.max_spare_servers = <?php echo $maxspareserver?>

pm.max_requests = 500
;pm.status_path = /status
;ping.path = /ping
;ping.response = pong
request_terminate_timeout = 0
request_slowlog_timeout = 0
slowlog = /var/log/php-fpm/slow.log
rlimit_files = 1024
rlimit_core = 0
;chroot =
;chdir = /var/www
catch_workers_output = yes
security.limit_extensions = .php .php3 .php4 .php5

env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f webmaster@domain.com
;php_flag[display_errors] = off
php_admin_value[error_log] = /var/log/php-fpm/error.log
php_admin_value[session.save_path] = /var/lib/php/session
php_admin_flag[log_errors] = on
php_admin_value[memory_limit] = 64M

Title: Re: Php-fpm
Post by: lupetalo on 2012-12-28, 19:39:07
Can you please tell mi what is changed and will it kill not active processes?
Title: Re: Php-fpm
Post by: lupetalo on 2012-12-28, 19:57:33
That did opposite, memory fills in just few minutes, every process for every user is takeni even more memory....
1.4% of memory or 152.52 Mb per user, that is too much....
Title: Re: Php-fpm
Post by: MRatWork on 2012-12-28, 21:32:38
You can try something like:
Code: [Select]
       $startserver = '2';
        $minspareserver = '2';
        $maxspareserver = '4';
        $maxchildren = '4';
Title: Re: Php-fpm
Post by: lupetalo on 2013-01-10, 15:23:53
Ended up with creating script which checks for free memory and if below 200mb restart php-fpm. Takes 2 sec and it is not noticable a lot. But for two weeks on two occasions restart did not worked without any real reason. service php-fpm restart did not kill all php-fpm processes.