🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nntp
3 messages
3 total messages Started by Jeff Garzik Thu, 05 Jun 1997 00:00
INN history lookup cache (patch)
#18283
Author: Jeff Garzik
Date: Thu, 05 Jun 1997 00:00
158 lines
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--


Re: INN history lookup cache (patch)
#18303
Author: Jeff Garzik
Date: Thu, 05 Jun 1997 00:00
90 lines
2683 bytes
This is a multi-part message in MIME format.

--------------77717925422134E07AF2910D
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

The history cache patch needs this patch to rename the DBZ hash
function, if you haven't already applied it.
-- 
Jeff Garzik
News Administrator, Spinne, Inc.
http://www.spinne.com/usenet/

--------------77717925422134E07AF2910D
Content-Type: text/plain; charset=us-ascii; name="dbz-hash-rename.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="dbz-hash-rename.patch"

diff --context -r --ignore-space-change ../inn-1.5.1/dbz/dbz.c dbz/dbz.c
*** ../inn-1.5.1/dbz/dbz.c	Tue Dec 17 09:40:40 1996
--- dbz/dbz.c	Mon Jun  2 05:24:59 1997
***************
*** 355,361 ****
  extern void CloseOnExec();
  
  /* misc. forwards */
- static long hash();
  static void crcinit();
  static char *cipoint();
  static char *mapcase();
--- 355,360 ----
***************
*** 1426,1432 ****
  {
  	register long h;
  
! 	h = hash(kp->dptr, kp->dsize);
  	if (osp != FRESH && osp->hash == h) {
  		if (sp != osp)
  			*sp = *osp;
--- 1425,1431 ----
  {
  	register long h;
  
! 	h = dbzhash(kp->dptr, kp->dsize);
  	if (osp != FRESH && osp->hash == h) {
  		if (sp != osp)
  			*sp = *osp;
***************
*** 1716,1725 ****
  }
  
  /*
!  - hash - Honeyman's nice hashing function
   */
! static long
! hash(name, size)
  register char *name;
  register int size;
  {
--- 1715,1724 ----
  }
  
  /*
!  - dbzhash - Honeyman's nice hashing function
   */
! long
! dbzhash(name, size)
  register char *name;
  register int size;
  {
diff --context -r --ignore-space-change ../inn-1.5.1/dbz/dbz.h dbz/dbz.h
*** ../inn-1.5.1/dbz/dbz.h	Tue Dec 17 09:40:40 1996
--- dbz/dbz.h	Mon Jun  2 05:24:59 1997
***************
*** 24,29 ****
--- 24,30 ----
  extern int dbzcancel();
  extern int dbzdebug();
  extern int dbzwritethrough();
+ extern long dbzhash();
  
  /*
   * In principle we could handle unlimited-length keys by operating a chunk

--------------77717925422134E07AF2910D--


Re: INN history lookup cache (patch)
#18526
Author: Mike Pelletier
Date: Thu, 19 Jun 1997 00:00
13 lines
901 bytes
In article <33963E5D.25DB7FE6@spinne.com>,
	Jeff Garzik  <jeff.garzik@spinne.com> wrote:
>
>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.

Yes, but what kind of performance benefits do you see as a result of
this hit rate?

	-Mike Pelletier.

Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads