]> granicus.if.org Git - apache/commitdiff
* Always try to reuse the address looked up for the worker if we are allowed to
authorRuediger Pluem <rpluem@apache.org>
Tue, 2 Apr 2013 09:18:01 +0000 (09:18 +0000)
committerRuediger Pluem <rpluem@apache.org>
Tue, 2 Apr 2013 09:18:01 +0000 (09:18 +0000)
  reuse the address. This saves DNS lookups.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1463455 13f79535-47bb-0310-9956-ffa450edef68

modules/proxy/proxy_util.c

index 9e773fb2e7fd35b64f28ffc3a9eba4ee20883a6b..1baf4fe49ccd14438c8f937baaddb7cd2756a02f 100644 (file)
@@ -2155,47 +2155,46 @@ ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
             decodeenc(uds_path);
             conn->uds_path = uds_path;
         }
-        else {
-            if (worker->s->is_address_reusable && !worker->s->disablereuse
-                && worker->cp->addr) {
-                /*
-                 * We got here because only conn->hostname was null.
-                 * If we have a worker->cp->addr we are allowed to reuse it
-                 * and hence save a DNS lookup.
-                 */
-                conn->addr = worker->cp->addr;
-            }
-            else {
-                err = apr_sockaddr_info_get(&(conn->addr),
-                                            conn->hostname, APR_UNSPEC,
-                                            conn->port, 0,
-                                            conn->pool);
-            }
+        else if (!worker->s->is_address_reusable || worker->s->disablereuse) {
+            /*
+             * Only do a lookup if we should not reuse the backend address.
+             * Otherwise we will look it up once for the worker.
+             */
+            err = apr_sockaddr_info_get(&(conn->addr),
+                                        conn->hostname, APR_UNSPEC,
+                                        conn->port, 0,
+                                        conn->pool);
         }
     }
-    else if (!worker->cp->addr) {
-        if ((err = PROXY_THREAD_LOCK(worker)) != APR_SUCCESS) {
-            ap_log_rerror(APLOG_MARK, APLOG_ERR, err, r, APLOGNO(00945) "lock");
-            return HTTP_INTERNAL_SERVER_ERROR;
-        }
-
+    if (worker->s->is_address_reusable && !worker->s->disablereuse) {
         /*
-         * Worker can have the single constant backend adress.
-         * The single DNS lookup is used once per worker.
-         * If dynamic change is needed then set the addr to NULL
-         * inside dynamic config to force the lookup.
+         * Looking up the backend address for the worker only makes sense if
+         * we can reuse the address.
          */
-        err = apr_sockaddr_info_get(&(worker->cp->addr),
-                                    conn->hostname, APR_UNSPEC,
-                                    conn->port, 0,
-                                    worker->cp->pool);
-        conn->addr = worker->cp->addr;
-        if ((uerr = PROXY_THREAD_UNLOCK(worker)) != APR_SUCCESS) {
-            ap_log_rerror(APLOG_MARK, APLOG_ERR, uerr, r, APLOGNO(00946) "unlock");
+        if (!worker->cp->addr) {
+            if ((err = PROXY_THREAD_LOCK(worker)) != APR_SUCCESS) {
+                ap_log_rerror(APLOG_MARK, APLOG_ERR, err, r, APLOGNO(00945) "lock");
+                return HTTP_INTERNAL_SERVER_ERROR;
+            }
+
+            /*
+             * Worker can have the single constant backend adress.
+             * The single DNS lookup is used once per worker.
+             * If dynamic change is needed then set the addr to NULL
+             * inside dynamic config to force the lookup.
+             */
+            err = apr_sockaddr_info_get(&(worker->cp->addr),
+                                        conn->hostname, APR_UNSPEC,
+                                        conn->port, 0,
+                                        worker->cp->pool);
+            conn->addr = worker->cp->addr;
+            if ((uerr = PROXY_THREAD_UNLOCK(worker)) != APR_SUCCESS) {
+                ap_log_rerror(APLOG_MARK, APLOG_ERR, uerr, r, APLOGNO(00946) "unlock");
+            }
+        }
+        else {
+            conn->addr = worker->cp->addr;
         }
-    }
-    else {
-        conn->addr = worker->cp->addr;
     }
     /* Close a possible existing socket if we are told to do so */
     if (conn->close) {