From: Jim Jagielski Date: Tue, 11 Nov 2008 20:01:59 +0000 (+0000) Subject: * mod_proxy: Add the possibility to set the worker parameters X-Git-Tag: 2.2.11~78 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3bf0124dd3af7fe88118e293990e5e478811d2ba;p=thirdparty%2Fapache%2Fhttpd.git * mod_proxy: Add the possibility to set the worker parameters connectiontimeout and ping in milliseconds. Trunk version of patch: http://svn.apache.org/viewvc?rev=705005&view=rev http://svn.apache.org/viewvc?rev=707022&view=rev Backport version for 2.2.x of patch: http://people.apache.org/~rpluem/patches/milli_seconds.diff +1: rpluem, pgollucci, jim git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@713145 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 6077cd46716..2dd6a9f9910 100644 --- a/CHANGES +++ b/CHANGES @@ -9,6 +9,11 @@ Changes with Apache 2.2.11 send the empty body packet, so container can deal with that. [Mladen Turk] + *) core: Add ap_timeout_parameter_parse to public API. [Ruediger Pluem] + + *) mod_proxy: Add the possibility to set the worker parameters + connectiontimeout and ping in milliseconds. [Ruediger Pluem] + *) Worker MPM: Crosscheck that idle workers are still available before using them and thus preventing an overflow of the worker queue which causes a SegFault. PR 45605 [Denis Ustimenko ] diff --git a/STATUS b/STATUS index 03eaeef3b38..24085315e0c 100644 --- a/STATUS +++ b/STATUS @@ -96,15 +96,6 @@ PATCHES ACCEPTED TO BACKPORT FROM TRUNK: http://people.apache.org/~rpluem/patches/proxy_alloc_lifetime_rework_2.2.x.diff +1: rpluem, pgollucci, jim - * mod_proxy: Add the possibility to set the worker parameters - connectiontimeout and ping in milliseconds. - Trunk version of patch: - http://svn.apache.org/viewvc?rev=705005&view=rev - http://svn.apache.org/viewvc?rev=707022&view=rev - Backport version for 2.2.x of patch: - http://people.apache.org/~rpluem/patches/milli_seconds.diff - +1: rpluem, pgollucci, jim - PATCHES PROPOSED TO BACKPORT FROM TRUNK: [ New proposals should be added at the end of the list ] diff --git a/docs/manual/mod/mod_proxy.xml b/docs/manual/mod/mod_proxy.xml index 8546ab051db..b0626faaf29 100644 --- a/docs/manual/mod/mod_proxy.xml +++ b/docs/manual/mod/mod_proxy.xml @@ -693,7 +693,8 @@ expressions timeout Connect timeout in seconds. The number of seconds Apache waits for the creation of a connection to - the backend to complete. + the backend to complete. By adding a postfix of ms the timeout can be + also set in milliseconds. disablereuse Off @@ -748,6 +749,8 @@ expressions which could be an issue, but it will lower the traffic in case some of the cluster nodes are down or busy. Currently this has an effect only for AJP. + By adding a postfix of ms the delay can be also set in + milliseconds. loadfactor 1 diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 411b2d50b42..bbce0ed0ece 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -132,6 +132,7 @@ * proxy_worker struct. * 20051115.17 (2.2.10) Add scolonsep to proxy_balancer * 20051115.18 (2.2.10) Add chroot support to unixd_config + * 20051115.19 (2.2.11) Added ap_timeout_parameter_parse to util.c / httpd.h */ #define MODULE_MAGIC_COOKIE 0x41503232UL /* "AP22" */ @@ -139,7 +140,7 @@ #ifndef MODULE_MAGIC_NUMBER_MAJOR #define MODULE_MAGIC_NUMBER_MAJOR 20051115 #endif -#define MODULE_MAGIC_NUMBER_MINOR 18 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 19 /* 0...n */ /** * Determine if the server's current MODULE_MAGIC_NUMBER is at least a diff --git a/include/httpd.h b/include/httpd.h index 542b6eaa7a2..a96e4d62097 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -1734,6 +1734,29 @@ AP_DECLARE(char *) ap_escape_quotes(apr_pool_t *p, const char *instring); AP_DECLARE(char *) ap_append_pid(apr_pool_t *p, const char *string, const char *delim); +/** + * Parse a given timeout parameter string into an apr_interval_time_t value. + * The unit of the time interval is given as postfix string to the numeric + * string. Currently the following units are understood: + * + * ms : milliseconds + * s : seconds + * mi[n] : minutes + * h : hours + * + * If no unit is contained in the given timeout parameter the default_time_unit + * will be used instead. + * @param timeout_parameter The string containing the timeout parameter. + * @param timeout The timeout value to be returned. + * @param default_time_unit The default time unit to use if none is specified + * in timeout_parameter. + * @return Status value indicating whether the parsing was successful or not. + */ +AP_DECLARE(apr_status_t) ap_timeout_parameter_parse( + const char *timeout_parameter, + apr_interval_time_t *timeout, + const char *default_time_unit); + /* Misc system hackery */ /** * Given the name of an object in the file system determine if it is a directory diff --git a/modules/proxy/mod_proxy.c b/modules/proxy/mod_proxy.c index 7aaa7da7af3..453653649a7 100644 --- a/modules/proxy/mod_proxy.c +++ b/modules/proxy/mod_proxy.c @@ -71,6 +71,8 @@ static const char *set_worker_param(apr_pool_t *p, { int ival; + apr_interval_time_t timeout; + if (!strcasecmp(key, "loadfactor")) { /* Normalized load factor. Used with BalancerMamber, * it is a number between 1 and 100. @@ -126,14 +128,15 @@ static const char *set_worker_param(apr_pool_t *p, worker->smax = ival; } else if (!strcasecmp(key, "acquire")) { - /* Acquire timeout in milliseconds. + /* Acquire in given unit (default is milliseconds). * If set this will be the maximum time to * wait for a free connection. */ - ival = atoi(val); - if (ival < 1) - return "Acquire must be at least one mili second"; - worker->acquire = apr_time_make(0, ival * 1000); + if (ap_timeout_parameter_parse(val, &timeout, "ms") != APR_SUCCESS) + return "Acquire timeout has wrong format"; + if (timeout < 1000) + return "Acquire must be at least one millisecond"; + worker->acquire = timeout; worker->acquire_set = 1; } else if (!strcasecmp(key, "timeout")) { @@ -267,22 +270,24 @@ static const char *set_worker_param(apr_pool_t *p, worker->lbset = ival; } else if (!strcasecmp(key, "ping")) { - /* Ping/Pong timeout in seconds. + /* Ping/Pong timeout in given unit (default is second). */ - ival = atoi(val); - if (ival < 1) - return "Ping/Pong timeout must be at least one second"; - worker->ping_timeout = apr_time_from_sec(ival); + if (ap_timeout_parameter_parse(val, &timeout, "s") != APR_SUCCESS) + return "Ping/Pong timeout has wrong format"; + if (timeout < 1000) + return "Ping/Pong timeout must be at least one millisecond"; + worker->ping_timeout = timeout; worker->ping_timeout_set = 1; } else if (!strcasecmp(key, "connectiontimeout")) { - /* Request timeout in seconds. + /* Request timeout in given unit (default is second). * Defaults to connection timeout */ - ival = atoi(val); - if (ival < 1) - return "Connectiontimeout must be at least one second."; - worker->conn_timeout = apr_time_from_sec(ival); + if (ap_timeout_parameter_parse(val, &timeout, "s") != APR_SUCCESS) + return "Connectiontimeout has wrong format"; + if (timeout < 1000) + return "Connectiontimeout must be at least one millisecond."; + worker->conn_timeout = timeout; worker->conn_timeout_set = 1; } else { diff --git a/server/util.c b/server/util.c index e1be3d1831d..3c927c23957 100644 --- a/server/util.c +++ b/server/util.c @@ -2146,3 +2146,71 @@ AP_DECLARE(char *) ap_append_pid(apr_pool_t *p, const char *string, delim, getpid()); } + +/** + * Parse a given timeout parameter string into an apr_interval_time_t value. + * The unit of the time interval is given as postfix string to the numeric + * string. Currently the following units are understood: + * + * ms : milliseconds + * s : seconds + * mi[n] : minutes + * h : hours + * + * If no unit is contained in the given timeout parameter the default_time_unit + * will be used instead. + * @param timeout_parameter The string containing the timeout parameter. + * @param timeout The timeout value to be returned. + * @param default_time_unit The default time unit to use if none is specified + * in timeout_parameter. + * @return Status value indicating whether the parsing was successful or not. + */ +AP_DECLARE(apr_status_t) ap_timeout_parameter_parse( + const char *timeout_parameter, + apr_interval_time_t *timeout, + const char *default_time_unit) +{ + char *endp; + const char *time_str; + apr_int64_t tout; + + tout = apr_strtoi64(timeout_parameter, &endp, 10); + if (errno) { + return errno; + } + if (!endp || !*endp) { + time_str = default_time_unit; + } + else { + time_str = endp; + } + + switch (*time_str) { + /* Time is in seconds */ + case 's': + *timeout = (apr_interval_time_t) apr_time_from_sec(tout); + break; + case 'h': + /* Time is in hours */ + *timeout = (apr_interval_time_t) apr_time_from_sec(tout * 3600); + break; + case 'm': + switch (*(++time_str)) { + /* Time is in miliseconds */ + case 's': + *timeout = (apr_interval_time_t) tout * 1000; + break; + /* Time is in minutes */ + case 'i': + *timeout = (apr_interval_time_t) apr_time_from_sec(tout * 60); + break; + default: + return APR_EGENERAL; + } + break; + default: + return APR_EGENERAL; + } + return APR_SUCCESS; +} +