🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #30448

GROUP command speedup for INN 2.1

#30448
From: Fluffy
Date: Wed, 12 Aug 1998 00:00
255 lines
7408 bytes
As per recent discussion, here is some go-go juice for the GROUP
command.  Tested only with traditional spool, where it's going to offer
the biggest win.

GROUP normally walks through the newsgroup to build the article array. 
This requires a scan of the spool directory, and is a horribly slow way
for newsreaders just to display new counts.  It can't be doing much
good for the server, either.

With this patch, we cheat.  Instead of returning a verified low and
high marks and a count, we just return the values from active.  The
count is a simple subtraction, and will tend to run high on servers
that process cancels.  I'm told that some clients out there will gag if
the count is high, but this estimate is allowed in both RFC977 and (in
detail) the last update draft I checked, so those clients are broken :P'

If a STAT, HEAD, BODY, ARTICLE, NEXT, LAST, XHDR, XOVER or XPAT follows
the GROUP command, we go out and scan the directory for real, and then
have a valid article array for all subsequent commands within that
group.  Also LISTGROUP will still properly load the array.

Patches for article.c, group.c and nnrpd.h, against INN 2.1 (release).

Meow.

=====begin=====
*** article.c.dist	Wed Aug 12 02:25:29 1998
--- article.c	Wed Aug 12 03:11:36 1998
***************
*** 80,85 ****
--- 80,89 ----
      SThead,	NNTP_HEAD_FOLLOWS_VAL,		"head"
  };
  
+ #ifdef FASTGROUPCMD
+ extern void GRPcleardirty(char *froup);
+ #endif
+ 
  extern unsigned int RARTtable[];
  extern int RARTcount;
  extern int RARTenable;
***************
*** 757,762 ****
--- 761,771 ----
  	return;
      }
  
+ #ifdef FASTGROUPCMD
+     if (GRPdirty)
+ 	GRPcleardirty(GRPlast);
+ #endif /*FASTGROUPCMD*/
+ 
      /* Default is to get current article, or specified article. */
      if (ac == 1) {
  	if (ARTindex < 0 || ARTindex >= ARTsize) {
***************
*** 828,833 ****
--- 837,848 ----
  	return;
      }
  
+ #ifdef FASTGROUPCMD
+     if (GRPdirty)
+ 	GRPcleardirty(GRPlast);
+ #endif /*FASTGROUPCMD*/
+ 
+ 
      next = (av[0][0] == 'n' || av[0][0] == 'N');
      if (next) {
  	delta = 1;
***************
*** 1462,1468 ****
--- 1477,1490 ----
  	return;
      }
  
+ 
      /* Range specified. */
+ 
+ #ifdef FASTGROUPCMD
+     if ((GRPcount != 0) && (GRPdirty))
+ 	GRPcleardirty(GRPlast);
+ #endif /*FASTGROUPCMD*/
+ 
      if (!CMDgetrange(ac - 1, av + 1, &range, &DidReply)) {
  	if (!DidReply) {
  	    Reply("%d %s fields follow\r\n", NNTP_HEAD_FOLLOWS_VAL,
***************
*** 1529,1534 ****
--- 1551,1561 ----
  	return;
      }
  
+ #ifdef FASTGROUPCMD
+     if (GRPdirty)
+ 	GRPcleardirty(GRPlast);
+ #endif /*FASTGROUPCMD*/
+ 
      /* Parse range. */
      gettimeofday(&stv, NULL);
      if (!CMDgetrange(ac, av, &range, &DidReply)) {
***************
*** 1644,1649 ****
--- 1671,1682 ----
      }
  
      /* Range specified. */
+ 
+ #ifdef FASTGROUPCMD
+     if ((GRPcount != 0) && (GRPdirty))
+ 	GRPcleardirty(GRPlast);
+ #endif /*FASTGROUPCMD*/
+ 
      if (!CMDgetrange(ac - 1, av + 1, &range, &DidReply)) {
  	if (!DidReply) {
  	    Reply("%d %s matches follow\r\n", NNTP_HEAD_FOLLOWS_VAL,
*** group.c.dist	Wed Aug 12 01:44:03 1998
--- group.c	Wed Aug 12 03:52:23 1998
***************
*** 564,570 ****
      return ((ARTLIST *)p1)->ArtNum - ((ARTLIST *)p2)->ArtNum;
  }
  
- 
  /*
  **  Fill in ARTnumbers with the numbers of the articles in the current
  **  group.
--- 564,569 ----
***************
*** 584,590 ****
--- 583,591 ----
      OVERINDEX           index;
  
      ARTsize = 0;
+ #ifndef FASTGROUPCMD
      GRPcount++;
+ #endif
  
      path = NEW(char, strlen(innconf->pathoverview) + strlen(dir) +
  				strlen(innconf->overviewname) + 32);
***************
*** 679,684 ****
--- 680,707 ----
  }
  
  
+ #ifdef FASTGROUPCMD
+ /*
+ ** Do a GRPscandir on the supplied newsfroup.
+ */
+ void GRPcleardirty(char *froup)
+ {
+     char		buff[SPOOLNAMEBUFF];
+     char	        *p;
+ 
+     /* Make the group name a directory name. */
+     if (buff != froup)
+ 	(void)strcpy(buff, froup);
+     for (p = buff; *p; p++)
+ 	if (*p == '.')
+ 	    *p = '/';
+ 	    
+     GRPscandir(buff);
+     GRPdirty = FALSE;
+ }
+ #endif /*FASTGROUPCMD*/
+ 
+ 
  /*
  **  Change to or list the specified newsgroup.  If invalid, stay in the old
  **  group.
***************
*** 748,754 ****
--- 771,782 ----
      /* If we haven't been in the group recently, rescan. */
      (void)time(&now);
      if (!EQ(buff, GRPlast) || now > last_time + NNRP_RESCAN_DELAY) {
+ #ifndef FASTGROUPCMD
  	GRPscandir(buff);
+ #else
+ 	GRPdirty = TRUE;
+ 	GRPcount++;
+ #endif /*FASTGROUPCMD*/
  	(void)strcpy(GRPlast, buff);
  	last_time = now;
      }
***************
*** 758,772 ****
--- 786,821 ----
  
      /* Doing a "group" command? */
      if (caseEQ(av[0], "group")) {
+ #ifndef FASTGROUPCMD
  	if (ARTsize == 0)
  	    Reply("%d 0 0 0 %s\r\n", NNTP_GROUPOK_VAL, group);
  	else
  	    Reply("%d %d %ld %ld %s\r\n",
  		NNTP_GROUPOK_VAL,
  		ARTsize, ARTnumbers[0].ArtNum, ARTnumbers[ARTsize - 1].ArtNum, group);
+ #else
+ 	/* We fake the article count from active. */
+         GROUPENTRY *gp = GRPfind(group);
+         long gphigh = GPHIGH(gp);
+         long gplow = GPLOW(gp);
+         ARTsize = gphigh - gplow + 1;
+         if ((gp) && (ARTsize > 0)) {
+             grplist[0] = av[2];
+             grplist[1] = NULL;
+ 	    Reply("%d %ld %ld %ld %s\r\n",
+ 		  NNTP_GROUPOK_VAL,
+ 		  ARTsize, gplow, gphigh, group);
+ 	}
+         else {
+ 	    Reply("%d 0 0 0 %s\r\n", NNTP_GROUPOK_VAL, group);
+         }
+ #endif /*FASTGROUPCMD*/
      }
      else {
  	/* Must be doing a "listgroup" command. */
+ #ifdef FASTGROUPCMD
+ 	GRPcleardirty(buff);
+ #endif /*FASTGROUPCMD*/
  	Reply("%d Article list follows\r\n", NNTP_GROUPOK_VAL);
  	for (i = 0; i < ARTsize; i++)
  	    Printf("%ld\r\n", ARTnumbers[i].ArtNum);
*** nnrpd.h.dist	Wed Aug 12 01:45:02 1998
--- nnrpd.h	Wed Aug 12 03:11:25 1998
***************
*** 38,43 ****
--- 38,48 ----
  #define ART_LINE_MALLOC		1024
  #define ART_MAX			1024
  
+ /*
+ ** define this to delay GRPscandir to speed up the GROUP command.
+ ** undef to restore stock behavior.
+ */
+ #define FASTGROUPCMD
  
  /*
  **  Some convenient shorthands.
***************
*** 148,153 ****
--- 153,159 ----
  EXTERN long	GRParticles;
  EXTERN long	GRPcount;
  EXTERN char	GRPlast[SPOOLNAMEBUFF];
+ EXTERN BOOL	GRPdirty;	/* Still need to call GRPscandir? */
  EXTERN long	POSTreceived;
  EXTERN long	POSTrejected;
  
=====end=====


Technical Details
Message-ID: <6qrl31$f95$1@fluffy.meow.org>
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

Show Full Headers
Complete Article Headers
Message-ID: <6qrl31$f95$1@fluffy.meow.org>
Subject: GROUP command speedup for INN 2.1
Date: Wed, 12 Aug 1998 00:00:00 +0000
From: fluffy@meow.org (Fluffy)
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: 380340779
X-Mail2News-Path: news.demon.net!fluffy.meow.org
X-Trace: mail2news.demon.co.uk 902911905 mail2news:7115 mail2news mail2news.demon.co.uk
Organization: MEOW
NNTP-Posting-Date: 12 Aug 1998 08:51:45 GMT
Newsgroups: news.software.nntp
X-Complaints-To: abuse@demon.net