| 1 |
--- inn-1.7.2.orig/innd/his.c |
| 2 |
+++ inn-1.7.2/innd/his.c |
| 3 |
@@ -1,4 +1,4 @@ |
| 4 |
-/* $Revision: 1.23 $ |
| 5 |
+/* $Revision: 1.2+histcache$ |
| 6 |
** |
| 7 |
** History file routines. |
| 8 |
*/ |
| 9 |
@@ -8,7 +8,21 @@ |
| 10 |
#include "clibrary.h" |
| 11 |
#include "innd.h" |
| 12 |
#include "dbz.h" |
| 13 |
+#if defined(TIMER) |
| 14 |
+#include "timer.h" |
| 15 |
+#endif /* defined(TIMER) */ |
| 16 |
|
| 17 |
+/* |
| 18 |
+ * history lookup cache |
| 19 |
+ */ |
| 20 |
+#define HISCACHESIZE (64 * 1024L) /* num elements in lookup cache array */ |
| 21 |
+typedef struct { |
| 22 |
+ long MessageIDHash; |
| 23 |
+ BOOL Found; |
| 24 |
+} _HIScache; |
| 25 |
+STATIC _HIScache HIScache[HISCACHESIZE]; |
| 26 |
+unsigned long HIScachehits; |
| 27 |
+unsigned long HIScachelookups; |
| 28 |
|
| 29 |
STATIC char HIShistpath[] = _PATH_HISTORY; |
| 30 |
STATIC FILE *HISwritefp; |
| 31 |
@@ -16,6 +30,8 @@ |
| 32 |
STATIC int HISdirty; |
| 33 |
STATIC int HISincore = INND_DBZINCORE; |
| 34 |
|
| 35 |
+#include "timer.h" |
| 36 |
+ |
| 37 |
|
| 38 |
/* |
| 39 |
** Set up the history files. |
| 40 |
@@ -46,6 +62,9 @@ |
| 41 |
exit(1); |
| 42 |
} |
| 43 |
} |
| 44 |
+ /* initialize history lookup cache data */ |
| 45 |
+ memset((void *)&HIScache, 0, sizeof(HIScache)); |
| 46 |
+ HIScachehits = HIScachelookups = 0; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
@@ -55,6 +74,9 @@ |
| 51 |
void |
| 52 |
HISsync() |
| 53 |
{ |
| 54 |
+#if defined(TIMER) |
| 55 |
+ TMRstart(TMR_HISSYNC); |
| 56 |
+#endif /* defined(TIMER) */ |
| 57 |
if (HISdirty) { |
| 58 |
if (dbzsync()) { |
| 59 |
syslog(L_FATAL, "%s cant dbzsync %m", LogName); |
| 60 |
@@ -62,6 +84,9 @@ |
| 61 |
} |
| 62 |
HISdirty = 0; |
| 63 |
} |
| 64 |
+#if defined(TIMER) |
| 65 |
+ TMRstop(TMR_HISSYNC); |
| 66 |
+#endif /* defined(TIMER) */ |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
@@ -84,6 +109,10 @@ |
| 71 |
syslog(L_ERROR, "%s cant close history %m", LogName); |
| 72 |
HISreadfd = -1; |
| 73 |
} |
| 74 |
+ |
| 75 |
+ if (HIScachelookups > 0) |
| 76 |
+ syslog(L_NOTICE, "SERVER history cache final: %lu lookups, %lu hits", |
| 77 |
+ HIScachelookups, HIScachehits); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
@@ -138,8 +167,14 @@ |
| 82 |
register int i; |
| 83 |
|
| 84 |
/* Get the seek value into the history file. */ |
| 85 |
+#if defined(TIMER) |
| 86 |
+ TMRstart(TMR_HISGREP); |
| 87 |
+#endif /* defined(TIMER) */ |
| 88 |
HISsetkey(MessageID, &key); |
| 89 |
val = dbzfetch(key); |
| 90 |
+#if defined(TIMER) |
| 91 |
+ TMRstop(TMR_HISGREP); |
| 92 |
+#endif /* defined(TIMER) */ |
| 93 |
if (val.dptr == NULL || val.dsize != sizeof offset) |
| 94 |
return NULL; |
| 95 |
|
| 96 |
@@ -198,9 +233,36 @@ |
| 97 |
{ |
| 98 |
datum key; |
| 99 |
datum val; |
| 100 |
+ long hash_pos, hash_val; |
| 101 |
|
| 102 |
+ |
| 103 |
+ /* hash msg id */ |
| 104 |
+ hash_val = dbzhash(MessageID, strlen(MessageID)); |
| 105 |
+ hash_pos = hash_val % HISCACHESIZE; |
| 106 |
+ |
| 107 |
+ /* check history lookup cache for hashed msg id */ |
| 108 |
+ HIScachelookups++; |
| 109 |
+ if (HIScache[hash_pos].MessageIDHash == hash_val) { |
| 110 |
+ HIScachehits++; |
| 111 |
+ return HIScache[hash_pos].Found; |
| 112 |
+ } |
| 113 |
+ |
| 114 |
+ /* check dbz history for msg id */ |
| 115 |
+#if defined(TIMER) |
| 116 |
+ TMRstart(TMR_HISHAVE); |
| 117 |
+#endif /* defined(TIMER) */ |
| 118 |
HISsetkey(MessageID, &key); |
| 119 |
val = dbzfetch(key); |
| 120 |
+ |
| 121 |
+ /* store hashed msg id, lookup result in history lookup cache */ |
| 122 |
+ HIScache[hash_pos].MessageIDHash = hash_val; |
| 123 |
+ HIScache[hash_pos].Found = (char)(val.dptr != NULL); |
| 124 |
+ |
| 125 |
+#if defined(TIMER) |
| 126 |
+ TMRstop(TMR_HISHAVE); |
| 127 |
+#endif /* defined(TIMER) */ |
| 128 |
+ |
| 129 |
+ /* return result of lookup */ |
| 130 |
return val.dptr != NULL; |
| 131 |
} |
| 132 |
|
| 133 |
@@ -237,11 +299,14 @@ |
| 134 |
char *paths; |
| 135 |
{ |
| 136 |
static char NOPATHS[] = ""; |
| 137 |
- long offset; |
| 138 |
+ long offset, hash_val, hash_pos; |
| 139 |
datum key; |
| 140 |
datum val; |
| 141 |
int i; |
| 142 |
|
| 143 |
+#if defined(TIMER) |
| 144 |
+ TMRstart(TMR_HISWRITE); |
| 145 |
+#endif /* defined(TIMER) */ |
| 146 |
HISsetkey(Data->MessageID, &key); |
| 147 |
if (paths != NULL && paths[0] != '\0') |
| 148 |
HISslashify(paths); |
| 149 |
@@ -268,6 +333,9 @@ |
| 150 |
i = errno; |
| 151 |
syslog(L_ERROR, "%s cant write history %m", LogName); |
| 152 |
IOError("history", i); |
| 153 |
+#if defined(TIMER) |
| 154 |
+ TMRstop(TMR_HISWRITE); |
| 155 |
+#endif /* defined(TIMER) */ |
| 156 |
return FALSE; |
| 157 |
} |
| 158 |
|
| 159 |
@@ -278,8 +346,19 @@ |
| 160 |
i = errno; |
| 161 |
syslog(L_ERROR, "%s cant dbzstore %m", LogName); |
| 162 |
IOError("history database", i); |
| 163 |
+#if defined(TIMER) |
| 164 |
+ TMRstop(TMR_HISWRITE); |
| 165 |
+#endif /* defined(TIMER) */ |
| 166 |
return FALSE; |
| 167 |
} |
| 168 |
+#if defined(TIMER) |
| 169 |
+ TMRstop(TMR_HISWRITE); |
| 170 |
+#endif /* defined(TIMER) */ |
| 171 |
+ /* store hashed message id value in history lookup cache */ |
| 172 |
+ hash_val = dbzhash(Data->MessageID, strlen(Data->MessageID)); |
| 173 |
+ hash_pos = hash_val % HISCACHESIZE; |
| 174 |
+ HIScache[hash_pos].MessageIDHash = hash_val; |
| 175 |
+ HIScache[hash_pos].Found = TRUE; |
| 176 |
|
| 177 |
if (++HISdirty >= ICD_SYNC_COUNT) |
| 178 |
HISsync(); |
| 179 |
--- inn-1.7.2.orig/innd/nc.c |
| 180 |
+++ inn-1.7.2/innd/nc.c |
| 181 |
@@ -1,4 +1,4 @@ |
| 182 |
-/* $Revision: 1.51 $ |
| 183 |
+/* $Revision: 1.51+precommit-cache$ |
| 184 |
** |
| 185 |
** Routines for the NNTP channel. Other channels get the descriptors which |
| 186 |
** we turn into NNTP channels, and over which we speak NNTP. |
| 187 |
@@ -107,6 +108,45 @@ |
| 188 |
|
| 189 |
|
| 190 |
/* |
| 191 |
+ * precommit cache |
| 192 |
+ */ |
| 193 |
+#define NCPRECOMCACHESIZE 4096L |
| 194 |
+#define NCPRECOMCACHETIMEOUT 30 |
| 195 |
+ |
| 196 |
+/* uncomment line below to: |
| 197 |
+ * - zap cache entry after art acceptance or rejection |
| 198 |
+ */ |
| 199 |
+/* #define NCPRECOM_PEDANTIC */ |
| 200 |
+ |
| 201 |
+/* uncomment line below to: |
| 202 |
+ * - have CHECK return DEFER instead of REFUSE |
| 203 |
+ * for cache hits |
| 204 |
+ */ |
| 205 |
+/* #define NCPRECOM_DEFER */ |
| 206 |
+ |
| 207 |
+typedef struct { |
| 208 |
+ long MessageIDHash; |
| 209 |
+ time_t Timestamp; |
| 210 |
+} _NCprecomcache; |
| 211 |
+ |
| 212 |
+STATIC _NCprecomcache NCprecomcache[NCPRECOMCACHESIZE]; |
| 213 |
+unsigned long NCprecomhits; |
| 214 |
+unsigned long NCprecomlookups; |
| 215 |
+STATIC long NCprecompos, NCprecomval; |
| 216 |
+STATIC NCprecominit = 0; |
| 217 |
+ |
| 218 |
+ |
| 219 |
+STATIC void |
| 220 |
+NCprecomclear () |
| 221 |
+{ |
| 222 |
+ memset((void *)&NCprecomcache, 0, sizeof(NCprecomcache)); |
| 223 |
+ NCprecomhits = NCprecomlookups = 0; |
| 224 |
+} |
| 225 |
+ |
| 226 |
+ |
| 227 |
+ |
| 228 |
+ |
| 229 |
+/* |
| 230 |
** Clear the work-in-progress entry and wake up anyone who might |
| 231 |
** have been waiting for us. |
| 232 |
*/ |
| 233 |
@@ -264,6 +304,11 @@ |
| 234 |
} |
| 235 |
cp->State = CSgetcmd; |
| 236 |
NCwritereply(cp, response); |
| 237 |
+#ifdef NCPRECOM_PEDANTIC |
| 238 |
+ NCprecomval = dbzhash(wp->MessageID, strlen(wp->MessageID)); |
| 239 |
+ NCprecompos = NCprecomval % NCPRECOMCACHESIZE; |
| 240 |
+ NCprecomcache[NCprecompos].MessageIDHash = 0L; |
| 241 |
+#endif |
| 242 |
break; |
| 243 |
|
| 244 |
case OMthrottled: |
| 245 |
@@ -343,7 +388,7 @@ |
| 246 |
} |
| 247 |
|
| 248 |
/* Write the terminator. */ |
| 249 |
- WCHANappend(cp, NCdotterm, STRLEN(NCdotterm)); |
| 250 |
+ NCwritereply(cp, NCdot); /* Was WCHANappend. fixed 1997/10/31 [email protected] */ |
| 251 |
} |
| 252 |
#endif /* 0 */ |
| 253 |
|
| 254 |
@@ -382,7 +427,7 @@ |
| 255 |
} |
| 256 |
|
| 257 |
/* Write the terminator. */ |
| 258 |
- NCwritereply(cp, NCdot); |
| 259 |
+ NCwritereply(cp, NCdot); /* Was WCHANappend. fixed 1997/10/31 [email protected] */ |
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
@@ -595,7 +640,20 @@ |
| 264 |
if (NCbadid(cp, p)) |
| 265 |
return; |
| 266 |
|
| 267 |
- if (HIShavearticle(p)) { |
| 268 |
+ /* compute msg id hash for pre-commit cache check */ |
| 269 |
+ NCprecomval = dbzhash(p, strlen(p)); |
| 270 |
+ NCprecompos = NCprecomval % NCPRECOMCACHESIZE; |
| 271 |
+ NCprecomlookups++; |
| 272 |
+ |
| 273 |
+ /* check pre-commit cache for msg id, with timeout */ |
| 274 |
+ if ((NCprecomcache[NCprecompos].MessageIDHash == NCprecomval) && |
| 275 |
+ ((NCprecomcache[NCprecompos].Timestamp + NCPRECOMCACHETIMEOUT) > Now.time)) { |
| 276 |
+ NCprecomhits++; |
| 277 |
+ cp->Refused++; |
| 278 |
+ NCwritereply(cp, NNTP_HAVEIT); |
| 279 |
+ } |
| 280 |
+ |
| 281 |
+ else if (HIShavearticle(p)) { |
| 282 |
cp->Refused++; |
| 283 |
NCwritereply(cp, NNTP_HAVEIT); |
| 284 |
} |
| 285 |
@@ -612,6 +670,9 @@ |
| 286 |
#endif /* defined(NNTP_RESENDIT_LATER) */ |
| 287 |
} |
| 288 |
else { |
| 289 |
+ /* pre-commit msg id so that noone else offers us this for 30 seconds */ |
| 290 |
+ NCprecomcache[NCprecompos].MessageIDHash = NCprecomval; |
| 291 |
+ NCprecomcache[NCprecompos].Timestamp = Now.time; |
| 292 |
cp->State = CSgetarticle; |
| 293 |
NCwritereply(cp, NNTP_SENDIT); |
| 294 |
} |
| 295 |
@@ -1409,6 +1474,14 @@ |
| 296 |
register CHANNEL *cp; |
| 297 |
int i; |
| 298 |
|
| 299 |
+ /* one-time initialization of pre-commit cache */ |
| 300 |
+ if (!NCprecominit) { |
| 301 |
+ NCprecomclear(); |
| 302 |
+ NCprecominit = 1; |
| 303 |
+ syslog(L_NOTICE, "Pre-commit cache initialized: %ld entries, %ld bytes", |
| 304 |
+ NCPRECOMCACHESIZE, (long) sizeof(NCprecomcache)); |
| 305 |
+ } |
| 306 |
+ |
| 307 |
/* Create the channel. */ |
| 308 |
cp = CHANcreate(fd, CTnntp, MustAuthorize ? CSgetauth : CSgetcmd, |
| 309 |
NCreader, NCwritedone); |
| 310 |
@@ -1484,6 +1557,12 @@ |
| 311 |
int msglen; |
| 312 |
WIP *who; |
| 313 |
|
| 314 |
+#if defined(DO_PERL) |
| 315 |
+ char *perlrc; |
| 316 |
+#endif /* DO_PERL */ |
| 317 |
+ |
| 318 |
+ |
| 319 |
+ |
| 320 |
if (AmSlave) { |
| 321 |
NCwritereply(cp, NCbadcommand); |
| 322 |
return; |
| 323 |
@@ -1508,14 +1587,51 @@ |
| 324 |
return; |
| 325 |
} |
| 326 |
|
| 327 |
- if (HIShavearticle(p)) { |
| 328 |
+#if defined(DO_PERL) |
| 329 |
+ /* invoke a perl message filter on the message id */ |
| 330 |
+ else if ((perlrc = (char *)HandleMessageID(p)) != NULL) { |
| 331 |
+ cp->Refused++; |
| 332 |
+ (void)sprintf(cp->Sendid.Data, "%d %s", NNTP_ERR_GOTID_VAL, p); |
| 333 |
+ NCwritereply(cp, cp->Sendid.Data); |
| 334 |
+ } |
| 335 |
+#endif |
| 336 |
+ |
| 337 |
+ /* compute msg id hash for pre-commit cache check */ |
| 338 |
+ NCprecomval = dbzhash(p, msglen - 5); |
| 339 |
+ NCprecompos = NCprecomval % NCPRECOMCACHESIZE; |
| 340 |
+ NCprecomlookups++; |
| 341 |
+ |
| 342 |
+ /* check pre-commit cache for msg id, with timeout */ |
| 343 |
+ if ((NCprecomcache[NCprecompos].MessageIDHash == NCprecomval) && |
| 344 |
+ ((NCprecomcache[NCprecompos].Timestamp + NCPRECOMCACHETIMEOUT) > Now.time)) { |
| 345 |
+ NCprecomhits++; |
| 346 |
+ |
| 347 |
+#ifdef NCPRECOM_DEFER |
| 348 |
+ (void)sprintf(cp->Sendid.Data, "%d %s", NNTP_RESENDID_VAL, p); |
| 349 |
+#else |
| 350 |
+ cp->Refused++; |
| 351 |
+ (void)sprintf(cp->Sendid.Data, "%d %s", NNTP_ERR_GOTID_VAL, p); |
| 352 |
+#endif |
| 353 |
+ NCwritereply(cp, cp->Sendid.Data); |
| 354 |
+ } |
| 355 |
+ |
| 356 |
+ /* check history for msg id existence */ |
| 357 |
+ else if (HIShavearticle(p)) { |
| 358 |
cp->Refused++; |
| 359 |
(void)sprintf(cp->Sendid.Data, "%d %s", NNTP_ERR_GOTID_VAL, p); |
| 360 |
NCwritereply(cp, cp->Sendid.Data); |
| 361 |
+ |
| 362 |
+ /* check to see if article's already in progress on some other channel */ |
| 363 |
} else if (NCinprogress(cp, p, &who)) { |
| 364 |
(void)sprintf(cp->Sendid.Data, "%d %s", NNTP_RESENDID_VAL, p); |
| 365 |
NCwritereply(cp, cp->Sendid.Data); |
| 366 |
+ |
| 367 |
+ /* otherwise, we don't have the message, tell remote to send it to us */ |
| 368 |
} else { |
| 369 |
+ /* pre-commit msg id so that noone else offers us this for 30 seconds */ |
| 370 |
+ NCprecomcache[NCprecompos].MessageIDHash = NCprecomval; |
| 371 |
+ NCprecomcache[NCprecompos].Timestamp = Now.time; |
| 372 |
+ |
| 373 |
(void)sprintf(cp->Sendid.Data, "%d %s", NNTP_OK_SENDID_VAL, p); |
| 374 |
NCwritereply(cp, cp->Sendid.Data); |
| 375 |
} |
| 376 |
@@ -1540,10 +1656,21 @@ |
| 377 |
continue; |
| 378 |
for ( ; ISWHITE(*p); p++) |
| 379 |
continue; |
| 380 |
+ |
| 381 |
+ msglen = strlen(p) + 5; /* 3 digits + space + id + null */ |
| 382 |
+ |
| 383 |
if (!ARTidok(p)) { |
| 384 |
syslog(L_NOTICE, "%s bad_messageid %s", CHANname(cp), MaxLength(p, p)); |
| 385 |
} |
| 386 |
- msglen = strlen(p) + 5; /* 3 digits + space + id + null */ |
| 387 |
+ |
| 388 |
+ /* pre-commit msg id so that noone else offers us this for 30 seconds */ |
| 389 |
+ else { |
| 390 |
+ NCprecomval = dbzhash(p, msglen - 5); |
| 391 |
+ NCprecompos = NCprecomval % NCPRECOMCACHESIZE; |
| 392 |
+ NCprecomcache[NCprecompos].MessageIDHash = NCprecomval; |
| 393 |
+ NCprecomcache[NCprecompos].Timestamp = Now.time; |
| 394 |
+ } |
| 395 |
+ |
| 396 |
if (cp->Sendid.Size < msglen) { |
| 397 |
if (cp->Sendid.Size > 0) DISPOSE(cp->Sendid.Data); |
| 398 |
if (msglen > MAXHEADERSIZE) cp->Sendid.Size = msglen; |
| 399 |
--- inn-1.7.2.orig/innd/cc.c |
| 400 |
+++ inn-1.7.2/innd/cc.c |
| 401 |
@@ -737,6 +744,10 @@ |
| 402 |
return "1 Not active"; |
| 403 |
} |
| 404 |
|
| 405 |
+extern unsigned long HIScachehits; |
| 406 |
+extern unsigned long HIScachelookups; |
| 407 |
+extern unsigned long NCprecomhits; |
| 408 |
+extern unsigned long NCprecomlookups; |
| 409 |
|
| 410 |
/* |
| 411 |
** Return our operating mode. |
| 412 |
@@ -746,6 +757,9 @@ |
| 413 |
CCmode(av) |
| 414 |
char *av[]; |
| 415 |
{ |
| 416 |
+#if defined(DO_PERL) |
| 417 |
+ dSP; |
| 418 |
+#endif |
| 419 |
register char *p; |
| 420 |
register int i; |
| 421 |
int h; |
| 422 |
@@ -842,9 +856,37 @@ |
| 423 |
p += strlen(strcpy(p, "enabled")); |
| 424 |
else |
| 425 |
p += strlen(strcpy(p, "disabled")); |
| 426 |
+ |
| 427 |
+ /* perl filter status */ |
| 428 |
+ |
| 429 |
+ if (perl_get_cv("filter_stats", FALSE) != NULL) { |
| 430 |
+ *p++ = '\n'; |
| 431 |
+ p += strlen(strcpy(p, "Perl filter stats: ")); |
| 432 |
+ |
| 433 |
+ ENTER ; |
| 434 |
+ SAVETMPS; |
| 435 |
+ |
| 436 |
+ perl_call_argv("filter_stats", G_EVAL|G_NOARGS, NULL); |
| 437 |
+ |
| 438 |
+ SPAGAIN; |
| 439 |
+ |
| 440 |
+ p += strlen(strcpy(p, POPp)); |
| 441 |
+ |
| 442 |
+ PUTBACK; |
| 443 |
+ FREETMPS; |
| 444 |
+ LEAVE; |
| 445 |
+ } |
| 446 |
+ |
| 447 |
#endif /* defined(DO_PERL) */ |
| 448 |
|
| 449 |
- i = strlen(buff); |
| 450 |
+ *p++ = '\n'; |
| 451 |
+ sprintf(p, "History cache: %lu lookups, %lu hits", HIScachelookups, HIScachehits); |
| 452 |
+ p += strlen(p); |
| 453 |
+ *p++ = '\n'; |
| 454 |
+ sprintf(p, "Precommit cache: %lu lookups, %lu hits", NCprecomlookups, NCprecomhits); |
| 455 |
+ p += strlen(p); |
| 456 |
+ |
| 457 |
+ i = strlen(buff); |
| 458 |
if (CCreply.Size <= i) { |
| 459 |
CCreply.Size = i; |
| 460 |
RENEW(CCreply.Data, char, CCreply.Size + 1); |
| 461 |
--- inn-1.7.2.orig/innd/chan.c |
| 462 |
+++ inn-1.7.2/innd/chan.c |
| 463 |
@@ -31,6 +31,8 @@ |
| 464 |
STATIC CHANNEL *CHANrc; |
| 465 |
#endif /* PRIORITISE_REMCONN */ |
| 466 |
|
| 467 |
+#include "timer.h" |
| 468 |
+ |
| 469 |
|
| 470 |
/* |
| 471 |
** Set a buffer's contents, ignoring anything that might have |
| 472 |
@@ -781,6 +793,10 @@ |
| 473 |
char *p; |
| 474 |
time_t LastUpdate; |
| 475 |
|
| 476 |
+#if defined(TIMER) |
| 477 |
+ TMRinit(); |
| 478 |
+#endif /* defined(TIMER) */ |
| 479 |
+ |
| 480 |
LastUpdate = GetTimeInfo(&Now) < 0 ? 0 : Now.time; |
| 481 |
for ( ; ; ) { |
| 482 |
/* See if any processes died. */ |
| 483 |
@@ -790,8 +806,17 @@ |
| 484 |
MyRead = RCHANmask; |
| 485 |
MyWrite = WCHANmask; |
| 486 |
MyTime = TimeOut; |
| 487 |
+#if defined(TIMER) |
| 488 |
+ i = TMRmainloophook(); |
| 489 |
+ if (i) |
| 490 |
+ MyTime.tv_sec = i; |
| 491 |
+ TMRstart(TMR_IDLE); |
| 492 |
+#endif /* defined(TIMER) */ |
| 493 |
count = select(CHANlastfd + 1, &MyRead, &MyWrite, (FDSET *)NULL, |
| 494 |
&MyTime); |
| 495 |
+#if defined(TIMER) |
| 496 |
+ TMRstop(TMR_IDLE); |
| 497 |
+#endif /* defined(TIMER) */ |
| 498 |
if (GotTerminate) { |
| 499 |
(void)write(2, EXITING, STRLEN(EXITING)); |
| 500 |
CleanupAndExit(0, (char *)NULL); |
| 501 |
--- inn-1.7.2.orig/innd/art.c |
| 502 |
+++ inn-1.7.2/innd/art.c |
| 503 |
@@ -10,6 +10,9 @@ |
| 504 |
#include "dbz.h" |
| 505 |
#include "art.h" |
| 506 |
#include <sys/uio.h> |
| 507 |
+#if defined(TIMER) |
| 508 |
+#include "timer.h" |
| 509 |
+#endif /* defined(TIMER) */ |
| 510 |
|
| 511 |
typedef struct iovec IOVEC; |
| 512 |
|
| 513 |
@@ -1725,6 +1768,7 @@ |
| 514 |
static BUFFER Files; |
| 515 |
static BUFFER Header; |
| 516 |
static char buff[SPOOLNAMEBUFF]; |
| 517 |
+ static char path[MAXHEADERSIZE]; |
| 518 |
register char *p; |
| 519 |
register int i; |
| 520 |
register int j; |
| 521 |
@@ -1757,6 +1803,18 @@ |
| 522 |
Data.MessageID = ihave; |
| 523 |
error = ARTclean(article, &Data); |
| 524 |
|
| 525 |
+ /* This makes me want to scream in agony and rip my eyeballs |
| 526 |
+ out. We clobber our Path: header all to hell later on, so |
| 527 |
+ we will preserve the data in a static buffer. I suppose |
| 528 |
+ we could have gone groveling around in the article buffer, |
| 529 |
+ but that seemed even worse, and more complex code. JG970605 */ |
| 530 |
+ strcpy(path, "?"); |
| 531 |
+ if (p = HDR(_path)) { |
| 532 |
+ sprintf(path, "%s", p); |
| 533 |
+ Data.Path = path; |
| 534 |
+ Data.PathLength = strlen(path); |
| 535 |
+ } |
| 536 |
+ |
| 537 |
/* Not much we can do here except toss it and report the error. */ |
| 538 |
if (error != NULL) { |
| 539 |
(void)sprintf(buff, "%d %s", NNTP_REJECTIT_VAL, |
| 540 |
@@ -2174,6 +2283,9 @@ |
| 541 |
ngp->PostCount = 0; |
| 542 |
|
| 543 |
if (Data.Name[0] == '\0') { |
| 544 |
+#if defined(TIMER) |
| 545 |
+ TMRstart(TMR_ARTWRITE); |
| 546 |
+#endif /* defined(TIMER) */ |
| 547 |
/* Write the article the first time. */ |
| 548 |
(void)sprintf(Data.Name, "%s/%lu", ngp->Dir, ngp->Filenum); |
| 549 |
if (ARTwrite(Data.Name, article, &Data) < 0 |
| 550 |
@@ -2192,12 +2304,21 @@ |
| 551 |
if (distributions) |
| 552 |
DISPOSE(distributions); |
| 553 |
ARTreject(buff, article); |
| 554 |
+#if defined(TIMER) |
| 555 |
+ TMRstop(TMR_ARTWRITE); |
| 556 |
+#endif /* defined (TIMER) */ |
| 557 |
return buff; |
| 558 |
} |
| 559 |
+#if defined(TIMER) |
| 560 |
+ TMRstop(TMR_ARTWRITE); |
| 561 |
+#endif /* defined(TIMER) */ |
| 562 |
p += strlen(strcpy(p, Data.Name)); |
| 563 |
Data.NameLength = strlen(Data.Name); |
| 564 |
} |
| 565 |
else { |
| 566 |
+#if defined(TIMER) |
| 567 |
+ TMRstart(TMR_ARTLINK); |
| 568 |
+#endif /* defined(TIMER) */ |
| 569 |
/* Link to the main article. */ |
| 570 |
(void)sprintf(linkname, "%s/%lu", ngp->Dir, ngp->Filenum); |
| 571 |
if (DoLinks && link(Data.Name, linkname) < 0 |
| 572 |
@@ -2223,6 +2344,9 @@ |
| 573 |
} |
| 574 |
#endif /* defined(DONT_HAVE_SYMLINK) */ |
| 575 |
} |
| 576 |
+#if defined(TIMER) |
| 577 |
+ TMRstop(TMR_ARTLINK); |
| 578 |
+#endif /* defined(TIMER) */ |
| 579 |
*p++ = ' '; |
| 580 |
p += strlen(strcpy(p, linkname)); |
| 581 |
} |
| 582 |
@@ -2279,11 +2403,25 @@ |
| 583 |
* has been processed. We could pause ourselves here, but it doesn't |
| 584 |
* seem to be worth it. */ |
| 585 |
if (Accepted) { |
| 586 |
- if (ControlHeader >= 0) |
| 587 |
+ if (ControlHeader >= 0) { |
| 588 |
+#if defined(TIMER) |
| 589 |
+ TMRstart(TMR_ARTCTRL); |
| 590 |
+#endif /* defined(TIMER) */ |
| 591 |
ARTcontrol(&Data, HDR(ControlHeader)); |
| 592 |
+#if defined(TIMER) |
| 593 |
+ TMRstop(TMR_ARTCTRL); |
| 594 |
+#endif /* defined(TIMER) */ |
| 595 |
+ } |
| 596 |
p = HDR(_supersedes); |
| 597 |
- if (*p && ARTidok(p)) |
| 598 |
+ if (*p && ARTidok(p)) { |
| 599 |
+#if defined(TIMER) |
| 600 |
+ TMRstart(TMR_ARTCNCL); |
| 601 |
+#endif /* defined(TIMER) */ |
| 602 |
ARTcancel(&Data, p, FALSE); |
| 603 |
+#if defined(TIMER) |
| 604 |
+ TMRstop(TMR_ARTCNCL); |
| 605 |
+#endif /* defined(TIMER) */ |
| 606 |
+ } |
| 607 |
} |
| 608 |
|
| 609 |
/* If we need the overview data, write it. */ |
| 610 |
@@ -2292,8 +2430,15 @@ |
| 611 |
|
| 612 |
/* And finally, send to everyone who should get it */ |
| 613 |
for (sp = Sites, i = nSites; --i >= 0; sp++) |
| 614 |
- if (sp->Sendit) |
| 615 |
+ if (sp->Sendit) { |
| 616 |
+#if defined(TIMER) |
| 617 |
+ TMRstart(TMR_SITESEND); |
| 618 |
+#endif /* defined(TIMER) */ |
| 619 |
SITEsend(sp, &Data); |
| 620 |
+#if defined(TIMER) |
| 621 |
+ TMRstop(TMR_SITESEND); |
| 622 |
+#endif /* defined(TIMER) */ |
| 623 |
+ } |
| 624 |
|
| 625 |
return NNTP_TOOKIT; |
| 626 |
} |
| 627 |
--- inn-1.7.2.orig/innd/Makefile |
| 628 |
+++ inn-1.7.2/innd/Makefile |
| 629 |
@@ -44,14 +44,18 @@ |
| 630 |
LINTLIB = ../llib-linn.ln |
| 631 |
## =()<TCL_LIB = @<TCL_LIB>@>()= |
| 632 |
TCL_LIB = |
| 633 |
+## =()<IDENT_LIB = @<IDENT_LIB>@>()= |
| 634 |
+IDENT_LIB = -lident |
| 635 |
+ |
| 636 |
+CFLAGS+= -DTIMER |
| 637 |
|
| 638 |
SOURCES = \ |
| 639 |
art.c cc.c chan.c his.c icd.c innd.c lc.c nc.c newsfeeds.c ng.c \ |
| 640 |
- proc.c rc.c site.c tcl.c perl.c |
| 641 |
+ proc.c rc.c site.c tcl.c perl.c timer.c |
| 642 |
|
| 643 |
OBJECTS = \ |
| 644 |
art.o cc.o chan.o his.o icd.o innd.o lc.o nc.o newsfeeds.o ng.o \ |
| 645 |
- proc.o rc.o site.o tcl.o perl.o |
| 646 |
+ proc.o rc.o site.o tcl.o perl.o timer.o |
| 647 |
|
| 648 |
ALL = innd inndstart |
| 649 |
|
| 650 |
@@ -68,7 +72,7 @@ |
| 651 |
$(CTAGS) $(SOURCES) ../lib/*.c innd.h ../include/*.h |
| 652 |
|
| 653 |
innd: $(P) $(OBJECTS) $(LIBNEWS) |
| 654 |
- $(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(LIBNEWS) $(TCL_LIB) $(PERLLIB) $(LIBS) |
| 655 |
+ $(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(LIBNEWS) $(TCL_LIB) $(PERLLIB) $(IDENT_LIB) $(LIBS) |
| 656 |
|
| 657 |
inndstart: $(P) inndstart.o $(LIBNEWS) |
| 658 |
$(CC) $(LDFLAGS) -o $@ inndstart.o $(LIBNEWS) $(LIBS) |
| 659 |
--- inn-1.7.2.orig/innd/timer.c |
| 660 |
+++ inn-1.7.2/innd/timer.c |
| 661 |
@@ -0,0 +1,149 @@ |
| 662 |
+#include <stdio.h> |
| 663 |
+#include <string.h> |
| 664 |
+#include <sys/time.h> |
| 665 |
+ |
| 666 |
+#include "logging.h" |
| 667 |
+#include "timer.h" |
| 668 |
+ |
| 669 |
+unsigned start[MAXTIMERS]; |
| 670 |
+unsigned cumulative[MAXTIMERS]; |
| 671 |
+unsigned count[MAXTIMERS]; |
| 672 |
+ |
| 673 |
+unsigned last_summary; |
| 674 |
+ |
| 675 |
+int maxtimer = 0; |
| 676 |
+ |
| 677 |
+/* |
| 678 |
+ * This package is a quick hack to allow me to draw some conclusions |
| 679 |
+ * about INN and "where the time goes" without having to run profiling |
| 680 |
+ * and continually stop/restart the server. |
| 681 |
+ * |
| 682 |
+ * Functions that should have their time monitored need to call |
| 683 |
+ * TMRstart(n) at the beginning of the segment of code and TMRstop(n) |
| 684 |
+ * at the end. The time spent will be accumulated and added to the |
| 685 |
+ * total for the counter 'n'. 'n' is probably one of the constants in |
| 686 |
+ * timer.h. You probably want to add a description to TMRsummary |
| 687 |
+ * explaining what your 'n' represents. |
| 688 |
+ * |
| 689 |
+ * There are no sanity checks to see if you have failed to start a timer, |
| 690 |
+ * etc., etc. It is assumed that the user is moderately intelligent and |
| 691 |
+ * can properly deploy this code. |
| 692 |
+ * |
| 693 |
+ * Recursion is not allowed on a given timer. Setting multiple timers |
| 694 |
+ * is fine (i.e., you may have a timer for the total time to write an |
| 695 |
+ * article, how long the disk write takes, how long the history update |
| 696 |
+ * takes, blah blah.. which are components of the total art write time) |
| 697 |
+ * |
| 698 |
+ * This package is written with the assumption that TMRmainloophook() |
| 699 |
+ * will be called with none of the timers started. The statistics are |
| 700 |
+ * generated here. It may not be fatal to have a timer running, but |
| 701 |
+ * it will not be properly accounted for (at least within that time slice). |
| 702 |
+ */ |
| 703 |
+ |
| 704 |
+/* |
| 705 |
+ * This function is designed to report the number of milliseconds since |
| 706 |
+ * the first invocation. I wanted better resolution than time(), and |
| 707 |
+ * something easier to work with than gettimeofday()'s struct timeval's. |
| 708 |
+ */ |
| 709 |
+ |
| 710 |
+unsigned gettime() |
| 711 |
+{ |
| 712 |
+ static init = 0; |
| 713 |
+ static struct timeval start_tv; |
| 714 |
+ struct timeval tv; |
| 715 |
+ |
| 716 |
+ if (! init) { |
| 717 |
+ gettimeofday(&start_tv, NULL); |
| 718 |
+ init++; |
| 719 |
+ } |
| 720 |
+ gettimeofday(&tv, NULL); |
| 721 |
+ return((tv.tv_sec - start_tv.tv_sec) * 1000 + (tv.tv_usec - start_tv.tv_usec) / 1000); |
| 722 |
+} |
| 723 |
+ |
| 724 |
+ |
| 725 |
+ |
| 726 |
+ |
| 727 |
+ |
| 728 |
+void TMRinit() |
| 729 |
+{ |
| 730 |
+ int i; |
| 731 |
+ |
| 732 |
+ last_summary = gettime(); /* First invocation */ |
| 733 |
+ |
| 734 |
+ for (i = 0; i < MAXTIMERS; i++) { |
| 735 |
+ count[i] = start[i] = cumulative[i] = 0; |
| 736 |
+ } |
| 737 |
+} |
| 738 |
+ |
| 739 |
+ |
| 740 |
+ |
| 741 |
+ |
| 742 |
+ |
| 743 |
+void dosummary(secs) |
| 744 |
+unsigned secs; |
| 745 |
+{ |
| 746 |
+ char buffer[8192]; |
| 747 |
+ char buf[256]; |
| 748 |
+ char *str; |
| 749 |
+ int i; |
| 750 |
+ |
| 751 |
+ sprintf(buffer, "ME time %d ", secs); |
| 752 |
+ for (i = 0; i < maxtimer; i++) { |
| 753 |
+ str = "???"; |
| 754 |
+ switch (i) { |
| 755 |
+ case TMR_IDLE: str = "idle"; break; |
| 756 |
+ case TMR_ARTWRITE: str = "artwrite"; break; |
| 757 |
+ case TMR_ARTLINK: str = "artlink"; break; |
| 758 |
+ case TMR_HISWRITE: str = "hiswrite"; break; |
| 759 |
+ case TMR_HISSYNC: str = "hissync"; break; |
| 760 |
+ case TMR_SITESEND: str = "sitesend"; break; |
| 761 |
+ case TMR_ARTCTRL: str = "artctrl"; break; |
| 762 |
+ case TMR_ARTCNCL: str = "artcncl"; break; |
| 763 |
+ case TMR_HISHAVE: str = "hishave"; break; |
| 764 |
+ case TMR_HISGREP: str = "hisgrep"; break; |
| 765 |
+ } |
| 766 |
+ sprintf(buf, "%s %d(%d) ", str, cumulative[i], count[i]); |
| 767 |
+ cumulative[i] = count[i] = 0; |
| 768 |
+ strcat(buffer, buf); |
| 769 |
+ } |
| 770 |
+ syslog(L_NOTICE, "%s", buffer); |
| 771 |
+} |
| 772 |
+ |
| 773 |
+ |
| 774 |
+ |
| 775 |
+ |
| 776 |
+ |
| 777 |
+int TMRmainloophook() |
| 778 |
+{ |
| 779 |
+ unsigned now = gettime(); |
| 780 |
+ |
| 781 |
+ if (now - last_summary >= SUMMARY_INTERVAL) { |
| 782 |
+ dosummary(now - last_summary); |
| 783 |
+ last_summary = now; |
| 784 |
+ return 0; |
| 785 |
+ } |
| 786 |
+ return SUMMARY_INTERVAL - (now - last_summary)/1000; |
| 787 |
+} |
| 788 |
+ |
| 789 |
+ |
| 790 |
+ |
| 791 |
+ |
| 792 |
+ |
| 793 |
+void TMRstart(n) |
| 794 |
+int n; |
| 795 |
+{ |
| 796 |
+ if (n >= maxtimer) { |
| 797 |
+ maxtimer = n + 1; |
| 798 |
+ } |
| 799 |
+ start[n] = gettime(); |
| 800 |
+} |
| 801 |
+ |
| 802 |
+ |
| 803 |
+ |
| 804 |
+ |
| 805 |
+void TMRstop(n) |
| 806 |
+int n; |
| 807 |
+{ |
| 808 |
+ cumulative[n] += gettime() - start[n]; |
| 809 |
+ count[n]++; |
| 810 |
+} |
| 811 |
--- inn-1.7.2.orig/innd/timer.h |
| 812 |
+++ inn-1.7.2/innd/timer.h |
| 813 |
@@ -0,0 +1,19 @@ |
| 814 |
+#define SUMMARY_INTERVAL 300000 |
| 815 |
+ |
| 816 |
+#define MAXTIMERS 32 |
| 817 |
+ |
| 818 |
+#define TMR_IDLE 0 |
| 819 |
+#define TMR_ARTWRITE 1 |
| 820 |
+#define TMR_ARTLINK 2 |
| 821 |
+#define TMR_HISWRITE 3 |
| 822 |
+#define TMR_HISSYNC 4 |
| 823 |
+#define TMR_SITESEND 5 |
| 824 |
+#define TMR_ARTCTRL 6 |
| 825 |
+#define TMR_ARTCNCL 7 |
| 826 |
+#define TMR_HISHAVE 8 |
| 827 |
+#define TMR_HISGREP 9 |
| 828 |
+ |
| 829 |
+extern void TMRinit(); |
| 830 |
+extern int TMRmainloophook(); |
| 831 |
+extern void TMRstart(int); |
| 832 |
+extern void TMRstop(int); |