fat                                      Sun, 09 Oct 2011 15:12:26 +0000

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

Log:
- Fixed bug #55526 (Heartbeat causes a lot of unnecessary events)

Bug: https://bugs.php.net/55526 (Analyzed) Heartbeat causes a lot of 
unnecessary events
      
Changed paths:
    U   php/php-src/branches/PHP_5_3/NEWS
    U   php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm.c
    U   php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm.h
    U   php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm_conf.c
    U   php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm_events.c
    U   php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm_process_ctl.c
    U   php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm_process_ctl.h
    U   php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm.c
    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_conf.c
    U   php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_events.c
    U   php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_process_ctl.c
    U   php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_process_ctl.h
    U   php/php-src/trunk/sapi/fpm/fpm/fpm.c
    U   php/php-src/trunk/sapi/fpm/fpm/fpm.h
    U   php/php-src/trunk/sapi/fpm/fpm/fpm_conf.c
    U   php/php-src/trunk/sapi/fpm/fpm/fpm_events.c
    U   php/php-src/trunk/sapi/fpm/fpm/fpm_process_ctl.c
    U   php/php-src/trunk/sapi/fpm/fpm/fpm_process_ctl.h

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS	2011-10-09 14:36:11 UTC (rev 317936)
+++ php/php-src/branches/PHP_5_3/NEWS	2011-10-09 15:12:26 UTC (rev 317937)
@@ -75,6 +75,7 @@
   . Fixed bug #53872 (internal corruption of phar). (Hannes)

 - PHP-FPM SAPI:
+  . Fixed bug #55526 (Heartbeat causes a lot of unnecessary events). (fat)
   . Fixed bug #55533 (The -d parameter doesn't work). (fat)
   . Implemented FR #52569 (Add the "ondemand" process-manager
     to allow zero children). (fat)

Modified: php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm.c
===================================================================
--- php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm.c	2011-10-09 14:36:11 UTC (rev 317936)
+++ php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm.c	2011-10-09 15:12:26 UTC (rev 317937)
@@ -36,7 +36,8 @@
 	.listening_socket = 0,
 	.max_requests = 0,
 	.is_child = 0,
-	.test_successful = 0
+	.test_successful = 0,
+	.heartbeat = 0
 };

 int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf) /* {{{ */

Modified: php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm.h
===================================================================
--- php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm.h	2011-10-09 14:36:11 UTC (rev 317936)
+++ php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm.h	2011-10-09 15:12:26 UTC (rev 317937)
@@ -24,6 +24,7 @@
 	int max_requests; /* for this child */
 	int is_child;
 	int test_successful;
+	int heartbeat;
 };

 extern struct fpm_globals_s fpm_globals;

Modified: php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm_conf.c
===================================================================
--- php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm_conf.c	2011-10-09 14:36:11 UTC (rev 317936)
+++ php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm_conf.c	2011-10-09 15:12:26 UTC (rev 317937)
@@ -878,6 +878,10 @@
 			}
 		}

+		if (wp->config->request_terminate_timeout) {
+			fpm_globals.heartbeat = fpm_globals.heartbeat ? MIN(fpm_globals.heartbeat, (wp->config->request_terminate_timeout * 1000) / 3) : (wp->config->request_terminate_timeout * 1000) / 3;
+		}
+
 		/* slowlog */
 		if (wp->config->slowlog && *wp->config->slowlog) {
 			fpm_evaluate_full_path(&wp->config->slowlog, wp, NULL, 0);
@@ -912,6 +916,8 @@
 				}
 				close(fd);
 			}
+
+			fpm_globals.heartbeat = fpm_globals.heartbeat ? MIN(fpm_globals.heartbeat, (wp->config->request_slowlog_timeout * 1000) / 3) : (wp->config->request_slowlog_timeout * 1000) / 3;
 		}

 		/* chroot */

Modified: php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm_events.c
===================================================================
--- php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm_events.c	2011-10-09 14:36:11 UTC (rev 317936)
+++ php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm_events.c	2011-10-09 15:12:26 UTC (rev 317937)
@@ -350,7 +350,9 @@
 	fpm_event_add(&signal_fd_event, 0);

 	/* add timers */
-	fpm_pctl_heartbeat(NULL, 0, NULL);
+	if (fpm_globals.heartbeat > 0) {
+		fpm_pctl_heartbeat(NULL, 0, NULL);
+	}

 	if (!err) {
 		fpm_pctl_perform_idle_server_maintenance_heartbeat(NULL, 0, NULL);

Modified: php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm_process_ctl.c
===================================================================
--- php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm_process_ctl.c	2011-10-09 14:36:11 UTC (rev 317936)
+++ php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm_process_ctl.c	2011-10-09 15:12:26 UTC (rev 317937)
@@ -453,9 +453,13 @@
 		return;
 	}

+	/* ensure heartbeat is not lower than FPM_PCTL_MIN_HEARTBEAT */
+	fpm_globals.heartbeat = MAX(fpm_globals.heartbeat, FPM_PCTL_MIN_HEARTBEAT);
+
 	/* first call without setting to initialize the timer */
+	zlog(ZLOG_DEBUG, "heartbeat have been set up with a timeout of %dms", fpm_globals.heartbeat);
 	fpm_event_set_timer(&heartbeat, FPM_EV_PERSIST, &fpm_pctl_heartbeat, NULL);
-	fpm_event_add(&heartbeat, FPM_PCTL_HEARTBEAT);
+	fpm_event_add(&heartbeat, fpm_globals.heartbeat);
 }
 /* }}} */


Modified: php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm_process_ctl.h
===================================================================
--- php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm_process_ctl.h	2011-10-09 14:36:11 UTC (rev 317936)
+++ php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm_process_ctl.h	2011-10-09 15:12:26 UTC (rev 317937)
@@ -11,9 +11,10 @@
 #define FPM_MAX_SPAWN_RATE (32)
 /* 1s (in ms) heartbeat for idle server maintenance */
 #define FPM_IDLE_SERVER_MAINTENANCE_HEARTBEAT (1000)
-/* 130ms heartbeat for pctl */
-#define FPM_PCTL_HEARTBEAT (130)
+/* a minimum of 130ms heartbeat for pctl */
+#define FPM_PCTL_MIN_HEARTBEAT (130)

+
 struct fpm_child_s;

 void fpm_pctl(int new_state, int action);

Modified: php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm.c
===================================================================
--- php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm.c	2011-10-09 14:36:11 UTC (rev 317936)
+++ php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm.c	2011-10-09 15:12:26 UTC (rev 317937)
@@ -36,7 +36,8 @@
 	.listening_socket = 0,
 	.max_requests = 0,
 	.is_child = 0,
-	.test_successful = 0
+	.test_successful = 0,
+	.heartbeat = 0
 };

 int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf) /* {{{ */

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-10-09 14:36:11 UTC (rev 317936)
+++ php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm.h	2011-10-09 15:12:26 UTC (rev 317937)
@@ -24,6 +24,7 @@
 	int max_requests; /* for this child */
 	int is_child;
 	int test_successful;
+	int heartbeat;
 };

 extern struct fpm_globals_s fpm_globals;

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-10-09 14:36:11 UTC (rev 317936)
+++ php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_conf.c	2011-10-09 15:12:26 UTC (rev 317937)
@@ -878,6 +878,10 @@
 			}
 		}

+		if (wp->config->request_terminate_timeout) {
+			fpm_globals.heartbeat = fpm_globals.heartbeat ? MIN(fpm_globals.heartbeat, (wp->config->request_terminate_timeout * 1000) / 3) : (wp->config->request_terminate_timeout * 1000) / 3;
+		}
+
 		/* slowlog */
 		if (wp->config->slowlog && *wp->config->slowlog) {
 			fpm_evaluate_full_path(&wp->config->slowlog, wp, NULL, 0);
@@ -912,6 +916,8 @@
 				}
 				close(fd);
 			}
+
+			fpm_globals.heartbeat = fpm_globals.heartbeat ? MIN(fpm_globals.heartbeat, (wp->config->request_slowlog_timeout * 1000) / 3) : (wp->config->request_slowlog_timeout * 1000) / 3;
 		}

 		/* chroot */

Modified: php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_events.c
===================================================================
--- php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_events.c	2011-10-09 14:36:11 UTC (rev 317936)
+++ php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_events.c	2011-10-09 15:12:26 UTC (rev 317937)
@@ -350,7 +350,9 @@
 	fpm_event_add(&signal_fd_event, 0);

 	/* add timers */
-	fpm_pctl_heartbeat(NULL, 0, NULL);
+	if (fpm_globals.heartbeat > 0) {
+		fpm_pctl_heartbeat(NULL, 0, NULL);
+	}

 	if (!err) {
 		fpm_pctl_perform_idle_server_maintenance_heartbeat(NULL, 0, NULL);

Modified: php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_process_ctl.c
===================================================================
--- php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_process_ctl.c	2011-10-09 14:36:11 UTC (rev 317936)
+++ php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_process_ctl.c	2011-10-09 15:12:26 UTC (rev 317937)
@@ -453,9 +453,13 @@
 		return;
 	}

+	/* ensure heartbeat is not lower than FPM_PCTL_MIN_HEARTBEAT */
+	fpm_globals.heartbeat = MAX(fpm_globals.heartbeat, FPM_PCTL_MIN_HEARTBEAT);
+
 	/* first call without setting to initialize the timer */
+	zlog(ZLOG_DEBUG, "heartbeat have been set up with a timeout of %dms", fpm_globals.heartbeat);
 	fpm_event_set_timer(&heartbeat, FPM_EV_PERSIST, &fpm_pctl_heartbeat, NULL);
-	fpm_event_add(&heartbeat, FPM_PCTL_HEARTBEAT);
+	fpm_event_add(&heartbeat, fpm_globals.heartbeat);
 }
 /* }}} */


Modified: php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_process_ctl.h
===================================================================
--- php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_process_ctl.h	2011-10-09 14:36:11 UTC (rev 317936)
+++ php/php-src/branches/PHP_5_4/sapi/fpm/fpm/fpm_process_ctl.h	2011-10-09 15:12:26 UTC (rev 317937)
@@ -11,9 +11,10 @@
 #define FPM_MAX_SPAWN_RATE (32)
 /* 1s (in ms) heartbeat for idle server maintenance */
 #define FPM_IDLE_SERVER_MAINTENANCE_HEARTBEAT (1000)
-/* 130ms heartbeat for pctl */
-#define FPM_PCTL_HEARTBEAT (130)
+/* a minimum of 130ms heartbeat for pctl */
+#define FPM_PCTL_MIN_HEARTBEAT (130)

+
 struct fpm_child_s;

 void fpm_pctl(int new_state, int action);

Modified: php/php-src/trunk/sapi/fpm/fpm/fpm.c
===================================================================
--- php/php-src/trunk/sapi/fpm/fpm/fpm.c	2011-10-09 14:36:11 UTC (rev 317936)
+++ php/php-src/trunk/sapi/fpm/fpm/fpm.c	2011-10-09 15:12:26 UTC (rev 317937)
@@ -36,7 +36,8 @@
 	.listening_socket = 0,
 	.max_requests = 0,
 	.is_child = 0,
-	.test_successful = 0
+	.test_successful = 0,
+	.heartbeat = 0
 };

 int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf) /* {{{ */

Modified: php/php-src/trunk/sapi/fpm/fpm/fpm.h
===================================================================
--- php/php-src/trunk/sapi/fpm/fpm/fpm.h	2011-10-09 14:36:11 UTC (rev 317936)
+++ php/php-src/trunk/sapi/fpm/fpm/fpm.h	2011-10-09 15:12:26 UTC (rev 317937)
@@ -24,6 +24,7 @@
 	int max_requests; /* for this child */
 	int is_child;
 	int test_successful;
+	int heartbeat;
 };

 extern struct fpm_globals_s fpm_globals;

Modified: php/php-src/trunk/sapi/fpm/fpm/fpm_conf.c
===================================================================
--- php/php-src/trunk/sapi/fpm/fpm/fpm_conf.c	2011-10-09 14:36:11 UTC (rev 317936)
+++ php/php-src/trunk/sapi/fpm/fpm/fpm_conf.c	2011-10-09 15:12:26 UTC (rev 317937)
@@ -878,6 +878,10 @@
 			}
 		}

+		if (wp->config->request_terminate_timeout) {
+			fpm_globals.heartbeat = fpm_globals.heartbeat ? MIN(fpm_globals.heartbeat, (wp->config->request_terminate_timeout * 1000) / 3) : (wp->config->request_terminate_timeout * 1000) / 3;
+		}
+
 		/* slowlog */
 		if (wp->config->slowlog && *wp->config->slowlog) {
 			fpm_evaluate_full_path(&wp->config->slowlog, wp, NULL, 0);
@@ -912,6 +916,8 @@
 				}
 				close(fd);
 			}
+
+			fpm_globals.heartbeat = fpm_globals.heartbeat ? MIN(fpm_globals.heartbeat, (wp->config->request_slowlog_timeout * 1000) / 3) : (wp->config->request_slowlog_timeout * 1000) / 3;
 		}

 		/* chroot */

Modified: php/php-src/trunk/sapi/fpm/fpm/fpm_events.c
===================================================================
--- php/php-src/trunk/sapi/fpm/fpm/fpm_events.c	2011-10-09 14:36:11 UTC (rev 317936)
+++ php/php-src/trunk/sapi/fpm/fpm/fpm_events.c	2011-10-09 15:12:26 UTC (rev 317937)
@@ -350,7 +350,9 @@
 	fpm_event_add(&signal_fd_event, 0);

 	/* add timers */
-	fpm_pctl_heartbeat(NULL, 0, NULL);
+	if (fpm_globals.heartbeat > 0) {
+		fpm_pctl_heartbeat(NULL, 0, NULL);
+	}

 	if (!err) {
 		fpm_pctl_perform_idle_server_maintenance_heartbeat(NULL, 0, NULL);

Modified: php/php-src/trunk/sapi/fpm/fpm/fpm_process_ctl.c
===================================================================
--- php/php-src/trunk/sapi/fpm/fpm/fpm_process_ctl.c	2011-10-09 14:36:11 UTC (rev 317936)
+++ php/php-src/trunk/sapi/fpm/fpm/fpm_process_ctl.c	2011-10-09 15:12:26 UTC (rev 317937)
@@ -453,9 +453,13 @@
 		return;
 	}

+	/* ensure heartbeat is not lower than FPM_PCTL_MIN_HEARTBEAT */
+	fpm_globals.heartbeat = MAX(fpm_globals.heartbeat, FPM_PCTL_MIN_HEARTBEAT);
+
 	/* first call without setting to initialize the timer */
+	zlog(ZLOG_DEBUG, "heartbeat have been set up with a timeout of %dms", fpm_globals.heartbeat);
 	fpm_event_set_timer(&heartbeat, FPM_EV_PERSIST, &fpm_pctl_heartbeat, NULL);
-	fpm_event_add(&heartbeat, FPM_PCTL_HEARTBEAT);
+	fpm_event_add(&heartbeat, fpm_globals.heartbeat);
 }
 /* }}} */


Modified: php/php-src/trunk/sapi/fpm/fpm/fpm_process_ctl.h
===================================================================
--- php/php-src/trunk/sapi/fpm/fpm/fpm_process_ctl.h	2011-10-09 14:36:11 UTC (rev 317936)
+++ php/php-src/trunk/sapi/fpm/fpm/fpm_process_ctl.h	2011-10-09 15:12:26 UTC (rev 317937)
@@ -11,9 +11,10 @@
 #define FPM_MAX_SPAWN_RATE (32)
 /* 1s (in ms) heartbeat for idle server maintenance */
 #define FPM_IDLE_SERVER_MAINTENANCE_HEARTBEAT (1000)
-/* 130ms heartbeat for pctl */
-#define FPM_PCTL_HEARTBEAT (130)
+/* a minimum of 130ms heartbeat for pctl */
+#define FPM_PCTL_MIN_HEARTBEAT (130)

+
 struct fpm_child_s;

 void fpm_pctl(int new_state, int action);
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to