Squid-2.2.STABLE3: nonhierarchical_direct squid.conf directive Adds a new squid.conf directive: nonhierachical_direct. This controls if requests Squid classifies as non-hierarchical (matches hierarchy_stoplist or non-cachable request type) should go direct if possible, or if parents should be used on such requests. Also improved parent selection for never_direct (selects all available parents incase the primary one should fail). Index: squid/src/cf.data.pre diff -u squid/src/cf.data.pre:1.1.1.36 squid/src/cf.data.pre:1.1.1.36.2.1 --- squid/src/cf.data.pre:1.1.1.36 Wed May 19 23:27:10 1999 +++ squid/src/cf.data.pre Thu May 20 00:30:28 1999 @@ -2776,19 +2776,42 @@ encrypted. This is the encryption key. DOC_END +NAME: nonhierarchical_direct +TYPE: onoff +LOC: Config.onoff.nonhierarchical_direct +DEFAULT: on +DOC_START + By default, Squid will send any non-hierarchical requests + (matching hierarchy_stoplist or not cachable request type) direct + to origin servers. + + If you set this to off, then Squid will prefer to send these + requests to parents. + + Note that in most configurations, by turning this off you will only + add latency to these request without any improvement in global hit + ratio. + + If you are inside an firewall then see never_direct instead of + this directive. + +nonhierarchical_direct on +DOC_END + NAME: prefer_direct TYPE: onoff LOC: Config.onoff.prefer_direct -DEFAULT: on +DEFAULT: off DOC_START - By default, if the ICP, HTCP, Cache Digest, etc. techniques - do not yield a parent cache, Squid gives higher preference - to forwarding the request direct to origin servers, rather - than selecting a parent cache anyway. - - If you want Squid to give higher precedence to a parent - cache, instead of going direct, then turn this option off. -prefer_direct on + Normally Squid tries to use parents for most requests. If you by some + reason like it to first try going direct and only use a parent if + going direct fails then set this to off. + + By combining nonhierarchical_direct off and prefer_direct on you + can set up Squid to use a parent as a backup path if going direct + fails. + +prefer_direct off DOC_END NAME: strip_query_terms Index: squid/src/peer_select.c diff -u squid/src/peer_select.c:1.1.1.28.2.1 squid/src/peer_select.c:1.1.1.28.2.2 --- squid/src/peer_select.c:1.1.1.28.2.1 Wed May 19 23:59:52 1999 +++ squid/src/peer_select.c Thu May 20 00:30:30 1999 @@ -88,6 +88,7 @@ static void peerGetSomeNeighborReplies(ps_state *); static void peerGetSomeDirect(ps_state *); static void peerGetSomeParent(ps_state *); +static void peerGetAllParents(ps_state *); static void peerAddFwdServer(FwdServer **, peer *, hier_code); static void @@ -278,11 +279,23 @@ peerGetSomeNeighborReplies(ps); entry->ping_status = PING_DONE; } - if (Config.onoff.prefer_direct) + switch (ps->direct) { + case DIRECT_YES: peerGetSomeDirect(ps); - peerGetSomeParent(ps); - /* Have direct as a last resort if possible.. */ - peerGetSomeDirect(ps); + break; + case DIRECT_NO: + peerGetSomeParent(ps); + peerGetAllParents(ps); + break; + default: + if (Config.onoff.prefer_direct) + peerGetSomeDirect(ps); + if (request->flags.hierarchical || !Config.onoff.nonhierarchical_direct) + peerGetSomeParent(ps); + if (!Config.onoff.prefer_direct) + peerGetSomeDirect(ps); + break; + } peerSelectCallback(ps); } @@ -435,6 +448,35 @@ debug(44, 3) ("peerSelect: %s/%s\n", hier_strings[code], p->host); peerAddFwdServer(&ps->servers, p, code); } +} + +/* Adds alive parents. Used as a last resort for never_direct. + */ +static void +peerGetAllParents(ps_state * ps) +{ + peer *p; + request_t *request = ps->request; + /* Add all alive parents */ + for (p = Config.peers; p; p = p->next) { + /* XXX: neighbors.c lacks a public interface for enumerating + * parents to a request so we have to dig some here.. + */ + if (neighborType(p, request) != PEER_PARENT) + continue; + if (!peerHTTPOkay(p, request)) + continue; + debug(15, 3) ("peerGetAllParents: adding alive parent %s\n", p->host); + peerAddFwdServer(&ps->servers, p, ANY_OLD_PARENT); + } + /* XXX: should add dead parents here, but it is currently + * not possible to find out which parents are dead or which + * simply are not configured to handle the request. + */ + /* Add default parent as a last resort */ + if ((p = getDefaultParent(request))) { + peerAddFwdServer(&ps->servers, p, DEFAULT_PARENT); + } } static void Index: squid/src/structs.h diff -u squid/src/structs.h:1.1.1.37.10.4 squid/src/structs.h:1.1.1.37.10.5 --- squid/src/structs.h:1.1.1.37.10.4 Wed May 19 23:59:53 1999 +++ squid/src/structs.h Thu May 20 00:30:31 1999 @@ -375,6 +375,7 @@ int redir_rewrites_host; int persistent_client_posts; int prefer_direct; + int nonhierarchical_direct; int strip_query_terms; } onoff; acl *aclList;