Article View: news.software.nntp
Article #28847Silly patch
From: Michael O'Reilly
Date: Fri, 05 Jun 1998 00:00
Date: Fri, 05 Jun 1998 00:00
170 lines
5140 bytes
5140 bytes
A patch I wrote a while back from innd-1.7.2.insync-1.1d, that I use
for my linux news server, with nothing special in the way of disks (in
fact, all the news articles on two 8gig drives).
This patch lets our news server keep up. It does something really
dumb: it forks the server for every article write, so that the main
server loop doesn't block while it's doing directory lookups.
This is a dumb patch so innd no longer notices if you run out of disk
space.
It made a pretty huge difference to our thru-put. Having multiple disk
requests in the queue is a big win for overall thruput (as opposed to
waiting for each disk request to complete before issuing the new
one). It at least doubled our article accept rate.
Cavets:
o If you run out of disk space on the article spool, innd will
throw away articles.
o You _shouldn't_ MMAP the article or history files. something
strange happens when you mmap(), dirty lots of things,
and then fork() 15 times, and have all the children
exit.
o It's only worth running this on real operating
systems. I.e. if your OS can't do copy-on-write and
fast fork()/exit()'s, then forget it.
o If you don't have heaps of idle CPU (normal for a news
server), you want to be careful. This patch will burn
CPU like you're rarely seen before.
Advantages:
innd will actually use your disk array. I.e. if you have 6
disks, it can actually keep all of them busy instead
of only 1 at a time.
There's a magic constant in the patch (search for '15'). If you have
lots of memory and disks, you may want to increase this a bit. It's in
there just so that if innd can accept faster than the disks can write,
you won't blow up the server.
Comments/experiences welcome.
Michael.
--- art.c.orig Wed Dec 17 13:33:16 1997
+++ art.c Mon Mar 23 12:21:51 1998
@@ -1,4 +1,4 @@
-/* $Revision: 1.68 $
+/* $Revision: 1.1 $
**
** Article-processing.
*/
@@ -548,6 +548,8 @@
IOVEC *end;
char bytesbuff[SMBUF];
int i;
+ int pid;
+ static int round = 0;
if ((p = HeaderFind(Article->Data, "Path", 4)) == NULL
|| p == Article->Data) {
@@ -557,12 +559,6 @@
return -1;
}
- /* Open the file. */
- if ((fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, ARTFILE_MODE)) < 0) {
- if (errno != ENOENT)
- IOError(WHEN, errno);
- return -1;
- }
/* Set up the scatter/gather vectors. */
vp = iov;
@@ -617,22 +613,57 @@
ARTheaders[_bytes].Length = Data->SizeLength;
ARTheaders[_bytes].Found = 1;
+ fflush(Log); /* we don't want the forked child doing this. */
+
+ /* run every 15th one in-line to stop meltdown.. */
+ if (++round > 15) {
+ round = 0;
+ pid = -1;
+ } else
+ pid = fork();
+
+ if (pid < 1) { /* if it's failed or it's a child, do the write */
+
+ /* Open the file. */
+ if ((fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, ARTFILE_MODE)) < 0) {
+ char *p;
+ for (p = strlen(name) + name ; p > name ; --p)
+ if (*p == '/') {
+ *p = 0;
+ MakeSpoolDirectory(name);
+ *p = '/';
+ fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, ARTFILE_MODE);
+ break;
+ }
+
+ if (fd < 0) {
+ syslog(L_ERROR, "%s cant open %s %m", LogName, name);
+ if (!pid) exit(0);
+ if (errno != ENOENT)
+ IOError(WHEN, errno);
+ return -1;
+ }
+ }
+
/* Now do the write. */
if (xwritev(fd, iov, vp - iov) < 0) {
i = errno;
syslog(L_ERROR, "%s cant write %s %m", LogName, name);
- IOError(WHEN, i);
- (void)close(fd);
if (unlink(name) < 0 && errno != ENOENT) {
i = errno;
syslog(L_ERROR, "%s cant unlink %s %m", LogName, name);
+ if (!pid) exit(0);
IOError(WHEN, i);
}
+ if (!pid) exit(0);
+ IOError(WHEN, i);
+ (void)close(fd);
return -1;
}
if (close(fd) < 0) {
i = errno;
syslog(L_ERROR, "%s cant close %s %m", LogName, name);
+ if (!pid) exit(0);
IOError(WHEN, i);
if (unlink(name) < 0 && errno != ENOENT) {
i = errno;
@@ -641,6 +672,9 @@
}
return -1;
}
+
+ if (!pid) exit(0);
+ }
/* Set the owner. */
if (AmRoot)
@@ -1196,6 +1230,10 @@
}
/* Get the files where the message is stored and and zap them. */
+
+ fflush(Log);
+ { int pid; pid = fork(); if (pid < 1) {
+
for ( ; *files; files = p + 1) {
/* Snip off next name, turn dots to slashes. */
for (p = files; ISWHITE(*p); p++)
@@ -1213,6 +1251,10 @@
if (!more)
break;
}
+
+ if (!pid) exit(0);
+ } }
+
if (c)
next[-1] = c;
}
Technical Details
Message-ID:
<x7emx4feuh.fsf@metal.iinet.net.au>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: <x7emx4feuh.fsf@metal.iinet.net.au> Subject: Silly patch Date: Fri, 05 Jun 1998 00:00:00 +0000 From: Michael O'Reilly <michael@metal.iinet.net.au> 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: 359766811 Organization: iiNet Technologies Newsgroups: news.software.nntp