Article View: news.software.nntp
Article #18283INN history lookup cache (patch)
From: Jeff Garzik
Date: Thu, 05 Jun 1997 00:00
Date: Thu, 05 Jun 1997 00:00
158 lines
4557 bytes
4557 bytes
This is a multi-part message in MIME format.
--------------57DA24E750E5DB6133469157
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Enclosed is the history cache patch. All history lookups pass through
this cache before hitting the huge DBZ index. It is based on coneill's
idea, but it takes it further such that
- no memory allocation / freeing is performed
- cache stats are kept, and reporting in syslog
I've been running this for a while, and haven't seen many problems. I
usually get better than 30% hit rate on the history cache.
Each time the history file is opened (after a pause or throttle) the
history cache is flushed. Each time the history file is closed, final
cache stats are reported.
--
Jeff Garzik
News Administrator, Spinne, Inc.
http://www.spinne.com/usenet/
--------------57DA24E750E5DB6133469157
Content-Type: text/plain; charset=us-ascii; name="history-lookup.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="history-lookup.patch"
*** ../inn-1.5.1/innd/his.c Tue Dec 17 09:40:40 1996
--- innd/his.c Wed Jun 4 23:54:22 1997
***************
*** 1,4 ****
! /* $Revision: 1.23 $
**
** History file routines.
*/
--- 1,4 ----
! /* $Revision: 1.2+histcache$
**
** History file routines.
*/
***************
*** 9,14 ****
--- 9,27 ----
#include "innd.h"
#include "dbz.h"
+ /*
+ * history lookup cache
+ */
+ #define HISCACHESIZE (64 * 1024L) /* num elements in lookup cache array */
+
+ typedef struct {
+ long MessageIDHash;
+ BOOL Found;
+ } _HIScache;
+
+ STATIC _HIScache HIScache[HISCACHESIZE];
+ unsigned long HIScachehits;
+ unsigned long HIScachelookups;
STATIC char HIShistpath[] = _PATH_HISTORY;
STATIC FILE *HISwritefp;
***************
*** 46,51 ****
--- 59,68 ----
exit(1);
}
}
+
+ /* initialize history lookup cache data */
+ memset((void *)&HIScache, 0, sizeof(HIScache));
+ HIScachehits = HIScachelookups = 0;
}
***************
*** 84,89 ****
--- 101,109 ----
syslog(L_ERROR, "%s cant close history %m", LogName);
HISreadfd = -1;
}
+
+ syslog(L_NOTICE, "SERVER history cache final: %lu lookups, %lu hits",
+ HIScachelookups, HIScachehits);
}
***************
*** 198,206 ****
--- 218,245 ----
{
datum key;
datum val;
+ long hash_pos, hash_val;
+
+ /* hash msg id */
+ hash_val = dbzhash(MessageID, strlen(MessageID));
+ hash_pos = hash_val % HISCACHESIZE;
+
+ /* check history lookup cache for hashed msg id */
+ HIScachelookups++;
+ if (HIScache[hash_pos].MessageIDHash == hash_val) {
+ HIScachehits++;
+ return HIScache[hash_pos].Found;
+ }
+ /* check dbz history for msg id */
HISsetkey(MessageID, &key);
val = dbzfetch(key);
+
+ /* store hashed msg id, lookup result in history lookup cache */
+ HIScache[hash_pos].MessageIDHash = hash_val;
+ HIScache[hash_pos].Found = (char)(val.dptr != NULL);
+
+ /* return result of lookup */
return val.dptr != NULL;
}
***************
*** 237,243 ****
char *paths;
{
static char NOPATHS[] = "";
! long offset;
datum key;
datum val;
int i;
--- 276,282 ----
char *paths;
{
static char NOPATHS[] = "";
! long offset, hash_val, hash_pos;
datum key;
datum val;
int i;
***************
*** 278,283 ****
--- 317,328 ----
IOError("history database", i);
return FALSE;
}
+
+ /* store hashed message id value in history lookup cache */
+ hash_val = dbzhash(Data->MessageID, strlen(Data->MessageID));
+ hash_pos = hash_val % HISCACHESIZE;
+ HIScache[hash_pos].MessageIDHash = hash_val;
+ HIScache[hash_pos].Found = TRUE;
if (++HISdirty >= ICD_SYNC_COUNT)
HISsync();
--------------57DA24E750E5DB6133469157--
Technical Details
Message-ID:
<33963E5D.25DB7FE6@spinne.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mailShow Full Headers
Complete Article Headers
Message-ID: <33963E5D.25DB7FE6@spinne.com> Subject: INN history lookup cache (patch) Date: Thu, 05 Jun 1997 00:00:00 +0000 From: Jeff Garzik <jeff.garzik@spinne.com> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail X-Deja-AN: 246223376 Organization: Spinne http://spinne.com Newsgroups: news.software.nntp