From: Jim Jagielski Date: Tue, 29 Nov 2011 21:15:57 +0000 (+0000) Subject: Merge r1208067, r1208068, r1208069 from trunk: X-Git-Tag: 2.3.16~83 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8a6498191986769cda940563daca09bbe2cf6c09;p=apache Merge r1208067, r1208068, r1208069 from trunk: whitespace Some optimization... we have a hash, use it. Quicker than all these string comparisons. Ensure casing doesn't matter... (we know balancer->s->name is lc) Reviewed/backported by: jim git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1208071 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/proxy/mod_proxy.c b/modules/proxy/mod_proxy.c index aa76ab9502..e63be0800a 100644 --- a/modules/proxy/mod_proxy.c +++ b/modules/proxy/mod_proxy.c @@ -670,8 +670,8 @@ static int proxy_trans(request_rec *r) } } - conf - = (proxy_server_conf *) ap_get_module_config(r->server->module_config, &proxy_module); + conf = (proxy_server_conf *) ap_get_module_config(r->server->module_config, + &proxy_module); /* long way - walk the list of aliases, find a match */ if (conf->aliases->nelts) { @@ -1464,6 +1464,7 @@ static const char * if (err) return apr_pstrcat(cmd->temp_pool, "ProxyPass ", err, NULL); } + new->balancer = balancer; } else { proxy_worker *worker = ap_proxy_get_worker(cmd->temp_pool, NULL, conf, r); diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h index 236aa94ebd..f91afca81f 100644 --- a/modules/proxy/mod_proxy.h +++ b/modules/proxy/mod_proxy.h @@ -88,6 +88,11 @@ enum enctype { */ #define DEFAULT_MAX_FORWARDS -1 +typedef struct proxy_balancer proxy_balancer; +typedef struct proxy_worker proxy_worker; +typedef struct proxy_conn_pool proxy_conn_pool; +typedef struct proxy_balancer_method proxy_balancer_method; + /* static information about a remote proxy */ struct proxy_remote { const char *scheme; /* the schemes handled by this proxy, or '*' */ @@ -105,6 +110,7 @@ struct proxy_alias { const char *fake; ap_regex_t *regex; unsigned int flags; + proxy_balancer *balancer; /* only valid for reverse-proxys */ }; struct dirconn_entry { @@ -119,11 +125,6 @@ struct noproxy_entry { struct apr_sockaddr_t *addr; }; -typedef struct proxy_balancer proxy_balancer; -typedef struct proxy_worker proxy_worker; -typedef struct proxy_conn_pool proxy_conn_pool; -typedef struct proxy_balancer_method proxy_balancer_method; - typedef struct { apr_array_header_t *proxies; apr_array_header_t *sec_proxy; @@ -408,7 +409,7 @@ typedef struct { apr_time_t wupdated; /* timestamp of last change to workers list */ int max_attempts; /* Number of attempts before failing */ int index; /* shm array index */ - int hash; + unsigned int hash; unsigned int sticky_force:1; /* Disable failover for sticky sessions */ unsigned int scolonsep:1; /* true if ';' seps sticky session paths */ unsigned int max_attempts_set:1; @@ -427,7 +428,7 @@ struct proxy_balancer { ap_slotmem_provider_t *storage; int growth; /* number of post-config workers can added */ int max_workers; /* maximum number of allowed workers */ - int hash; + unsigned int hash; apr_time_t wupdated; /* timestamp of last change to workers list */ proxy_balancer_method *lbmethod; apr_global_mutex_t *gmutex; /* global lock for updating list of workers */ diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c index df3d6d9609..2af6768d18 100644 --- a/modules/proxy/proxy_util.c +++ b/modules/proxy/proxy_util.c @@ -1298,7 +1298,9 @@ PROXY_DECLARE(proxy_balancer *) ap_proxy_get_balancer(apr_pool_t *p, proxy_balancer *balancer; char *c, *uri = apr_pstrdup(p, url); int i; + unsigned int hash; + ap_str_tolower(uri); c = strchr(uri, ':'); if (c == NULL || c[1] != '/' || c[2] != '/' || c[3] == '\0') { return NULL; @@ -1307,9 +1309,10 @@ PROXY_DECLARE(proxy_balancer *) ap_proxy_get_balancer(apr_pool_t *p, if ((c = strchr(c + 3, '/'))) { *c = '\0'; } + hash = ap_proxy_hashfunc(uri, PROXY_HASHFUNC_DEFAULT); balancer = (proxy_balancer *)conf->balancers->elts; for (i = 0; i < conf->balancers->nelts; i++) { - if (strcasecmp(balancer->s->name, uri) == 0) { + if (balancer->hash == hash) { if (!care || !balancer->s->inactive) { return balancer; } @@ -1410,6 +1413,7 @@ PROXY_DECLARE(char *) ap_proxy_define_balancer(apr_pool_t *p, } (*balancer)->s = bshared; + (*balancer)->sconf = conf; return ap_proxy_update_balancer(p, *balancer, alias); }