]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
DW:
authorwessels <>
Mon, 26 Jun 2000 10:57:16 +0000 (10:57 +0000)
committerwessels <>
Mon, 26 Jun 2000 10:57:16 +0000 (10:57 +0000)
 - Made the store dir selection algorithm configurable via
   'store_dir_select_algorithm'.  There are currently two options:
   'least-load' (storeDirSelectSwapDirLeastLoad(), the default),
   and 'round-robin' (storeDirSelectSwapDirRoundRobin()).
 - Added counter stats to the storeCreate() function to find out
   how often it fails and succeeds.

src/cf.data.pre
src/protos.h
src/store.cc
src/store_dir.cc
src/store_io.cc
src/structs.h
src/typedefs.h

index 3e1466900aee13c5c2efa840db519a7d744ea319..1f18fc739e5301be8b7720b5eefe364f4917c139 100644 (file)
@@ -1,6 +1,6 @@
 
 #
-# $Id: cf.data.pre,v 1.190 2000/06/26 01:38:37 wessels Exp $
+# $Id: cf.data.pre,v 1.191 2000/06/26 04:57:16 wessels Exp $
 #
 #
 # SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -3226,5 +3226,13 @@ DOC_START
        the administrators attention.
 DOC_END
 
+NAME: store_dir_select_algorithm
+TYPE: string
+LOC: Config.store_dir_select_algorithm
+DEFAULT: least-load
+DOC_START
+       Set this to 'round-robin' as an alternative.
+DOC_END
+
 EOF
 
index 8d0ef363e451266c7213b981517336a3be40cc03..2bc231cf861cae475ed573e7b671e8d0812b5e98 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: protos.h,v 1.373 2000/06/25 22:41:22 wessels Exp $
+ * $Id: protos.h,v 1.374 2000/06/26 04:57:16 wessels Exp $
  *
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -909,7 +909,7 @@ extern char *storeSwapFullPath(int, char *);
 extern char *storeSwapSubSubDir(int, char *);
 extern const char *storeSwapPath(int);
 extern int storeDirWriteCleanLogs(int reopen);
-extern int storeDirSelectSwapDir(const StoreEntry *);
+extern STDIRSELECT *storeDirSelectSwapDir;
 extern int storeVerifySwapDirs(void);
 extern void storeCreateSwapDirectories(void);
 extern void storeDirCloseSwapLogs(void);
index 0e2bc2b520d033707a1c8f7726642d299cabee2b..f1babdd6d56b435189c20dfda03054b92f69f2b7 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store.cc,v 1.526 2000/06/25 22:28:43 wessels Exp $
+ * $Id: store.cc,v 1.527 2000/06/26 04:57:16 wessels Exp $
  *
  * DEBUG: section 20    Storage Manager
  * AUTHOR: Harvest Derived
@@ -71,6 +71,8 @@ typedef struct lock_ctrl_t {
     StoreEntry *e;
 } lock_ctrl_t;
 
+extern OBJH storeIOStats;
+
 /*
  * local function prototypes
  */
@@ -938,6 +940,9 @@ storeInit(void)
     cachemgrRegister("store_check_cachable_stats",
        "storeCheckCachable() Stats",
        storeCheckCachableStats, 0, 1);
+    cachemgrRegister("store_io",
+       "Store IO Interface Stats",
+       storeIOStats, 0, 1);
 }
 
 void
index 1ab208f9ef779ccdc82c563ce7c61ccfa76913fb..4e9420df7a4b00c6f14eae6adcf07699b4a553e6 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store_dir.cc,v 1.112 2000/06/25 22:28:43 wessels Exp $
+ * $Id: store_dir.cc,v 1.113 2000/06/26 04:57:17 wessels Exp $
  *
  * DEBUG: section 47    Store Directory Routines
  * AUTHOR: Duane Wessels
 #include "squid.h"
 
 static int storeDirValidSwapDirSize(int, ssize_t);
+static STDIRSELECT storeDirSelectSwapDirRoundRobin;
+static STDIRSELECT storeDirSelectSwapDirLeastLoad;
+
+/*
+ * This function pointer is set according to 'store_dir_select_algorithm'
+ * in squid.conf.
+ */
+STDIRSELECT *storeDirSelectSwapDir = storeDirSelectSwapDirLeastLoad;
 
 void
 storeDirInit(void)
@@ -46,6 +54,13 @@ storeDirInit(void)
        sd = &Config.cacheSwap.swapDirs[i];
        sd->init(sd);
     }
+    if (0 == strcasecmp(Config.store_dir_select_algorithm, "round-robin")) {
+       storeDirSelectSwapDir = storeDirSelectSwapDirRoundRobin;
+       debug(47, 1) ("Using Round Robin store dir selection\n");
+    } else {
+       storeDirSelectSwapDir = storeDirSelectSwapDirLeastLoad;
+       debug(47, 1) ("Using Least Load store dir selection\n");
+    }
 }
 
 void
@@ -97,7 +112,6 @@ storeDirValidSwapDirSize(int swapdir, ssize_t objsize)
 }
 
 
-#if UNUSED                     /* Squid-2..4.DEVEL3 code */
 /*
  * This new selection scheme simply does round-robin on all SwapDirs.
  * A SwapDir is skipped if it is over the max_size (100%) limit.  If
@@ -108,7 +122,7 @@ storeDirValidSwapDirSize(int swapdir, ssize_t objsize)
  * XXX This function does NOT account for the read_only flag!
  */
 static int
-storeDirSelectSwapDir(void)
+storeDirSelectSwapDirRoundRobin(const StoreEntry * unused)
 {
     static int dirn = 0;
     int i;
@@ -129,40 +143,6 @@ storeDirSelectSwapDir(void)
     return dirn;
 }
 
-#if USE_DISKD && EXPERIMENTAL
-/*
- * This fileno selection function returns a fileno on the least
- * busy SwapDir.  Ties are broken by selecting the SwapDir with
- * the most free space.
- */
-static int
-storeDirSelectSwapDir(void)
-{
-    SwapDir *SD;
-    int min_away = 10000;
-    int min_size = 1 << 30;
-    int dirn = 0;
-    int i;
-    for (i = 0; i < Config.cacheSwap.n_configured; i++) {
-       SD = &Config.cacheSwap.swapDirs[i];
-       if (SD->cur_size > SD->max_size)
-           continue;
-       if (SD->u.diskd.away > min_away)
-           continue;
-       if (SD->cur_size > min_size)
-           continue;
-       if (SD->flags.read_only)
-           continue;
-       min_away = SD->u.diskd.away;
-       min_size = SD->cur_size;
-       dirn = i;
-    }
-    return dirn;
-}
-#endif
-
-#endif /* Squid-2.4.DEVEL3 code */
-
 /*
  * Spread load across all of the store directories
  *
@@ -176,8 +156,8 @@ storeDirSelectSwapDir(void)
  * ALL swapdirs, regardless of state. Again, this is a hack while
  * we sort out the real usefulness of this algorithm.
  */
-int
-storeDirSelectSwapDir(const StoreEntry * e)
+static int
+storeDirSelectSwapDirLeastLoad(const StoreEntry * e)
 {
     ssize_t objsize;
     ssize_t least_size;
index 1488c88817590521de7b74180010bddb0659baad..b9a4345472f6b7628e817ba7b7135db404aa01de 100644 (file)
@@ -1,5 +1,15 @@
 #include "squid.h"
 
+static struct {
+    struct {
+       int calls;
+       int select_fail;
+       int create_fail;
+       int success;
+    } create;
+} store_io_stats;
+
+OBJH storeIOStats;
 
 /*
  * submit a request to create a cache object for writing.
@@ -13,7 +23,9 @@ storeCreate(StoreEntry * e, STIOCB * file_callback, STIOCB * close_callback, voi
     size_t objsize;
     sdirno dirn;
     SwapDir *SD;
+    storeIOState *sio;
 
+    store_io_stats.create.calls++;
     /* This is just done for logging purposes */
     objsize = objectLen(e);
     if (objsize != -1)
@@ -26,15 +38,19 @@ storeCreate(StoreEntry * e, STIOCB * file_callback, STIOCB * close_callback, voi
     dirn = storeDirSelectSwapDir(e);
     if (dirn == -1) {
        debug(20, 2) ("storeCreate: no valid swapdirs for this object\n");
+       store_io_stats.create.select_fail++;
        return NULL;
     }
     debug(20, 2) ("storeCreate: Selected dir '%d' for obj size '%d'\n", dirn, objsize);
     SD = &Config.cacheSwap.swapDirs[dirn];
 
     /* Now that we have a fs to use, call its storeCreate function */
-    return (SD->obj.create(SD, e, file_callback, close_callback, callback_data));
-
-    /* Done */
+    sio = SD->obj.create(SD, e, file_callback, close_callback, callback_data);
+    if (NULL == sio)
+       store_io_stats.create.create_fail++;
+    else
+       store_io_stats.create.success++;
+    return sio;
 }
 
 
@@ -85,3 +101,17 @@ storeOffset(storeIOState * sio)
 {
     return sio->offset;
 }
+
+/*
+ * Make this non-static so we can register
+ * it from storeInit();
+ */
+void
+storeIOStats(StoreEntry * sentry)
+{
+    storeAppendPrintf(sentry, "Store IO Interface Stats\n");
+    storeAppendPrintf(sentry, "create.calls %d\n", store_io_stats.create.calls);
+    storeAppendPrintf(sentry, "create.select_fail %d\n", store_io_stats.create.select_fail);
+    storeAppendPrintf(sentry, "create.create_fail %d\n", store_io_stats.create.create_fail);
+    storeAppendPrintf(sentry, "create.success %d\n", store_io_stats.create.success);
+}
index 04ef188eb9d74629f4a26b805d3bc59e55beeebc..fa13e134f53a3a2053fad05977dc45f2522f3413 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: structs.h,v 1.343 2000/06/26 03:36:06 wessels Exp $
+ * $Id: structs.h,v 1.344 2000/06/26 04:57:17 wessels Exp $
  *
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -504,6 +504,7 @@ struct _SquidConfig {
        int high_pf;
        int high_memory;
     } warnings;
+    char *store_dir_select_algorithm;
 };
 
 struct _SquidConfig2 {
index 780349ea26983db9067e058a3508d206ff6a9c7d..c9388b436c9184f6650dc26a480126df20dabbaf 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: typedefs.h,v 1.105 2000/06/25 22:28:43 wessels Exp $
+ * $Id: typedefs.h,v 1.106 2000/06/26 04:57:17 wessels Exp $
  *
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -309,4 +309,7 @@ typedef struct _htcpReplyData htcpReplyData;
 #endif
 
 typedef RemovalPolicy *REMOVALPOLICYCREATE(wordlist * args);
+
+typedef int STDIRSELECT(const StoreEntry *);
+
 #endif /* _TYPEDEFS_H_ */