Article View: news.software.nntp
Article #5147Uh, oh...Usenet has got beeg trouble....
From: T. William Wells
Date: Wed, 21 Feb 1996 00:00
Date: Wed, 21 Feb 1996 00:00
280 lines
13211 bytes
13211 bytes
The good news: running the stream patches (where are the latest,
btw?) has improved matters for my installation. So also did
setting the active sync time to once every 100 articles. The bad
news: My closest provider, sprintlink, only connects to me 68% of
the time. This is truly horrible. As it is, it looks like if
*nothing* goes wrong, I'll eventually catch up to real time. I
give no odds on *that* happening. :-|
So, I'm back to looking for ways to speed up my server.
I did a little statistics gathering. The way I did this was to
time from select to select and divide them into two groups: those
with a namei call and those without. 19% of them had a namei call.
Presumably only those 19% were relevant to new article creation.
In those 19%, 69% of the time was spent in namei calls.
The more I think about it, the more this isn't surprising. First
of all, the inode cache only applies to the directory component of
pathnames. The final element, because it is almost always a link
being created, results in a complete search of the directory.
Thus, any caching comes from the buffer cache. As I recall, the
buffer cache uses LRU -- and this just doesn't work well for what
is essentially random access to the disk. Not unless the "working
set" (so to speak) of active directories happens to fit in your
buffer cache. Fat chance.
Thus, for all practical purposes, each new article requires
reading the entire directory it gets filed in. Sure, the buffer
cache helps *some* (there is no obvious way to find this info in
my OS, so I have no real numbers) but it's surely not going to be
a drastic improvement. Maybe 20%.
What does that mean? Well, if an article gets filed under a 100K
directory, perhaps 80K has to be read in, then maybe 8K written
out, and all that *synchronously*. Then again the inode cache
isn't 100% efficient so for the sake of simplicity, I'm going to
pretend that the entire article directory gets read in and that
there are no other relevant times.
So, what does this amount to? Well, the probability of an article
being in a given newsgroup is (assuming equal expire times, a bad
assumption, but the point is to get a feel for the impact of this,
not precise mathematics) proportional to the size of the
directory. And the amount of data transferred is also.... The
average data to be transferred is:
sum(over all newsgroups, p[article in newsgroup] *
size of directory)
That probability is, roughly, just the size of the directory
divided by the total of all directory sizes, thus the average data
to be transferred by the directory read is:
sum(over all newsgroups, size of directory * size of directory)
---------------------------------------------------------------
sum(over all newsgroups, size of directory)
Now, before getting into the actual numbers, it's worth thinking
about that formula. The number you get there scales linearly with
the size of the newsfeed -- but it applies to each and every
article filed. That means that the data transfered for a newsfeed
proportional to the *square* of the size of the newsfeed!
If you're getting a sinking feeling, you're right on the money.
So what are the actual numbers like? Well, the average article is
12K. (It's only 3K if you aren't getting the binaries.) The block
size (on many Unix systems, anyway) is 4K and I'll pretend that
two of those are written per article. And then for the above
number....
44,560 bytes
That's right. 12K+8K+44K or 64K per article. At today's rate,
that's 128K per second. *If* you aren't doing anything else with
the machine. Like updating the history, log, or active files....
In short, in the not too distant future, you'd better be running
some *very* fast disks, and forget about caching because it won't
help, or you are completely, totally screwed.
The bottom line is that the current news spool structure is going
to become obsolete. It requires O(log(n)*n**2) (the log(n) comes
from the article number size) bytes transferred per article. While
newsgroup reorganization helps some, by keeping down the size of
the individual directories (and thus pushing forward the time to
doomsday), it's a sure bet that it'll hit a limit all too soon.
And I haven't even talked about the latency effects....
Besides which, it is entirely foolish to be spending two thirds of
your disk bandwidth on directory diddling, when it just isn't
necessary.
There is, fortunately, an easy solution. Instead of writing all
the articles into a single directory, write them into
subdirectories. If one got silly, one could a directory level per
digit, which makes the time O(n * log(n)) -- a much more *polite*
number. :-)
Realistically, a million articles is extreme. So, divide the
article number into 7+3 digits and write the articles into
.../0123456./789 . If you have a very small newsgroup, you do one
extra directory search. If you have a very large, say million
article, newsgroup, you search 2000 entries instead of a million.
So how would this fare on my newsfeed? Well, *every* article now
has an extra directory read. A typical directory entry has 8 bytes
of overhead and there are 8 bytes of data in the first level. So a
4K block can contain 64 entries or 64000 articles.... There are
not many groups that large... in fact, at the moment, there are
none. So, 4K it is, per file, like it or not.
Then, the average subdirectory is 5.3K, call it 6K for the sake of
round numbers. This is a total of 10K for the lookup; add another
4K for the directory write and 12K for the article... the result
is 26K, which compares favorably with 64K. :-) And, unlike that
latter number, it is essentially fixed; it doesn't increase until
there are newsgroups with over 64000 articles. On top of that, the
synchronous part goes from 44K to 14K and that directly affects
the performance of feeds that don't use streaming. (Or even those
that do: I rather expect that the server gets stuck waiting during
those writes....)
Nothing comes for free, of course. Everything that accesses the
news spool must now know about the new directory structure. The
NNTP daemon, whatever it is, must know to create the extra level
of directories, and expire must know to delete the directories
when they're no longer needed.
The thought then crosses my mind that, perhaps, it's time to go
whole hog and just use a file where the subdirectory would be.
This is reasonable *if* one can build a "directory" in this file
that is more efficient than the system's.
Obviously, if a full directory were being implemented, one would
have all the headaches that come with trying to implement that.
However, as with dbz, it's possible to implement just a subset
functionality, as news doesn't require all the features....
The first question that pops into my mind is "just how *big* will
one of those files get?" Well, it could be pretty big. If every
article were 1Meg and there were 1024 of them, we're talking a
gigabyte.... On the other hand, if you're accepting that many huge
articles one hopes that you have some pretty big spool disks....
So, ignore that problem.
The next problem is that file system writes are not synchronous.
That means data inconsistencies are a problem. Actually not, but
I'll explain shortly....
So, here's a very simple structure:
1001 4 byte entries, each containing an offset to an article. The
list of articles is terminated with a zero offset. The very last
entry is a sentinel entry, so there are no more than 1000 articles
in the file. A cancelled article is marked by a single bit in the
offset. This is the low bit; articles start on 4 byte boundaries.
Each article starts with 4 bytes of size and is followed by the
article itself. There is no article terminator. The first article
starts at byte 4096; thus there is space after the index for
random other purposes.
Now, to create an article, these are the steps:
open the file
read the index block
find the entry
if the entry is in use
{the active file lost some entries}
trash that entry and all successors
truncate the file to the end of the last article
if preceeding entries are not in use
mark them as cancelled
put the file size into the entry
write the block
seek to the end of the file
write the article size
write the article, possibly with padding
close the file
On a crash, it's "OK" to lose some articles. You're going to
anyway, as, for example, the active file is likely to not have
been synced. What's needed is the ability to restore consistency
after a crash. This is pretty easy, fortunately. You find the end
of the file and zero out all block entries that point at or past
it. Then you look at the last entry and make sure that it's
consistent with the article size. If not, you zero it and back up
one. You don't need to worry about the active file; if the active
file got updated first, you have unused entries; otherwise, the
file gets cleaned up during article creation.
Expiry works by "cancelling" articles; when all articles are
cancelled, the file goes away. Here's an algorithm, using a
sorted list of files to expire:
if this is the last of the files, pause the server
open the file
read the index block
mark all articles to be expired
if there are no active entries
delete the file
else
write the index block
close the file
if the server is paused, unpause it
{alternately, instead of pausing the server, feed it a
bunch of cancel commands}
One subtletly in cancellation. Because there can be any number of
readers on a file, you can't go diddling with the contents. You
can, however, make a copy of the file, edited however one might
like, and then rename the copy to the file. This works because
there are no operations that depend on the state of the file
across a close/open sequence. (The one exception to this,
truncating when out of sync with the active file, works because
no attempt will be made to access the articles beyond the
truncation point.)
The server cancels an article:
open the file
read the index block
mark the article to be cancelled
write the index block
close the file
There is a presumption here, that even though an article is
cancelled, its history entry sticks around until expiry. That's
needed because only expire deletes these files.
Finally, there's reading an article
open the file
read the index block
seek to the article start
read the article size
read just that many bytes from the file
That's it. This is not too complex, though it is certainly more
complex than the current arrangement. You can't grep these files
with impunity, either. Nor likely edit them. But those are
relatively minor annoyances. Heck, the grep problem can largely be
ignored by having a fifth character before the article start, a
newline. Then, at worst, you grep some binary garbage along with
the text you want. The edit problem can be resolved by storing the
material before each article in ASCII and putting the article
number in there; then you can just drop the 4K header, edit the
ASCII, and reconstitute the header with a simple utility.
Finally, you flat out lose on crossposts. You get a copy of each
cross-posted article. (On the plus side, no more worries about
links.) In compensation for this, articles use less space than
they used to: the overhead is not a half a block per article (plus
inode information) but a handful of bytes.
On the other hand, you get enormous performance benefits. Creating
a new article generally does not involve synchronous writes nor
humongous directory searches. Newsgroups will get too large for
human consumption before they get too large for this system to
handle.
Expiry can be totally divorced from history file processing. The
history file can lose the dates in the middle field and become
nothing more than an index from message ids to files; the data
itself would live just before each article. Some forms of expiry
then become ridiculously easy.....
About the only major drawback to this whole scheme is that every
newsreader that does direct spool access has to be modified. On
the other hand, reading is trivial. And, in many installations, it
just doesn't matter -- all reading is done via nntp anyway.
Now, the $64,000 questions: Have I missed something that would
make this scheme unworkable? Is someone doing this? Would the
maintainers of INN be willing to have this as a compile-time
option?
Technical Details
Message-ID:
<Dn4HrC.KIx@twwells.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-mailReferences:
<311F8C62.4BC4@pluto.njcc.com> <DMu8B6.6Jn@twwells.com>Show Full Headers
Complete Article Headers
Message-ID: <Dn4HrC.KIx@twwells.com> Subject: Uh, oh...Usenet has got beeg trouble.... Date: Wed, 21 Feb 1996 00:00:00 +0000 From: bill@twwells.com (T. William Wells) References: <311F8C62.4BC4@pluto.njcc.com> <DMu8B6.6Jn@twwells.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: 140365496 Organization: None, Mt. Laurel, NJ Newsgroups: news.software.nntp