]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
hno squid-2.2.STABLE3.nonhierarchical_direct-2.patch
authorhno <>
Wed, 3 May 2000 00:35:09 +0000 (00:35 +0000)
committerhno <>
Wed, 3 May 2000 00:35:09 +0000 (00:35 +0000)
Squid-2.2.STABLE3: nonhierarchical_direct squid.conf directive

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 to try to selects all available parents
to increase the likelyhood that there is at least one alive parent where
the request can be forwarded.

src/cf.data.pre
src/peer_select.cc
src/structs.h

index 9d1048dcdfd0a2db1336bd8e1df57bfde93d4ddc..2d9c1b5c273dd6821606f4d6af664375ac2d1251 100644 (file)
@@ -1,6 +1,6 @@
 
 #
-# $Id: cf.data.pre,v 1.168 2000/03/14 22:59:13 wessels Exp $
+# $Id: cf.data.pre,v 1.169 2000/05/02 18:35:09 hno Exp $
 #
 #
 # SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -3030,19 +3030,42 @@ DOC_START
        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.
+       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.
 
-       If you want Squid to give higher precedence to a parent
-       cache, instead of going direct, then turn this option off.
-prefer_direct on
+prefer_direct off
 DOC_END
 
 NAME: strip_query_terms
index 2ac9dcea42b6da587a1a0f318de5ced35c9520e5..3bd6233c72083a0d42820985f3abcd70b73b7870 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: peer_select.cc,v 1.106 2000/05/02 18:32:41 hno Exp $
+ * $Id: peer_select.cc,v 1.107 2000/05/02 18:35:09 hno Exp $
  *
  * DEBUG: section 44    Peer Selection Algorithm
  * AUTHOR: Duane Wessels
@@ -89,6 +89,7 @@ static void peerGetSomeNeighbor(ps_state *);
 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
@@ -273,11 +274,23 @@ peerSelectFoo(ps_state * ps)
        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);
 }
 
@@ -434,6 +447,35 @@ peerGetSomeParent(ps_state * ps)
     }
 }
 
+/* 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
 peerPingTimeout(void *data)
 {
index 42c9b350e7b1f5f02e1c69e848f71411708ab748..d25e356512425f5660dafccd81d2413c6cf39eb4 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: structs.h,v 1.318 2000/05/02 18:32:41 hno Exp $
+ * $Id: structs.h,v 1.319 2000/05/02 18:35:09 hno Exp $
  *
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -407,6 +407,7 @@ struct _SquidConfig {
        int offline;
        int redir_rewrites_host;
        int prefer_direct;
+       int nonhierarchical_direct;
        int strip_query_terms;
        int redirector_bypass;
        int ignore_unknown_nameservers;