From: Jean-Gabriel Dick Date: Wed, 20 Jul 2011 07:35:53 +0000 (+1200) Subject: Bug 1842: Optimize order of tests in peerWouldBePinged() and peerHTTPOkay() X-Git-Tag: take08~55^2~56 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6315602cd3e7a38a47a1cd5f29c41d3c422da39e;p=thirdparty%2Fsquid.git Bug 1842: Optimize order of tests in peerWouldBePinged() and peerHTTPOkay() The peerAllowedToUse() function may be time consuming, especially on sites that have lots of acls. --- diff --git a/src/neighbors.cc b/src/neighbors.cc index 398ad00141..ae4d6e18b1 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -213,22 +213,19 @@ peerAllowedToUse(const peer * p, HttpRequest * request) static int peerWouldBePinged(const peer * p, HttpRequest * request) { - if (!peerAllowedToUse(p, request)) + if (p->icp.port == 0) return 0; if (p->options.no_query) return 0; - if (p->options.background_ping && (squid_curtime - p->stats.last_query < Config.backgroundPingRate)) - return 0; - if (p->options.mcast_responder) return 0; if (p->n_addresses == 0) return 0; - if (p->icp.port == 0) + if (p->options.background_ping && (squid_curtime - p->stats.last_query < Config.backgroundPingRate)) return 0; /* the case below seems strange, but can happen if the @@ -237,6 +234,9 @@ peerWouldBePinged(const peer * p, HttpRequest * request) if (!request->flags.hierarchical) return 0; + if (!peerAllowedToUse(p, request)) + return 0; + /* Ping dead peers every timeout interval */ if (squid_curtime - p->stats.last_query > Config.Timeout.deadPeer) return 1; @@ -251,16 +251,16 @@ peerWouldBePinged(const peer * p, HttpRequest * request) int peerHTTPOkay(const peer * p, HttpRequest * request) { + if (p->max_conn) + if (p->stats.conn_open >= p->max_conn) + return 0; + if (!peerAllowedToUse(p, request)) return 0; if (!neighborUp(p)) return 0; - if (p->max_conn) - if (p->stats.conn_open >= p->max_conn) - return 0; - return 1; }