🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #61323

Re: [FNTP] more on hash chunk sizes

#61323
From: Curt Welch
Date: Fri, 11 Oct 2002 20:11
238 lines
14590 bytes
"Brian Truitt" <btruitt@rcn.com> wrote:
> I think that the chunk size should be the lowest part size you should
> expect someone to post at. Make it 64K, binaries shouldn't ever be split
> into pieces smaller than this, and at 512k part sizes, it only requires 8
> hash calculations per post.

I realized there's more to think about when selecting the chunk size
for the hash.  I'll summarize what I've heard/though about so far.

But first...

THE HASH

To start with, let me explain for anyone not following this, that we are
basically defining a hash algorthm that works well with multipart posts
because it allows you to verify that a single post matches it's hash id
without having access to all the other posts.  The hash algorithm is built
using a standard secure hash such as MD5 or SHA1.  We divide the entire
file up into fixed sized chunks, and calculate the hash value of each
chunk.  We then build a binary tree of hash values by taking each two hash
values, combine them, and calculate the hash of the combined.  We do this
with a large binary tree until you get to the top where you have only a
single hash value for the entire file.

The beauty of this system is that when you post a segment of data from the
file, you can include the hash values of all the other segments.  But
instead of having to include thousnads of hash values for a 1000 part file,
you include the highest hash values from the tree possible which will allow
you to recalculate the total hash using the data in the file and the hash
values supplied.  With the help of the tree, you only end up having to
include a very small number of hash values with each post (on the order of
2*log2(P) where P is the number of chunks).

So, in designing the hash which will become a possible standard for all
large binaries posted to Usenet, we have to pick a chunk size (just like
you have to pick a the number of bits you want if you were designing a new
hash). Whatevery chunk size we pick will end up being something to live
with for a long time.  Changing the hash later defeats some of it's reason
for being so it's not something you would want to do on a regular basis.

So, we have identified various issues for selecting a chunk size so far...

HASH TREE SIZE

The first chunk size issue is that smaller chunk sizes creates a larger
hash tree.  The hash calculation isn't significant unless you get down
somewhere below the 1KB size for junks, but the number of hashes which have
to be saved before a file can be posted, and then the number of hash values
that need to be included with each post as its digntial "signature",
increases.  But it's logrithmic, so every time you double the chunk size
you only remove one hash value from the post.  And for 1KB chunk sizes we
are only talking about somewhere in the range of 20 hash values for typical
files worset case and 10 or less on the average.  So the data is fairly
small either way.  But larger chunk sizes are generally better in terms of
reducing the size of the hash tree and the number of hash values to deal
with everywhere.

ARTICLE SIZE

The second issue on chunk size is the fact that all multpart posts which
use this system must be split on chunk size boundries.  The larger the
chunk size, the less options we have when selecting the size of the
multipart post, and the harder it becomes to keep all the articles in a set
close to the same size as possible.  Though it's not commonly done now,
it's better to keep all the posts in a multipart set the about the same
size.  Many feeds on Usenet are size limited, so the larger the post, the
less options it has to move though usenet, and the more likely it is to get
caught in feed which is backlogged (which slows it's movement though
usenet), and the more likely it is to be dropped and lost.

The common algorithm used today is to set a part size, and post all the
parts the same size, except the last, which will be "whaterver is left".
This means the last article in a multipart set very offen will fly though
usenet making it to sites that will end up blocking the rest of the post,
and making it to some sites hours ahead of the rest of the post.  The
problem that can cause, even if all the other posts show up later, is that
the last part will be expired first.  So this creates a window at the end
of the expiration time where all but the last part is sitting on the
server.  People think the "Usenet" lost the last part when in fact, it had
already come and gone.  This is a noticable problem on very short retnetion
servers (1 day range) where you could find 25% of all posts having this
problem even though the server is getting 100% of all the articles.

At the same time, If you don't balance the data between the articles, you
have forced your articles to be larger than they need to be.  This is most
common for smaller posts done with large part sizes.  Say you have a 910KB
post split into 300K chunks.  You end up with 3 posts of 300K and one post
of 10K.  So you already are sending out 4 articles.  If the posting tool
balanced the data between the 4 posts, you would instead have had 4 posts
of 240K each.  Those 240K posts will make it to more sites, and make it
there faster, than the 300K posts which are 25% larger than they should
have been.

So I want to encourage people to start doing this - to balance the amount
of data placed in each post of a multipart set.  But because the chunk size
limites the ability to balance, you have the issue that the larger the
chunk size you select, the less balanced the post will be.  For a 64KB
chunk size, this means that some posts will end up being 64K larger than
the rest in the set.  And, because the last file will end up with a partial
chunk it can worst case end up being 2x the chunk size smaller than the
largest files in the post.  So for a 64K chunk size, the last post in the
set may be as much as 128K (minus one byte) smaller than the largest in the
set (probably the first article posted).  So, for this dynamic, you want
smaller chunk sizes instead of larger chunk sizes.

But, the chunk size also becomes the lower limit on the article size for
mutlipart posts.  With this system, you must but at least 1 full chunk in
each article.  So a larger chunk size like 64K makes it impossible to use
this system and post small multipart articles (trying to squeze them into
systems that only want text for example).  So that would en

UUENCODE

Like I said in another post, to make this system compatible with uuencode
we have the problem that uuencode puts 45 bytes of file data on each line.
When you post in uuencode format, each article must fall on a uuencode line
break.  So that means every uuencode file contains a number of bytes which
is a multiple of 45. And the factors of 45 are 3, 3, and 5.  Not a single 2
in there.

So if we want the chunk sizes to fall on a power of 2 block boundry (to
match disk blocks and IO buffers), and also fall on uuencode 45 byte
boundries, you are forced to pick a size which is simply the produce of 45
with the power of 2 boundy (like 1K).  This make 45KB the smalest chunk
size that does both of those things.

The other option is to ignore the 45 byte uuencode limit and force uucode
to do something very non standard like including a short last-line at the
end of each article in the set.  The "M" at the beginning of each uuencode
line documents the length of the line (M is 45 in the uuencode system).
And in theory, you should be able to put less bytes on the last line and
have it work. Some uudecoding tools will work with that.  But the question
is how many would break. Normally, the very last line for the entire file
is shorter.  Some uuencoding tools I bet will see a short line and take
that to mean it's the end of the file and not just "a short line".  Or
maybe assume it's a signature added to the end of a post that needs to be
ignored, etc.

The other approach is to use a smaller chunk size, like 1K, and force any
tool that wants to deal with creating uuencode solve the problem on their
own by splitting the file into a size which is a multiple of 45*CHUNK-SIZE
(45K if we select 1K as the size).

But if we ignore the uuencod issue, and go with a chunk size like 64K
(which has no prime factors of 3 or 5), that forces a uuencode article to
contain multiples of 45*64K (2.8MB) in order to get it to split on normall
uuencode lines.  And 2.8MB of uuencode data expands to a article size of
3.9MB which of course is totally unreasonable as a "minimal" article size
for todays Usenet.

Becaus of this, if we go with any chunk size larger than 1K, it should
contain some prime factors of 3 or 5 to allow some degree of compatibility
with anyone wanting to post uuencoded articles using this system.

ERROR DETECTION

The other big advantage of this hash system is that it becomes a very
strong error detecion system to not only prevent forgeries, but also to
simply spot corrupted data in articles which can sometimes happen in
transit on Usenet, and sometimes happen when articles are posted.

But, error dection with this happens at the chunk-size level.  If a post
has a one bit corruption in transit because of broken hardware somewhere
(like an 'a' changed into an 'A'), then not only can this system detect
that the article is corrupted, it can identify the location of the
corruption down to which chunk it is in.  This could in theory, allow a
download tool to use all the other chunks from the post, and only throw out
the one chunk which was corrupted.  A repost then would only need to repost
the single corrupted chunk, and not the entire article to fix the problem.

To repost a single missing chunk, the software would have to generate the
"repost request" information automatically, but that's something we have
talked about anyhow.  We want the software to be able to create a computer
parsable description of what's missing and for a re-post tool to be able to
read that and generate the minimal amount of reposts to fix the problem (or
to simply send the re-post data though e-mail).

The larger the chunk size we select, the less resolution there will be for
being able to narrow down the location of corrupted data in a file.  That
means that more "good" data will have to be thrown out with the bad.

But the flip side to this is that maybe no one in practice will ever bother
to try do repost anything other than entire articles, or par files which
have the power to fix entire articles, so the fact that we can "save" 90%
of the data in an article might not end up doing us much good anyway.

But, the flip to the flip side, is that the download tool has the power to
fix damaged or missing segments by spotting an accidental repost of the
same file in any group it's scanning.  And if you are only missing a single
1K chunk, instead of a 64K chunk, the odds of finding an article to "fix"
the missing data I think is better for the 1K chunk size.  But if
everything is being posted in these same chunk sizes, maybe that's not
really true...

POWER OF 2 AND OTHER BOUNDRY ISSUES

This hash algorthm works fine for any chunk size (in bytes) and doesn't
realy need to be on a power of 2 block boundry. We could make the chunks
1234 bytes each if we wanted to.  The hash algorithms like MD5 and SHA1
work fine for any number of bytes and because of the amount of CPU work to
calculate the hash anyway, the block aligment issues might not be important
at all.  MD5 is a 16 byte hash, and that makes it natural to calculate a
hash for data sizes which are a multiple of 16 bytes.  But SHA1 is a 20
byte hash, (which I assume works internally on 20 byte chunks but I don't
know that for sure), so making the chunk size a multiple of 20 might be
slightly more natural if SHA1 is used (which is what my current code just
happens to use).  20 bytes has a factor of 5 so that's one of the 3 factors
needed for UUENCODE, so that's a plus anyay.

So, far, we have also talked about using Base64 to represnet chunk offset,
article size, and file size.  Using a chunk size which falls on a base64
boundry then becomes a minor advantage as well when looking at numbers
encoded in base64.  Just like using sizes which are multiples of 10 make
things easy to understand when working in base10.

But I suspect that's of close to 0 value because these Base64 numbers are
very hard to do anything with in your head (What is J3a + Ca anyway?). All
it lets you know is that for a chunk size of BAA (which is like 100 in MIME
Base64 character set), Then the offsets will be A (aka 0), BAA (aka 100),
CAA (aka 200) etc. when represtend in bytes.

CONCLUSION

That's about all the issues I have found so far which are affecting the
choice of chunk size...

Anybody see others or have move thoughs and what they think will be a good
CHUNK size?

For now, I'm writing my code so the chunk size is simple to change (a
define), so once I'm able to actually post and downlad real articles done
with this system, we will have more information to work with on what the
issues are and just how important each of the above issues really are.

-- 
Curt Welch                                            http://CurtWelch.Com/
curt@kcwc.com                          Webmaster for http://NewsReader.Com/
Technical Details
Message-ID: <20021011161123.133$Fc_-_@newsreader.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!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!news-out.cwix.com!newsfeed.cwix.com!newsfeed1.cidera.com!Cidera!feed2.newsreader.com!newsreader.com!news2.newsreader.com!ellis.newsreader.com!not-for-mail
References: <hpk9quk1cq0ti2reeu03epd0tgf4b8a8p0@4ax.com> <20021010014047.034$XV@newsreader.com> <ao4htp$rq1$1@bob.news.rcn.net>

Show Full Headers
Complete Article Headers
Message-ID: <20021011161123.133$Fc_-_@newsreader.com>
Subject: Re: [FNTP] more on hash chunk sizes
Date: Fri, 11 Oct 2002 20:11:23 +0000
From: curt@kcwc.com (Curt Welch)
References: <hpk9quk1cq0ti2reeu03epd0tgf4b8a8p0@4ax.com> <20021010014047.034$XV@newsreader.com> <ao4htp$rq1$1@bob.news.rcn.net>
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!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!news-out.cwix.com!newsfeed.cwix.com!newsfeed1.cidera.com!Cidera!feed2.newsreader.com!newsreader.com!news2.newsreader.com!ellis.newsreader.com!not-for-mail
Organization: NewsReader.Com
Newsgroups: news.software.nntp
X-Trace: NewsReader.Com XtFi8T=h0jahMHHDjPH/g4kB-kqjj=qZPXO5DCF8V2jmD3n
X-Face: "p}G*1KH{+F7EYGKLb>ogDguabZ+%,?^epeFB!nzu`)`$=QcvL1KF6<0GH!Tbc!Sqo[|tV5
  %IW48mQf3K=Ci&gZ7]]aazx@]Y-nq!r5{yH/#,?@lDdUDvOfByB2hVW0.@OM%{l/{cT'{w
X-Url: http://CurtWelch.Com/
User-Agent: NewsReader.Com
Lines: 237