fat                                      Sun, 17 Jul 2011 11:41:57 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=313323

Log:
- Implemented FR #55166 (Added process.max to control the number of process FPM 
can fork)

Bug: https://bugs.php.net/55166 (Assigned) Implement a global limit to the 
overall number of php processes
      
Changed paths:
    U   php/php-src/branches/PHP_5_4/NEWS
    U   php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm.h
    U   php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_children.c
    U   php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_conf.c
    U   php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_conf.h
    U   php/php-src/branches/PHP_5_4/sapi/fpm/php-fpm.conf.in

Modified: php/php-src/branches/PHP_5_4/NEWS
===================================================================
--- php/php-src/branches/PHP_5_4/NEWS   2011-07-17 10:49:25 UTC (rev 313322)
+++ php/php-src/branches/PHP_5_4/NEWS   2011-07-17 11:41:57 UTC (rev 313323)
@@ -1,6 +1,9 @@
 PHP                                                                        
NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2011, PHP 5.4.0 Alpha 3
+- Improved PHP-FPM SAPI:
+  . Added process.max to control the number of process FPM can fork. FR #55166.
+    (fat)

 14 Jul 2011, PHP 5.4.0 Alpha 2
 - General improvements:

Modified: php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm.h
===================================================================
--- php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm.h     2011-07-17 10:49:25 UTC 
(rev 313322)
+++ php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm.h     2011-07-17 11:41:57 UTC 
(rev 313323)
@@ -24,6 +24,7 @@
        int max_requests; /* for this child */
        int is_child;
        int test_successful;
+       int process_max; /* global */
 };

 extern struct fpm_globals_s fpm_globals;

Modified: php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_children.c
===================================================================
--- php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_children.c    2011-07-17 
10:49:25 UTC (rev 313322)
+++ php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_children.c    2011-07-17 
11:41:57 UTC (rev 313323)
@@ -363,6 +363,7 @@
        pid_t pid;
        struct fpm_child_s *child;
        int max;
+       static int warned = 0;

        if (wp->config->pm == PM_STYLE_DYNAMIC) {
                if (!in_event_loop) { /* starting */
@@ -374,7 +375,9 @@
                max = wp->config->pm_max_children;
        }

-       while (fpm_pctl_can_spawn_children() && wp->running_children < max) {
+       while (fpm_pctl_can_spawn_children() && wp->running_children < max && 
fpm_globals.running_children < fpm_global_config.process_max) {
+
+               warned = 0;
                child = fpm_resources_prepare(wp);

                if (!child) {
@@ -407,6 +410,11 @@

        }

+       if (!warned && fpm_globals.running_children >= 
fpm_global_config.process_max) {
+               warned = 1;
+               zlog(ZLOG_WARNING, "The maximum number of processes has been 
reached. Please review your configuration and consider raising 'process.max'");
+       }
+
        return 1; /* we are done */
 }
 /* }}} */

Modified: php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_conf.c
===================================================================
--- php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_conf.c        2011-07-17 
10:49:25 UTC (rev 313322)
+++ php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_conf.c        2011-07-17 
11:41:57 UTC (rev 313323)
@@ -66,8 +66,9 @@
 struct fpm_global_config_s fpm_global_config = {
        .daemonize = 1,
 #ifdef HAVE_SYSLOG_H
-       .syslog_facility = -1
+       .syslog_facility = -1,
 #endif
+       .process_max = 0,
 };
 static struct fpm_worker_pool_s *current_wp = NULL;
 static int ini_recursion = 0;
@@ -79,6 +80,7 @@
        { "emergency_restart_threshold", &fpm_conf_set_integer,         
GO(emergency_restart_threshold) },
        { "emergency_restart_interval",  &fpm_conf_set_time,            
GO(emergency_restart_interval) },
        { "process_control_timeout",     &fpm_conf_set_time,            
GO(process_control_timeout) },
+       { "process.max",                 &fpm_conf_set_integer,         
GO(process_max) },
        { "daemonize",                   &fpm_conf_set_boolean,         
GO(daemonize) },
        { "pid",                         &fpm_conf_set_string,          
GO(pid_file) },
        { "error_log",                   &fpm_conf_set_string,          
GO(error_log) },
@@ -1014,6 +1016,12 @@

        fpm_globals.log_level = fpm_global_config.log_level;

+       if (fpm_global_config.process_max < 0) {
+               zlog(ZLOG_ERROR, "process_max can't be negative");
+               return -1;
+       }
+       fpm_globals.process_max = fpm_global_config.process_max;
+
        if (!fpm_global_config.error_log) {
                fpm_global_config.error_log = strdup("log/php-fpm.log");
        }
@@ -1394,6 +1402,7 @@
        zlog(ZLOG_NOTICE, "\tsyslog.facility = %d",             
fpm_global_config.syslog_facility); /* FIXME: convert to string */
 #endif
        zlog(ZLOG_NOTICE, "\tprocess_control_timeout = %ds",    
fpm_global_config.process_control_timeout);
+       zlog(ZLOG_NOTICE, "\tprocess.max = %d",                 
fpm_global_config.process_max);
        zlog(ZLOG_NOTICE, "\temergency_restart_interval = %ds", 
fpm_global_config.emergency_restart_interval);
        zlog(ZLOG_NOTICE, "\temergency_restart_threshold = %d", 
fpm_global_config.emergency_restart_threshold);
        zlog(ZLOG_NOTICE, "\trlimit_files = %d",                
fpm_global_config.rlimit_files);

Modified: php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_conf.h
===================================================================
--- php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_conf.h        2011-07-17 
10:49:25 UTC (rev 313322)
+++ php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_conf.h        2011-07-17 
11:41:57 UTC (rev 313323)
@@ -32,6 +32,7 @@
 #endif
        int rlimit_files;
        int rlimit_core;
+       int process_max;
 };

 extern struct fpm_global_config_s fpm_global_config;

Modified: php/php-src/branches/PHP_5_4/sapi/fpm/php-fpm.conf.in
===================================================================
--- php/php-src/branches/PHP_5_4/sapi/fpm/php-fpm.conf.in       2011-07-17 
10:49:25 UTC (rev 313322)
+++ php/php-src/branches/PHP_5_4/sapi/fpm/php-fpm.conf.in       2011-07-17 
11:41:57 UTC (rev 313323)
@@ -69,6 +69,13 @@
 ; Default Value: 0
 ;process_control_timeout = 0

+; The maximum number of processes FPM will fork. This has been design to 
control
+; the global number of processes when using dynamic PM within a lot of pools.
+; Use it with caution.
+; Note: A value of 0 indicates no limit
+; Default Value: 0
+; process.max = 128
+
 ; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging.
 ; Default Value: yes
 ;daemonize = yes

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to