From 65a53c8ed44bb597f7fde1ae5ad80900e9b02131 Mon Sep 17 00:00:00 2001 From: wessels <> Date: Mon, 26 Jun 2000 10:57:16 +0000 Subject: [PATCH] DW: - 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 | 10 ++++++++- src/protos.h | 4 ++-- src/store.cc | 7 +++++- src/store_dir.cc | 58 ++++++++++++++++-------------------------------- src/store_io.cc | 36 +++++++++++++++++++++++++++--- src/structs.h | 3 ++- src/typedefs.h | 5 ++++- 7 files changed, 75 insertions(+), 48 deletions(-) diff --git a/src/cf.data.pre b/src/cf.data.pre index 3e1466900a..1f18fc739e 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -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 diff --git a/src/protos.h b/src/protos.h index 8d0ef363e4..2bc231cf86 100644 --- a/src/protos.h +++ b/src/protos.h @@ -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); diff --git a/src/store.cc b/src/store.cc index 0e2bc2b520..f1babdd6d5 100644 --- a/src/store.cc +++ b/src/store.cc @@ -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 diff --git a/src/store_dir.cc b/src/store_dir.cc index 1ab208f9ef..4e9420df7a 100644 --- a/src/store_dir.cc +++ b/src/store_dir.cc @@ -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 @@ -36,6 +36,14 @@ #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; diff --git a/src/store_io.cc b/src/store_io.cc index 1488c88817..b9a4345472 100644 --- a/src/store_io.cc +++ b/src/store_io.cc @@ -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); +} diff --git a/src/structs.h b/src/structs.h index 04ef188eb9..fa13e134f5 100644 --- a/src/structs.h +++ b/src/structs.h @@ -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 { diff --git a/src/typedefs.h b/src/typedefs.h index 780349ea26..c9388b436c 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -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_ */ -- 2.47.3