🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nntp
41 messages
41 total messages Started by Juergen Helbing Mon, 24 Mar 2003 12:40
Newsreader programming - sorting one million lines ?
#64509
Author: Juergen Helbing
Date: Mon, 24 Mar 2003 12:40
47 lines
2411 bytes
This is not a server question, but it is about nntp-software.
So I hope that it is on-topic here:

Binary Usenet has meanwhile newsgroups with more than 50.000
messages per day. So a retention of 30 day in a newsreader would
cause a header-list of 1.500.000 messages.

Sorting header lists by date, subject line and/or from  is necessary
(and sorting by subject is also needed for joining multiparts).

Until now I am cutting the header-list to the 150.000 newest msgs
- but this causes often problems - especially if someone does not 
read a group for one week.....
I'm still keeping the 150.000 msgs in memory (approx. 30-70 MB)
where sorting is easy - even if it is not too fast with quicksort or 
heapsort.
A first test-run with 500.000 msgs shows me that sorting them
takes up to one minute - and if there is not enough memory in the
computer and swapping begins then sorting takes forever.

I'm not yet keeping sorting indices for subject, date, author, 
msgid(sending host), filename, size, line, available server.
And introducing them (and updating them - again very slowly - 
at every header fetch) would cause both - disk space and time 
and effort for expiry........

Reducing the amount by detecting - and eliminating - multiparts
would not be a solution for me.


So here finally my question:
How do you sort your header-lists if they dont fit into memory ?

I believe that sorting "1.500.000" lines simply by 'users-click'
is a very demanding job - and such quantities appear only on
the binary usenet today....

Any ideas, tips, 
genuine disk sorting algorithms introduced since 1979 
and better/faster than B-Tree ?


TIA
-- 
Juergen

Re: Newsreader programming - sorting one million lines ?
#64510
Author: Heiko Studt
Date: Mon, 24 Mar 2003 18:54
97 lines
3947 bytes
Juergen Helbing did nothing on 24.03.2003 13:40:45:

> Sorting header lists by date, subject line and/or from  is necessary
> (and sorting by subject is also needed for joining multiparts).

You want to sort *one* thing at a time, right, and only with same values you
want to sort again!?

> I'm still keeping the 150.000 msgs in memory (approx. 30-70 MB)

Then you save *everything*.

Use something like an database:

You save every XOver(?)-Line in one line in a "Direktzugriffs"-file.
(In a kind of form you like)
Now you save a pointer to the beginning of the line in a
fixed-width-record-file.
Now you load 10 chars from all subjects to memory and save the index of it.
Therefor you can use a sorted stringlist. (AFAIK sorting by including is
fastest, isn't it?). After all you have a pre-sorted list where you have to
resort all "similar" things with full-width subject, date and so on.

This is a smaller solution in Delphi:

pInt = ^int64;

temI : pInt;
f : tFileStream64;
i : int64;
tsl : tStringList;

begin
  f := tFileStream.Create('TempDatabase.tmp');
  tsl := tStringList.create;
  try
    f.position := 0;
    tsl.sorted := true;
    i := 0;
    while not StreamEof(XOverStream) do begin
      s := GetLine(XOverStream);
      new(temI);
      temI := i;
      tsl.AddObject(GetSortingItems(s), tObject(temI));
      f.write(s);
      i := f.position;
    end;

    //And here you have a sorted tsl with pointers in tsl.Objects.
    //The rest you can do yourself. ;-P

  finally
    tsl.free
    f.free;
  end; 


> where sorting is easy - even if it is not too fast with quicksort or 
> heapsort.
> A first test-run with 500.000 msgs shows me that sorting them
> takes up to one minute - and if there is not enough memory in the
> computer and swapping begins then sorting takes forever.
> 
> I'm not yet keeping sorting indices for subject, date, author, 
> msgid(sending host), filename, size, line, available server.
> And introducing them (and updating them - again very slowly - 
> at every header fetch) would cause both - disk space and time 
> and effort for expiry........
> 
> Reducing the amount by detecting - and eliminating - multiparts
> would not be a solution for me.
> 
> 
> So here finally my question:
> How do you sort your header-lists if they dont fit into memory ?
> 
> I believe that sorting "1.500.000" lines simply by 'users-click'
> is a very demanding job - and such quantities appear only on
> the binary usenet today....
> 
> Any ideas, tips, 
> genuine disk sorting algorithms introduced since 1979 
> and better/faster than B-Tree ?
> 
> 
> TIA
> -- 
> Juergen


MFG

-- 
Heiko Studt
http://www.goldpool.org/temp/IMAPHamster.zip 20.3.2003 24:00

Re: Newsreader programming - sorting one million lines ?
#64512
Author: greg andruk
Date: Mon, 24 Mar 2003 21:50
17 lines
2172 bytes
archiver@i3w.com (Juergen Helbing) writes:

> So here finally my question:
> How do you sort your header-lists if they dont fit into memory ?

Look on Google for tape-sort and merge-sort.  The basic idea is to
break the data into chunks that fit into memory, sort and save them
into temporary files, then merge the chunks back together to obtain
your complete sorted list. The more tape drives you have, the faster
you can sort.  You can use disk files instead of scratch tapes, but
that's cheating.

There are quite a few variations on this idea.  You might also
consider using a database with multiple indexes, this could be easier
but maybe slower if you end up generating indexes that are rarely
used.
Re: Newsreader programming - sorting one million lines ?
#64513
Author: Jeffrey M. Vinocur
Date: Tue, 25 Mar 2003 01:26
33 lines
2321 bytes
In article <4540d.o33203@archiver.winews.net>,
Juergen Helbing <archiver@i3w.com> wrote:
>
>How do you sort your header-lists if they dont fit into memory ?

Well, in principle a modern memory manager should take care of
writing them to disk as needed.  (That is, most of the time
virtual memory will suffice, rather than you having to open a
temporary file yourself.)

I wonder if the reason you're having problems is that your sort
algorithm has poor locality, causing a lot of swapping.

I just poked at the source for GNU sort(1) from the textutils
package, and it seems to be using mergesort, which surely would
have better cache locality than quicksort.  You might try that,
before resorting to drastic measures.  Actually, you can even
estimate the time you'll need for the memory-access at least:
take N headers you can hold in memory (say, 1,000,000 of them)
and do a linear traversal of all of them, and multiply by
log_2(N) (here, about 20).  If that's acceptable, it's probably
worth implementing mergesort.

Otherwise, I'd say it's time to consult an algorithmicist.
Either ask in an appropriate newsgroup, or find a textbook.  (I
just checked the Cormen/Leiserson/Rivest text and didn't see
anything useful, perhaps Knuth would be an appropriate resource.)


-- 
Jeffrey M. Vinocur
jeff@litech.org
Re: Newsreader programming - sorting one million lines ?
#64514
Author: Juergen Helbing
Date: Tue, 25 Mar 2003 05:56
46 lines
2459 bytes
blorg <blorg@usenet-invalid.to> wrote:

>Agent will resort  ~ 1,000,000 headers in less than a minute without
>grabbing >40mb of memory the toughest resort IIRC is 'by subject'
>and may take 1 minute or longer on that many headers.

Yes, Agent does a great job.
But from peeking into their file structure seven years ago
I believe they are keeping indices in their idx files.
So the 'time-consumption' is moved to 'update headers'
(which can be very slow from my experience).

>>How do you sort your header-lists if they dont fit into memory ?
>
>Use databases. Dont keep this much data in memory on a pc, it
>doesn't work well.  

You are right - any kind of database might do the job.
I'm just afraid that everything I'll try will be far slower
than today - even for the same volume of data.

>>Any ideas, tips,  genuine disk sorting algorithms introduced since
>>1979 and better/faster than B-Tree ?
>
>Doesn't B-Tree have enough throughput?  I have a sheet of stats
>if that would be helpful to you.

I am already using a B-Tree for the MsgIds.
It is very fast - but this method requires to maintain _all_ sorting
indexes in seperate B-Trees (6 in my case). Updating all of them
after header fetch and expiring them is very slow (compared
to today :-)

And creating a B-Tree every time just for sorting purposes would
be possible but too slow. Inserting 1e6 entries into a B-Tree would
take 1000 secs even if every insert operation would take only
1 milliSecond :-(

After reading also the other replies it seems to be finally necessary 
to maintain full disk indices.  A lot of programming ahead.

Thanks for your answer.
-- 
Juergen

Re: Newsreader programming - sorting one million lines ?
#64515
Author: Juergen Helbing
Date: Tue, 25 Mar 2003 06:08
45 lines
2316 bytes
Heiko Studt <UsenetBecky@goldpool.org> wrote:

>Then you save *everything*.

Yes, I'm having all Xover-headers in a single file.

>You save every XOver(?)-Line in one line in a "Direktzugriffs"-file.
>(In a kind of form you like)
>Now you save a pointer to the beginning of the line in a
>fixed-width-record-file.

This is already my actual structure.

>Now you load 10 chars from all subjects to memory and save the index of it.
>Therefor you can use a sorted stringlist. (AFAIK sorting by including is
>fastest, isn't it?). After all you have a pre-sorted list where you have to
>resort all "similar" things with full-width subject, date and so on.

This sounds reasonable and I remember the "5 tape sorting"
from the 50's :-) Reading the entire file once for presorting
and making 'small range sorting' on a smaller file-portion
sounds also good. But there seems to be one big problem:

The "small range sorting" requires access across the entire
file (The similar subject is used everywhere within one gig
of headers). And these disk-accesses are very slow....

>This is a smaller solution in Delphi:
>[...]
>      tsl.AddObject(GetSortingItems(s), tObject(temI));
>[...]

The "GetSortingItems(s)" seems to include an 
"fseek(randompostion-within-fullfile)"... and this is
used 1e6 times....  Having a fast disk with 1 mSec 
access to every item would still need 1000 seconds....

Obviously the required time for "external sorting" is
not acceptable.....

Thanks for your answer.
-- 
Juergen

Re: Newsreader programming - sorting one million lines ?
#64516
Author: Juergen Helbing
Date: Tue, 25 Mar 2003 06:12
40 lines
2086 bytes
greg andruk <gja@meowing.net> wrote:

>archiver@i3w.com (Juergen Helbing) writes:
>
>> So here finally my question:
>> How do you sort your header-lists if they dont fit into memory ?
>
>Look on Google for tape-sort and merge-sort.  

<smile>
I'm still having my old scripts from the university...

>The basic idea is to
>break the data into chunks that fit into memory, sort and save them
>into temporary files, then merge the chunks back together to obtain
>your complete sorted list. The more tape drives you have, the faster
>you can sort.  You can use disk files instead of scratch tapes, but
>that's cheating.

The charm of having "more tape drives" was that writing could be 
done seperately with full speed to all tape-drives.
A hard-disk with 5 or 10 files would need permanent movements
of the disk-heads. And using 5-10 harddrives is not a serious
option for normal computer users....


>There are quite a few variations on this idea.  You might also
>consider using a database with multiple indexes, this could be easier
>but maybe slower if you end up generating indexes that are rarely
>used.

Yes, maintaining multiple indexes seems to be the consequence.
I just hoped I could avoid the programming work.


Thanks for your answer.
-- 
Juergen

Re: Newsreader programming - sorting one million lines ?
#64517
Author: Juergen Helbing
Date: Tue, 25 Mar 2003 06:25
58 lines
2749 bytes
jeff@litech.org (Jeffrey M. Vinocur) wrote:

>>How do you sort your header-lists if they dont fit into memory ?
>
>Well, in principle a modern memory manager should take care of
>writing them to disk as needed.  (That is, most of the time
>virtual memory will suffice, rather than you having to open a
>temporary file yourself.)

You are right - but we are talking about 1e6 headers with a total
size of approx 1 gig. 

>I wonder if the reason you're having problems is that your sort
>algorithm has poor locality, causing a lot of swapping.

Right now my 150.000 headers are kept fully in memory
(50-75 megs).
There is no swapping at all (on a 256 MB RAM machine).

But this does no longer work with 6 times the quantity.
That's why I'm looking for better methods.


>I just poked at the source for GNU sort(1) from the textutils
>package, and it seems to be using mergesort, which surely would
>have better cache locality than quicksort.  You might try that,

Thanks for the tip.

>Otherwise, I'd say it's time to consult an algorithmicist.
>Either ask in an appropriate newsgroup, or find a textbook.  (I
>just checked the Cormen/Leiserson/Rivest text and didn't see
>anything useful, perhaps Knuth would be an appropriate resource.)

Normally I am one of the specialists for collecting and analysing 
huge masses of measurement trend data.
In a scientific project I had evaluated the "magic triangle" of of
the design targets: "time-to-insert sequentially", 
"time-to-retrieve randomly" and "disk-space".....  

But because that project was done in 1980 I thought it would be
a nice idea to ask here if something changed significantly meanwhile....


I will now either implement full sorting indexes for all criteria
or I will restrict the users to 150.000 items with the chance
to page forward and backwards in the list by date.. (last week,
two weeks ago, ....)


Thanks for your answer.
-- 
Juergen




Re: Newsreader programming - sorting one million lines ?
#64518
Author: Klaas
Date: Tue, 25 Mar 2003 08:40
30 lines
2522 bytes
After careful consideration, Jeffrey M. Vinocur muttered:

> I wonder if the reason you're having problems is that your sort
> algorithm has poor locality, causing a lot of swapping.
> 
> I just poked at the source for GNU sort(1) from the textutils
> package, and it seems to be using mergesort, which surely would
> have better cache locality than quicksort.  You might try that,
> before resorting to drastic measures.  Actually, you can even
> estimate the time you'll need for the memory-access at least:
> take N headers you can hold in memory (say, 1,000,000 of them)
> and do a linear traversal of all of them, and multiply by
> log_2(N) (here, about 20).  If that's acceptable, it's probably
> worth implementing mergesort.

It'd be interesting to see if the improved locality of mergesort helps 
considering its memory requirements (roughly double quicksort), which 
will also cause a lot of swapping.  I'd keep quicksort around for use 
with the smaller groups.

Also, radix sort would work well for sorting by artno (O(n)), although 
it's likely that you'd save the articles in that order anyway.

I definately agree that you should do the multipart combining _first_.  
In large binary groups, that should reduce your problem by 1/20 or so, 
and the articles should already be roughly in the order necessary to 
create the multipart index.

-Mike
Re: Newsreader programming - sorting one million lines ?
#64519
Author: Heiko Studt
Date: Tue, 25 Mar 2003 12:08
104 lines
5532 bytes
Juergen Helbing did nothing on 25.03.2003 07:08:53:

> >Then you save *everything*.
> Yes, I'm having all Xover-headers in a single file.

Ok.

> >You save every XOver(?)-Line in one line in a "Direktzugriffs"-file.
> >(In a kind of form you like)
> >Now you save a pointer to the beginning of the line in a
> >fixed-width-record-file.
> This is already my actual structure.

To go further: Save the things to sort in a different file, or something like
that.

> >Now you load 10 chars from all subjects to memory and save the index of it.
> >Therefor you can use a sorted stringlist. (AFAIK sorting by including is
> >fastest, isn't it?). After all you have a pre-sorted list where you have to
> >resort all "similar" things with full-width subject, date and so on.

> This sounds reasonable and I remember the "5 tape sorting"
> from the 50's :-) Reading the entire file once for presorting
> and making 'small range sorting' on a smaller file-portion
> sounds also good. But there seems to be one big problem:

Those are tow different things:
1 Sort to Ranges, goto 1 til all are sorted

Presort into smaller Ranges, on demand get the "samelooking" into memory 
and sort them with Bubble/Heap-Sort.

If you use the second one you would have a *sorted* index-file and an unsorted.
The unsorted is used to access to different items for sorting.
The same things can be done for threading:

XOver.txt      All XOvers are saved
XOver.idx      Begin of every line is saved by index (0..n)
Threading.idx  For every item the parent is saved and the index in XOver.idx
Sorted.idx     Based on XOver.idx or direct for XOver.txt, sorted.
               The 10 chars used for presorting are saved too.

As you load the 'old' datas you load Sorted.idx and sort it with bubble-sort
again (or otherwise: the best sorting algo for presorted lists)

For being sure you can also try to rebuild XOver.idx before and look if it's
the same as the old file.

Now you load new XOvers, save the *new* XOver at the end of XOver.txt, save
the pointer to XOver.idx and now sort into sorted.idx. If you need to you sort
it into Threading too.


Now, on screen, you want to show a new line: You load the complete XOvers of
those lines you show and those which have the same sorting-10-chars. Now you
can sort *these* in a complete way (subject, Date, else) and save the sorting
to the .idx-file. As you showed every line in your reader you have sorted the
complete XOver-list. As you use Bubble sort for this smaller Ranges, you would
have a good presorting-algo to not waste too much performance.

> The "small range sorting" requires access across the entire
> file (The similar subject is used everywhere within one gig
> of headers). And these disk-accesses are very slow....

Why? You *only* need to get for every XOver the sort-string. This has to be
done in *any* algorithmic as best as this would be. After that you would have
a well-presorted list you can sort on demand. If you use Threading you would
even be able to have a less-sorting.

BTW: If you use Delphi: VirtualTreeview is genious fast, even for sorting.

> >This is a smaller solution in Delphi:
> >      tsl.AddObject(GetSortingItems(s), tObject(temI));

> The "GetSortingItems(s)" seems to include an 
> "fseek(randompostion-within-fullfile)"... and this is

No.
You get the XOver line by line. In *any* case.
Now you can parse this line to get the things you need for sorting (10 chars).

> used 1e6 times....  Having a fast disk with 1 mSec 
> access to every item would still need 1000 seconds....

A fast disc should AFAIK even be faster... ;-P
But you didn't understand me. I want to sort *while* loading the XOvers. BTW:
You have anyway the problem of loading the XOvers out of disk. This can't be
prevented in any kind you want to try.

> Obviously the required time for "external sorting" is
> not acceptable.....

Do you want to save the real XOver to disc afterwards or not? Perhaps I didn't
understand. As this complete discussion is OT, I set a F'up2:Poster. Perhaps a
German-Mailcontact would be less misunderstandable


MFG

-- 
Heiko Studt
http://www.goldpool.org/temp/IMAPHamster.zip 20.3.2003 24:00

Re: Newsreader programming - sorting one million lines ?
#64521
Author: DS
Date: Tue, 25 Mar 2003 18:50
101 lines
5734 bytes
Can I put in my two cents?

First question- Do you mean 1.5 million msg's ? 

That's ALOT of msg's, or any type of data to sort.

As you know, I'm writing a binary d/l'r (and thank you all for your help, 
again), and I don't see nearly that many msg's (currently available to me 
from 4 differnet servers) in a single group. But I could see it possible, 
maybe. So let me explain a little bit of my development path.

When I began to develop this, I tried in-memory sorting, I tried this, I 
tried that. I could not come up with anything that I felt was high-
performance enough. Using a standard listview didn't work. It was way to 
slow for inserting items into. It could sort faster than me, but took a 
REALLY REALLY long time just to load 50,000 items in to the listview. The 
listview itself sorts pretty fast, but the load delay was crazy.

Without the ability to create my own high performance DB engine & the 
time required (I'm doing this on MY time) , I decided to use an outside 
DB engine.

OK, having zero budget, I had no choice but to use M$ Access db's with 
the Jet DB engine.

There it is, the 'cat's out of the bag'. I was putting off and putting 
off letting people know I was using Jet, thru VB none the less for my 
project. Go ahead, laugh, I know it's coming. Perception's of VB vs. C++. 
But I digress....that's a whole 'nother issue, for another newsgroup.

So the plan was develop in VB, get out there, then transpose into C++. I 
couldn't learn the NNTP 'scene' and VC++ at the same time.

Listen, how 'intense' could this be, basically just controlling winsock 
connections, and parsing strings. It's not like graphics filter's or 
thing's like that.

So anyway, I get 'acceptable' performance from the Jet engine. The main 
issue's in performance are downloading header's. My IP meter tells me 
that I top out at about 1 mBit/sec with 5-6 threads d/l'g after XOVER 
command's. That include's receiving a packet, parsing out each header 
dataset, breaking out each dataset into it's relevant parts, fully 
processing the subject line for multi-part detection (not joined at this 
juncture), looking in the database to see if it's there already, and 
adding it if not.

After all server's are processed for a specific group, a seperate process 
is spawned which goes thru that group's db and join's multi-part's, 
mark's complete or not, expires parts that are off the server(s), yadda 
yadda yadda.... For smaller groups this outside process takes 1-2 
seconds. For the larger groups 6-8. It is at this point that the info is 
ready for use and can be diplayed.

So displaying them I use a 'virtual' listview. Doing this allows me to 
use a table with million's of records and they are all diplayed instantly 
w/o having to load them into a listview. Additionally, all sorting and 
filtering is done by Jet and not me. I just pass an SQL open statement, 
and receive the data I want, sorted how I want, from the groups I want. 
Jet is WAYYYYYYYYY more efficient than I could ever be.

One of my features is 'Virtual Groups' which combine many groups into one 
view. Some quick (altho unscientific) benchmarks:

Virtual group contains 7 groups-alt.binaries.cd.image, a.b.c.i.reposts, 
a.b.c.i.highspeed, a.b.c.i.parts, a.b.i.c.clonecd, a.b.c.i.c.reposts, 
a.b.c.i.games.

After adding up the number of article in their db's. I came out to 
roughly 150,000. About the same number as you had been limiting your list 
to. Your time's reported were for 500K msg's tho. So obviously my numbers 
would be x 3, at least.

What I can tell you is that querying that virtual group, it takes about 
25 seconds for me to open the db, filter out what is NOT to be shown & 
sort, and display it in the virtual listview. Out of the 150,000 ish 
headers, some 5500 or so were actually displayed being either text 
messages, or a single header for a multipart download. Subsequently, each 
column-header click done to re-sort that group in a different manner 
takes 3-4 seconds. A re-sort closes the entire table and open the new 
recordset with the new sort. In the 3-4 seconds. 

When ZaNews is re-written in C++, I estimate a 15% - 25% increase in 
speed. I have come up with this number as an opinion formed by reading 
many bench mark tests for 'other' database engine controls comparing 
their performance between using it is VB or C++.

OK, everyone can laugh now about VB and Jet here. But I'll tell you, so 
far it's been working. Header downloads is the only 'very high' overhead 
that is done. And once you start d/l'g and managing parts and such, the 
actual db action should be quite light.

Regards,

DS

PS- I don't really think I answered his question even....sorry.




Re: Newsreader programming - sorting one million lines ?
#64529
Author: Juergen Helbing
Date: Wed, 26 Mar 2003 06:38
138 lines
6265 bytes
Heiko Studt <UsenetBecky@goldpool.org> wrote:

>Now, on screen, you want to show a new line: You load the complete XOvers of
>those lines you show and those which have the same sorting-10-chars. Now you
>can sort *these* in a complete way (subject, Date, else) and save the sorting
>to the .idx-file. 

Sorting while display is done seems to be an attractive method.
Unfortunately it fails if someone wants to 'seek forward'...
(Skip to next unread message.... Find text, ....)
Then the sorting is done in the background and the desktop
does not update for a long time.


>Why? You *only* need to get for every XOver the sort-string. This has to be
>done in *any* algorithmic as best as this would be. 

The problem of sorting huge files is locality:
If sorting is done chunks and the file is read sequentially, then
sorting can be very fast (the old 'tape-sorting' methods are using
this approach).
But as soon as it comes to "random access" to a one gig file
then the access-time of the harddisk is the bottleneck.
And even very fast harddisks need 3-5 mSecs (or more)
to read a small block which is 10 tracks ahead.


>No.
>You get the XOver line by line. In *any* case.
>Now you can parse this line to get the things you need for sorting (10 chars).

This seems to be a kind of "hashing" - the hash is the first N chars of
the sort-item. This wakes my curiosity:
If a sorting job cannot be done in memory (too large) 
- and not on harddisk (too slow) - then using a "mix method"
which reserves just the memory for the hash could be a solution
to _max_out_ the performance of the sort.
It would be even possible to vary the size of the hash depending
on available memory....

>> used 1e6 times....  Having a fast disk with 1 mSec 
>> access to every item would still need 1000 seconds....
>
>A fast disc should AFAIK even be faster... ;-P

AFAIK it would be even slower.

>But you didn't understand me. I want to sort *while* loading the XOvers. BTW:
>You have anyway the problem of loading the XOvers out of disk. This can't be
>prevented in any kind you want to try.

If I understand you correctly then I'm reading the Xover file sequentially.
I'm extracting the first N chars of the sort item (as hash) and keep them 
sorted in memory. Sounds all very good.
If I find an item with an identical hash now then it is necessary to 
reload all the items with the identical hash and compare then fully
to the current item to sort.
Now the problem: This could be a lot in the newsgroups: 
Many Subject - or From lines have identical first 10 chars.

If the actual read Subject would be:  Startrek Enterprise - ......
and a video multipart post (usually 1000-2000 headers) was
done one week ago (headers 1000-3000) and now again
(headers 560.000 - 562.000) then it would be necessary
to compare 2000 times a string with older strings from the harddisk.

The problem is then that the 'old strings' (with identical hash)
must be accessed 2000 times _again_and_again !

Of course it would be possible that the 'old strings' are still
in the disk-cache - but if a few posts are overlapped then
this will result in a lot of disk-accesses.

It seems to be necessary to implement a test.


Please understand me right:
I'm not saying that your method is bad. It sounds really good.
Therefor I'm trying to discuss it with you in depth.

>Do you want to save the real XOver to disc afterwards or not? 

No - the Xover file is on the harddisk because I need it for delivery
to clients. (MyNews is a server which delivers the full header-list
to clients - even if no articles are available yet).

Until today I am _not_ keeping sort-indices for the XOVER file.
Of course this is a problem of incremental design: MyNews was
never designed to handle one million headers in one group.

And now I'm trying to find a solution how to implement this new
requirement: Either I'm finding better sorting methods - or I need
to create (and maintain - and expire) sorting indices - which would
be even more work (and slower than everything else)....


>Perhaps I didn't understand. 

Your understanding is very good.


>As this complete discussion is OT, I set a F'up2:Poster. 

Computer scientists in an 'algorithm' newsgroup would believe
that I'm completely mad. Their default answer would be to use 
a database. Such people who are regularily dealing with huge
databases have no idea about Usenet and the special requirements
for downloading enormous amounts of new data all the time,
sorting and presenting them on the users desktop - and (mostly
important) to expire them.....

Our problems when we are writing news-readers and new-servers
are so specific (and demanding) that news.software.nntp would be
the only newsgroup where things are really understood.

And be sure - earlier or later all NNTP software programmers
are having the same problems. Then they can google for the
solution :-)
  
If any of the elders or admins believes that the discussion of
my question would belong to another newsgroup, then please
let me know. 

>Perhaps a
>German-Mailcontact would be less misunderstandable

If I'm going to implement a test-version of your approach 
and have problems with it, then I'll contact you directly.
But because also other interesting answers were posted
I believe that we can stay here for the next two levels.


Thanks for sharing your experience with me.

-- 
Juergen

Re: Newsreader programming - sorting one million lines ?
#64531
Author: Juergen Helbing
Date: Wed, 26 Mar 2003 06:44
33 lines
2032 bytes
Klaas <spamhole@klaas.ca> wrote:

>It'd be interesting to see if the improved locality of mergesort helps 
>considering its memory requirements (roughly double quicksort), which 
>will also cause a lot of swapping.  I'd keep quicksort around for use 
>with the smaller groups.

I am using always heapsort - because it offers a stable sorting
time even for presorted or reversly persorted lists:

A newsreader (my newsreader) is offering all kind of sorting:
Forward and backwards.... And I want to have a constant sorting
time. I believe that users dont like to wait very long....

>I definately agree that you should do the multipart combining _first_.  
>In large binary groups, that should reduce your problem by 1/20 or so, 
>and the articles should already be roughly in the order necessary to 
>create the multipart index.

This seems to be a good idea.
But unfortunately doing the multipart combining requires sorting by
subject. So sorting by subject cannot be done after multipart joining.

And sorting by author with previous multipart elimination requires 
to sort first by subject, then eliminating multiparts and then again
sorting by author.....

Or am I wrong ?

-- 
Juergen

Re: Newsreader programming - sorting one million lines ?
#64532
Author: Juergen Helbing
Date: Wed, 26 Mar 2003 07:13
129 lines
6185 bytes
DS <t.h.i.s.n.t.h.a.t@a.d.e.l.p.h.i.a..n.e.t> wrote:

>Can I put in my two cents?

Of course - that's why I am asking the group :-)


>First question- Do you mean 1.5 million msg's ? 
>That's ALOT of msg's, or any type of data to sort.

Yes. 
And if you believe that this would be ridiculous:

Some newsgroups are having already _today_ 30.000
and more headers per day. The volume (and the headers)
will continue to grow.
And it seems to be one of the major requirements to 
_combine_ several newsgroups into one (folder) - especially
if they contain similar topics (or are often used for xposts).

I am myself scanning some newsgroups only once a week.
And after a two week vacation most large binary groups
I'm scanning today cause already an overflow (of my 
internal 150.000 lines limit).

With a retention of 30-60 days I am using myself the amount
of headers is enormous.

Earlier or later more newsreader programmers will have
similar problems (or did solve them already).


>There it is, the 'cat's out of the bag'. I was putting off and putting 
>off letting people know I was using Jet, thru VB none the less for my 
>project. Go ahead, laugh, I know it's coming. Perception's of VB vs. C++. 

Programming is a question of clue and libs - not of the used language :-)
Our professors smiled when we started learning BASIC for PET2001
but they changed their mind quickly when they recognized that 
computer science was not limited to 'Pascal'  ;-)


>So anyway, I get 'acceptable' performance from the Jet engine. The main 
>issue's in performance are downloading header's. My IP meter tells me 
>that I top out at about 1 mBit/sec with 5-6 threads d/l'g after XOVER 
>command's. That include's receiving a packet, parsing out each header 
>dataset, breaking out each dataset into it's relevant parts, fully 
>processing the subject line for multi-part detection (not joined at this 
>juncture), looking in the database to see if it's there already, and 
>adding it if not.

If you are able to process 2000-3000 headers per seconds then
you are doing a great job.

>After all server's are processed for a specific group, a seperate process 
>is spawned which goes thru that group's db and join's multi-part's, 
>mark's complete or not, expires parts that are off the server(s), yadda 
>yadda yadda.... For smaller groups this outside process takes 1-2 
>seconds. For the larger groups 6-8. It is at this point that the info is 
>ready for use and can be diplayed.

Joining and expiry ?   I'm deeply impressed.
It seems that you are running a very fast PC-machine.

>Additionally, all sorting and 
>filtering is done by Jet and not me. I just pass an SQL open statement, 
>and receive the data I want, sorted how I want, from the groups I want. 
>Jet is WAYYYYYYYYY more efficient than I could ever be.

You are using the approach to keep all necessary sorting indices 
on the harddisk. 
It would be really interesting to know how this performs after some
weeks of operation when the disk is fully fragmented.
But the jet-database engine might be powereful enough
to solve all those problems externally.

>What I can tell you is that querying that virtual group, it takes about 
>25 seconds for me to open the db, filter out what is NOT to be shown & 
>sort, and display it in the virtual listview. Out of the 150,000 ish 
>headers, some 5500 or so were actually displayed being either text 
>messages, or a single header for a multipart download. Subsequently, each 
>column-header click done to re-sort that group in a different manner 
>takes 3-4 seconds. A re-sort closes the entire table and open the new 
>recordset with the new sort. In the 3-4 seconds. 

Very impressive numbers.


>When ZaNews is re-written in C++, I estimate a 15% - 25% increase in 
>speed. I have come up with this number as an opinion formed by reading 
>many bench mark tests for 'other' database engine controls comparing 
>their performance between using it is VB or C++.

I dont believe that you'll see any improvements in speed:
VB and C++ are similar compilers - and the speed gains for C++ are
usually caused by lack of plausibility checks. So your C++ version
might be even more unstable.
And most work is done on the harddisk-subsystem and the external
database - which wont be faster.
So if I were you then I would not transpile the software from VB to C.


>OK, everyone can laugh now about VB and Jet here. But I'll tell you, so 
>far it's been working. Header downloads is the only 'very high' overhead 
>that is done. And once you start d/l'g and managing parts and such, the 
>actual db action should be quite light.

There is no reason to be ashame.
You've done a great job and sharing your experience might be 
very helpful for other programmers.

>PS- I don't really think I answered his question even....sorry.

You did: you've demonstrated me that an external database can 
be very efficient for the problem solution. And that updating headers
after retrieval and expiry _can_ be done very fast even if all sorting
is also kept and maintained on the disk.

So the consequence for me would be to implement a database for
the headers.....  (or to use an external one as you did)...


Thanks for taking the time for your detailled report.
It was a pleasure to read it.

-- 
Juergen

Re: Newsreader programming - sorting one million lines ?
#64533
Author: Heiko Studt
Date: Wed, 26 Mar 2003 11:25
60 lines
3360 bytes
Juergen Helbing did nothing on 26.03.2003 07:44:07:

> I am using always heapsort - because it offers a stable sorting
> time even for presorted or reversly persorted lists:

But becuase of presorted lists this is *very* bad!

A B C D E F G I H

would be done (twisted) in nlog(n) to another string
and *THEN* it would be done to be sorted in nlog(n) again.

With bubble-sort you need only go and look and (at the end!) 
twist I with H.

Perhaps therefor this 'new' algorithmic would be fine:

Get the count of items which are 'higher' than the next one and the count of
items which are 'lower' than the next one.
Now, depending on the result, you can choose wether you use heap-sort (count
near '0'), bubble sort in reverse (count very negative eg -1000) 
or normal bubble sort (count very high eg 1000).

This would help to cut the *highest* time (presorting in reverse order) and
set it to half (presorting in both halfth of array).
But even this could be done in a better way:

If you reach a special count (500 or -500) you use this part as a presorted
part. Now you go further and get again the special count. This part is again
presorted. And so on.
Now you can try to reverse those parts which are very low (-500), so they are
(+500). At the end you can sort the complete list without too much overhead of
changing positions.

> A newsreader (my newsreader) is offering all kind of sorting:
> Forward and backwards.... And I want to have a constant sorting

Forward and backwards are *no* sorting. They are a form of presenting.

> time. I believe that users dont like to wait very long....

ACK.

> But unfortunately doing the multipart combining requires sorting by
> subject. So sorting by subject cannot be done after multipart joining.

> Or am I wrong ?

"References". I don't fetch binaries, but those should add this header too,
don't they? But you will *ever* have to save indexes to prevent users to sort
the local database again and again.


MFG

-- 
Heiko Studt
http://www.goldpool.org/temp/IMAPHamster.zip 20.3.2003 24:00

Re: Newsreader programming - sorting one million lines ?
#64540
Author: J.B. Moreno
Date: Wed, 26 Mar 2003 20:16
15 lines
1623 bytes
In article <b5s66v.1t4.1@Heiko.Studt.dialin.t-online.de>, 
 Heiko Studt <UsenetBecky@goldpool.org> wrote:

> With bubble-sort you need only go and look and (at the end!) 
> twist I with H.
> 
> Perhaps therefor this 'new' algorithmic would be fine:

A bubble sort is unsuitable for anything beyond a few hundred items,
some sort of insertion sort would be vastly preferable (preferably with
a dynamic index to speed things up).

-- 
J.B. Moreno
Re: Newsreader programming - sorting one million lines ?
#64543
Author: Heiko Studt
Date: Wed, 26 Mar 2003 21:52
61 lines
4185 bytes
J.B. Moreno did nothing on 26.03.2003 21:16:15:

> > With bubble-sort you need only go and look and (at the end!) 
> > twist I with H.

> A bubble sort is unsuitable for anything beyond a few hundred items,
> some sort of insertion sort would be vastly preferable (preferably with
> a dynamic index to speed things up).

It was a small example. We are talking about a very huge article base of more
than 10.000.000 articles. Therefor a 'normal' selectionsort/insertion sort
without need is a bad thing. Exspecially if the list is presorted.

I thought a bit more about the sorting-problem today, but I don't think my
thoughts would be useful. It's too easy to be not found by another one and
deleted after a 1-year-try to sort a small list. ;-)
Perhaps I should talk about it in an algorithmic-group first, but yet I don't
know where and if I should do so at all. If you say 'NOOO' say so and for me
it would be EOT.

Here I go:

My idea has something to do with 'relative' extrema. It should help to sort 
(presort) a list with the best algorithmic useable for this purpose.
We have a list of n items, now we go through this list and count how many
items are going pass, those are 'x'. Now, if the item we found is smaller than
the item before we decrease a second counter. Now we look three items
backwards if there was an "extrema" during these. If no, we are going further.
If there was an extrema we look back in our 'history' where our last extrema
were. If the level-difference is very high we are sorting with the algorithmic
we can do best for 'presorted' lists. (AFAIK Bubblesort) We can even look if
there were only, let us say, six items in between. Therefor we don't need any
sorting here.
Afterwards we sort this part and save the level and the points where we have
this pre-sorted-lists. Now we are going further.
At the end we try to set the list together with the saved levels, so that
allmost all parts are sorted. After this we can use a *small* bubblesort of 
at the maximum 20 going through.
All this would be best for "presorted" lists, even if this would be a
'parabell', of course we need to reverse some parts of the sorted items, but
this doesn't matter.

The going-through for finding the extrema should need around n counts. ->O(n)
The sorting of the parts should be, if the curve would be like sinus, around
O(n/z), where z is the count between the extrema of the sinus. It's influenced
by the settings we gave.

The last sorting, if we analyse the levels of the extremas quite right, we
would need around one going throughs.

At all it would be in the best kind of need of sorting a O(n)*3.
On the worst side of view it should *not* be O(n*(n/2)), it should be better.



MFG, am confused.

-- 
Heiko Studt

Re: Newsreader programming - sorting one million lines ?
#64544
Author: Jeffrey M. Vinocur
Date: Thu, 27 Mar 2003 01:03
24 lines
2061 bytes
In article <b5tb09.1hk.1@Heiko.Studt.dialin.t-online.de>,
Heiko Studt  <Heiko.Studt@gmx.de> wrote:
>
>I thought a bit more about the sorting-problem today, but I don't think my
>thoughts would be useful. It's too easy to be not found by another one and
>deleted after a 1-year-try to sort a small list. ;-)
>Perhaps I should talk about it in an algorithmic-group first, but yet I don't
>know where and if I should do so at all. If you say 'NOOO' say so and for me
>it would be EOT.

I think you guys are making mountains out of molehills here.  I
just sorted 500,000 lines of news logfiles (about 150 characters
per line), and it takes a bit under 2 sec on my system.  This is
a 850 MHz PIII with 256 MB of memory, using sort(1) from GNU
textutils, version 2.0.14.

I really don't think you need to starting thinking up new
algorithms from scratch here.


-- 
Jeffrey M. Vinocur
jeff@litech.org
Re: Newsreader programming - sorting one million lines ?
#64545
Author: Jeffrey M. Vinocur
Date: Thu, 27 Mar 2003 01:14
54 lines
3106 bytes
In article <11387.q33208@archiver.winews.net>,
Juergen Helbing <archiver@i3w.com> wrote:
>Heiko Studt <UsenetBecky@goldpool.org> wrote:
>
>>> used 1e6 times....  Having a fast disk with 1 mSec 
>>> access to every item would still need 1000 seconds....
>>
>>A fast disc should AFAIK even be faster... ;-P
>
>AFAIK it would be even slower.

Keep in mind that if you use an appropriate algorithm, you
shouldn't need random access.  And linear access can be cached
quite nicely by your operating system (and the drive itself).


>If I understand you correctly then I'm reading the Xover file sequentially.
>I'm extracting the first N chars of the sort item (as hash) and keep them 
>sorted in memory. Sounds all very good.
>If I find an item with an identical hash now then it is necessary to 
>reload all the items with the identical hash and compare then fully
>to the current item to sort.
>Now the problem: This could be a lot in the newsgroups: 
>Many Subject - or From lines have identical first 10 chars.

Of course, if you know what parts of the Subject are likely to be
the multipart [x/y] indicator, you could do multipart recombining
before sorting (using a hashtable, with a hash function on all of
the string except for "x").


>Our problems when we are writing news-readers and new-servers
>are so specific (and demanding) that news.software.nntp would be
>the only newsgroup where things are really understood.

I strongly disagree here.  If you go to a good computer scientist
and say "Here is a very precise specification for my problem:  I
have this much data, and it changes at such-and-such a frequency,
and I need to support the following operations" then you will
receive an appropriate answer.


>If any of the elders or admins believes that the discussion of
>my question would belong to another newsgroup, then please
>let me know. 

I don't *mind* -- but I think you'd have more _success_
elsewhere.


-- 
Jeffrey M. Vinocur
jeff@litech.org
Re: Newsreader programming - sorting one million lines ?
#64548
Author: JanC
Date: Thu, 27 Mar 2003 05:32
20 lines
1831 bytes
DS <t.h.i.s.n.t.h.a.t@a.d.e.l.p.h.i.a..n.e.t> schreef:

> OK, having zero budget, I had no choice but to use M$ Access db's with 
> the Jet DB engine.

There are several open source DB engines with C/C++ APIs for Windows...

MS Access saves *all* data & indexes from all DB tables in 1 file, and the 
file size limit on FAT32 partitions is about 2 GiB (2^31 bytes).
I think you'll reach that limit faster than you wished...

(And even on WinNT/2K/XP many people use FAT32 data partitions for 
compatibility with other operating systems.)

-- 
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
Re: Newsreader programming - sorting one million lines ?
#64565
Author: Juergen Helbing
Date: Fri, 28 Mar 2003 06:27
25 lines
1636 bytes
jeff@litech.org (Jeffrey M. Vinocur) wrote:

>I think you guys are making mountains out of molehills here.  I
>just sorted 500,000 lines of news logfiles (about 150 characters
>per line), and it takes a bit under 2 sec on my system.  This is
>a 850 MHz PIII with 256 MB of memory, using sort(1) from GNU
>textutils, version 2.0.14.

WOW, this is really fast.

>I really don't think you need to starting thinking up new
>algorithms from scratch here.

With approx 75 megs of filesize the sort(1) seems to be 
really fast. Under 2 secs is already a disk-transfer rate for
38 megs/sec..... 
My 2 years old IDE disk has just 10 megs/sec in my older 
private-news-server-PC.

Thanks for the link to sort(1).

-- 
Juergen

Re: Newsreader programming - sorting one million lines ?
#64570
Author: greg andruk
Date: Fri, 28 Mar 2003 08:32
10 lines
1962 bytes
archiver@i3w.com (Juergen Helbing) writes:

> The "small range sorting" requires access across the entire
> file (The similar subject is used everywhere within one gig
> of headers). And these disk-accesses are very slow....

If you are seeing a severe disk bottleneck, you should also suspect
the language or compiler.  There are, for example, surprising
differences between Symantec, MS, Borland and GNU stdio speeds.
Re: Newsreader programming - sorting one million lines ?
#64575
Author: DS
Date: Fri, 28 Mar 2003 13:37
21 lines
1623 bytes
JanC <usenet_spam@janc.invalid> wrote in
news:Xns934B428C69A95JanC@213.118.75.56: 

> DS <t.h.i.s.n.t.h.a.t@a.d.e.l.p.h.i.a..n.e.t> schreef:
> 
>> OK, having zero budget, I had no choice but to use M$ Access db's
>> with the Jet DB engine.
> 
> There are several open source DB engines with C/C++ APIs for
> Windows... 
> 
> MS Access saves *all* data & indexes from all DB tables in 1 file, and
> the file size limit on FAT32 partitions is about 2 GiB (2^31 bytes).
> I think you'll reach that limit faster than you wished...
> 

Already accounted for that. Not an issue at this time. 


DS
Re: Newsreader programming - sorting one million lines ?
#64585
Author: Curt Welch
Date: Sat, 29 Mar 2003 00:46
165 lines
11023 bytes
archiver@i3w.com (Juergen Helbing) wrote:
> So here finally my question:
> How do you sort your header-lists if they dont fit into memory ?
>
> I believe that sorting "1.500.000" lines simply by 'users-click'
> is a very demanding job - and such quantities appear only on
> the binary usenet today....

I've never had to solve that problem with my newsreaders, but I can throw
out a few things for you to think about.

With all interactive software, pure software speed isn't important.  Don't
get lost focusing on algorithms.  What's important is the responsivness of
the application.  This has as much to do with UI design as it does with
optimizing performance of algorithms.  Most good applications work not
because they simply "are" fast, but because they "seem" fast.  Most the
time, it's just a magic trick, and illusion.  Your problem is not that it
takes 60 seconds to sort 1.5M records, your problem is that the user is
being forced to wait 60 seconds doing nothing after they click a button
asking for the list to be resorted.  So, many times, the best soltion is
not to make the sort run in 10 seconds instead of 60, the solution is to
find a way that the user is not forced to set their waiting at all.  One
option for example, is to remove the button.  Don't laugh.  :) An
interactive application that takes 60 seconds to respond to a direct
request is unuseable.  It is almost always better to leave the feature out
of the application than to put one in which is unusable.

However, the far better approach than leaving a feature out is to find a
way to make it useable.

Finding a faster sort algortihm is one options which you have asked about
here.  The idea of "trust the vm system" is probably stupid.  nothing I've
seen about PCs tells me that you can put any trust into the vm system.
I've not done in real windows programming, but from my use of applications
on PCs, the worst thing you can do is trust the vm system.  that's because
to control responsifness of the applicsiton, you have to control what gets
swapped out, and when.  You never for example want UI code or data (like
the code for drawing buttons, or refreshing a window) to be swapped out.
YOu never want to user to have to wait 10 seconds for the vm to swap the IU
code back in before the application responds to you hitting an abort
button.  Applications that look to me like they took the "trust the vm"
option constantly have problems like that and they are, in my book,
unusable.  So don't trust the vm.  Make your appliction do the disk IO so
you can control when it happens and so that your disk IO "workload" never
gets in the way of UI code.

Second, sorting data that is stored on disk, and which must be written to
disk after the sort is easy.  You just do merge sort.  You read the data
sequential from disk, stoping when you have good sized chunk, then you sort
that chunk, and write it out to the disk.  Repeat until the entire data set
is sorted into N chunks.  Then, do a merge of X chunks at a time (where X
is N if possible and resonable), writing the outputfile as you merge.  When
correctly optimized, the time it takes to to this is limited by disk IO
speed, not CPU or sort speed.  The CPU is sorting/merging while the disks
are busy reading or writing data.  So the time is based on how many times
you have to read and write the data, and that's based on the memory size
based on the set size.  But, for your applacation, running on a smaller PC,
I doubt this will ever be fast enough to justify doing all that after they
hit the "sort by date" button.

So, you need too look for magic tricks.

The first and probably most useful trick is do the work at some other time
instead of waiting until they hit the "sort" button.  For a newsreader, the
data you are talking about is header data, and all header data has to be
downloaded.  Downloading headers always takes a lot of time and there's no
way around that, so an obvious thing to look at is doing all the sorting
work while it's being downloaded and you have time to waste as it is.  So
look at options of how to do as much work as you can while the data is
being downloaded.  And as always, you must keep the needs of the aplication
in mind, don't focus on "the sorting problem" and loose site of the big
picuture.

So, a newsreader needs to download headers, and store them in some type of
pre-sorted fashion on the disks.  But then, it needs to add more headers
the next time you download.  So, do you re-sort the entire batch (causing
you to re-read the entire set of data from the disk), or can you store it
some clever way to prevent you from having to do all that work every time
you download new headers?

For example, if you wanted to sort by author, and lets pretend that authors
names are created only from the letters a to z, then as you download the
headers, you can sort them into one of 26 buckets (a to z) based on the
first letter of their name.  You can then have 26 files (or logical files)
on the disk, so as you download, you collect the names in memory in these
buckets until a bucket gets enough data, then you write all the T's for
example out to the end of the T file, not bothering to sort the names
within the file.  So when you download new headers, you do part of the sort
work, but not all of it.  You just get all the Ts into the same file.

Then, when you want to disply the headers, you read and sort the A file to
get the first records.  Once you have done that, you can display all the
"A" authors even though you haven't sorted the rest of the files.  Depnding
on how the rest of the UI works, you may not even need to sort the rest
yet.  You might be able to put off the sort until they scroll down in the
list and try to look at other records.

So, this idea has issues, but the point of the example is trying to get you
to realize that there are a lot of tricks you can used based on the needs
of the application to do the work at different times so the user never has
to wait for the application to sort the entire 1.5M records.

There's also a psychological effect that happens when you spread the work
out over a long time instead of doing it all at once.  For example, an
applicaiton which sorts a little bit and causes small .5 second pauses
while downloading can seem much "faster", than one which waits until the
end of the download and "hangs" for 2 mintues doing what looks like
"nothing" while it does all the sort work after the download of new
headers.

Genreally, what you have said in your other posts I belive is the direction
you will have to go in.  You need to build indexes of some type which
represents the sorted data on the different fields you want to sort on
(date, author, size, whatever).  But look for creative ways to represt this
data so that it's both fast and easy to update while downloading, and
remeber that you can put of some of the work for later as long as what you
leave for later doesn't make it too slow when they actually hit a "sort by
date" button.

Also, when working with data on disk, and issues of sort times that are a
function not of CPU speed, but of disk speed and memory size vs data set
size, it's important to reduce the size of the data as much as possible.
For example, if you simply store 1.5M xover records in their normall wire
format, the time to sort that entire set by date will mostly be a function
not of the number of records you are sorting, but the total number of bytes
of data you have to sort.  1.5M xover records will be about 500 bytes per
record or 750 MBytes of data to sort.  If you want to sort by date, you can
for example pre-convert the date to a 32 bit unix time value, and store
that along with some pointer or reference to the real article.  If the
pointer is 32 bits, you then have 8 bytes per record instead of 500, then
the data set size gets reduced by a factor of 62 and the sort time is
reduced by more than that.  So what might have been a 60 second delay to
sort the entire data (unworkable) becomes a .5 second delay to sort the
date index alone (very workable).

And even if you find the need to sort the entire data set, if you can find
a way to store it that reduces the dataset size by a factor of 10, the sort
times are going to be reduced by more than a factor of 10.  And these gains
are far more important than the issue of "how to sort 1.5 m records when
they don't fit in memory".  And header data is very compactable because
there is lots of redundancy in the subjects, the authors, the groups, and
the references.

And back to the "magic" tricks, another good one to use is to make the user
think the job is done when it's not.  When they hit sort, you don't in fact
need to sort the entire set, you only need to figure out the part that's
going to be displayed in the current window.  If it's showing the first 50
articles in the set, then all you have to figure out is which 50 articles
out of the 1.5M are the ones which will show up in the window, and then
update that first.  Once the window is update, then the software can go
about doing the rest of the work while the user looks at that and thinks
about what button to hit next.  This can give you 5 seconds of "free" time
to work with.  This stuff however requies complex event driving
multi-threaded stuff that's real tricky to get right because if they hit
the "sort by author" button before your code is done sorting by date, you
need to abort the sort-by-date work, and start on the sort-by-author work.

So, maybe you didn't want to hear all this, and it's no simple answer for
how to huge amounts of article data quickly, but it may give you some
things to think about that will help you solve your problem....

-- 
Curt Welch                                            http://CurtWelch.Com/
curt@kcwc.com                          Webmaster for http://NewsReader.Com/
Re: Newsreader programming - sorting one million lines ?
#64589
Author: Marcus Mönnig
Date: Sat, 29 Mar 2003 10:22
12 lines
1718 bytes
Curt Welch wrote in <20030328194656.482$xw@newsreader.com>:

> So, maybe you didn't want to hear all this, and it's no simple answer for
> how to huge amounts of article data quickly, but it may give you some
> things to think about that will help you solve your problem....

That was one excellent posting about real-world programming_ Thanks Curt.

Marcus
-- 
Instant sex will never be better than the kind you have to peel and cook.
Re: Newsreader programming - sorting one million lines ?
#64609
Author: Juergen Helbing
Date: Mon, 31 Mar 2003 08:52
31 lines
1844 bytes
jeff@litech.org (Jeffrey M. Vinocur) wrote:

>Keep in mind that if you use an appropriate algorithm, you
>shouldn't need random access.  And linear access can be cached
>quite nicely by your operating system (and the drive itself).

Yes, indeed.
I was hoping to find some kind of good sorting algorithm with
mostly 'linear' disk access. And it seems that the "good old"
algorithms are still them same as 25 years ago.

>I don't *mind* -- but I think you'd have more _success_
>elsewhere.

Perhaps you are right.
But all people I've met until now told me that a true database
would be the best. Of course my faible to use a full database
software "just to run a newsreader" was pretty low. And especially
the expiry - and the amount of sorting features might blow up
the required volume for harddisk space enormously.
So the latest experiences from that guy who has a 
"lighting fast database" makes me re-evaluating my approach.

Thanks for your feedback. It helped a lot.

-- 
Juergen



Re: Newsreader programming - sorting one million lines ?
#64611
Author: Juergen Helbing
Date: Mon, 31 Mar 2003 09:00
40 lines
2140 bytes
Heiko Studt <UsenetBecky@goldpool.org> wrote:

>> I am using always heapsort - because it offers a stable sorting
>> time even for presorted or reversly persorted lists:
>
>But becuase of presorted lists this is *very* bad!

Yes - of course. But currently my lists are not presorted.
These are the XOVER cache files as they are - rougly
sorted by time.
I prefer personally stable sorting algorithms.
That is why I'm using heapsort (and B-Trees).

>> But unfortunately doing the multipart combining requires sorting by
>> subject. So sorting by subject cannot be done after multipart joining.
>
>> Or am I wrong ?
>
>"References". I don't fetch binaries, but those should add this header too,
>don't they? 

No they dont (until now. I'm trying to invent this ;-)

>But you will *ever* have to save indexes to prevent users to sort
>the local database again and again.

It seems that you are right:
My previous approach to keep the stuff in memory as long as possible
was good - and very efficiently when it came to integrity checks, expiry,
repair, threading, sorting.....
But obviously it would be time to either use blocks (display per week)
to have an easy and fast solution - or to maintain a bunch of indexes
- with all required work for maintenance, updating, delete and expiry.

Thanks for your feedback. It was very instructively.

-- 
Juergen

Re: Newsreader programming - sorting one million lines ?
#64610
Author: Juergen Helbing
Date: Mon, 31 Mar 2003 09:05
30 lines
1863 bytes
JanC <usenet_spam@janc.invalid> wrote:

>There are several open source DB engines with C/C++ APIs for Windows...

Nice to know.
Do you have any example (before I choose the wrong one ?)

>MS Access saves *all* data & indexes from all DB tables in 1 file, and the 
>file size limit on FAT32 partitions is about 2 GiB (2^31 bytes).
>I think you'll reach that limit faster than you wished...

I'm keeping data in chunks and "article-database files" which are 
designed to avoid the 2 GB limit for FAT32.

And an Xover file with 2 Gigs would be ~ 4.000.000 headers. (in on group)
I dont expect that size soon - and I am already maintaining
Xover-cache-files 'per month'..  :-)

Of course it is absolute nonsense to write and offer a personal
news-server/reader which is able to hold some terabytes of data.
But I'm prepared even for this situation.
Just the "presentation" and "segmentation" is still questionable.

But after all that feedback I'm now closer to a solution.
Thanks for your feedback - and the warning.

-- 
Juergen

Re: Newsreader programming - sorting one million lines ?
#64612
Author: Juergen Helbing
Date: Mon, 31 Mar 2003 09:40
163 lines
7646 bytes
curt@kcwc.com (Curt Welch) wrote:

>I've never had to solve that problem with my newsreaders, but I can throw
>out a few things for you to think about.

Your feedback is always highly appreciated.

>With all interactive software, pure software speed isn't important.  Don't
>get lost focusing on algorithms.  What's important is the responsivness of
>the application.  This has as much to do with UI design as it does with
>optimizing performance of algorithms.  Most good applications work not
>because they simply "are" fast, but because they "seem" fast.  Most the
>time, it's just a magic trick, and illusion.  

  <vbg>.... We are playing in the same league.
   Of course my newsreader is doing already a lot of work while it 
   displays lines... or in the background.

>Your problem is not that it
>takes 60 seconds to sort 1.5M records, your problem is that the user is
>being forced to wait 60 seconds doing nothing after they click a button
>asking for the list to be resorted.  

This is correct for 'normal' displays. And this is the reason why I'm
here in n.s.nntp:
If a newsreader offers a function to "skip to next unread thread"
then searching begins.....
Especially if a single keystroke permit to switch display between
'all msgs' and 'hide specified lines'...

I am already keeping a lot of info in 'additional indexes' - but they are
still related (a part of) to the individual header lines.

I am myself switching often display modes: 
"Sort by author" - to see if that guy posted other things.
"Sort by subject" - for regular scanning binary groups
"Sort by date" - for reading threads and older msgs.
"Sort by filename"  - for finding missing and reposted segments....


>So, many times, the best soltion is
>not to make the sort run in 10 seconds instead of 60, the solution is to
>find a way that the user is not forced to set their waiting at all.  One
>option for example, is to remove the button.  Don't laugh.  :) 

Please apologize - I could not resist:   <vvvvbbbbbgggg>

>An
>interactive application that takes 60 seconds to respond to a direct
>request is unuseable.  It is almost always better to leave the feature out
>of the application than to put one in which is unusable.

This is right - and my "sorting times" are now close to 10-30 secs
(with a progress indicator) - and before the app becomes unusable
I'm looking for solutions...

>The idea of "trust the vm system" is probably stupid.  

Yes - I can confirm this.

>YOu never want to user to have to wait 10 seconds for the vm to swap the IU
>code back in before the application responds to you hitting an abort
>button.  

Unfortunately exactly this happened (for me) when a 300 Meg file
is decoded and written to disk. The  fclose()  then flushes the file
and it takes sometimes endlessly until the  fclose()  is done.  
(Of course flushing every 10 Megs is also no big fun - but a bit better :-)


>The first and probably most useful trick is do the work at some other time
>instead of waiting until they hit the "sort" button.  For a newsreader, the
>data you are talking about is header data, and all header data has to be
>downloaded.  

Good point. 
Of course I am already doing 'filtering' while headers are coming in
- and duplicate detection (multihost readers need this) and xpost
detection....
With a good DSL line there are 300 headers/second coming in.
And already filtering with 30 rules - and a msgid database of 250 Megs
is slower (on my 400 Mhz PC with very fast harddisks) than the 
incoming data.   :-(

And of course I am myself starting to read newsgroups while headers
are still fetched (sorting, filename analysis, ...). 

As I said in another answer:
Newsreaders are a very demanding job for a PC when it comes
to binaries.  


>So, do you re-sort the entire batch (causing
>you to re-read the entire set of data from the disk), or can you store it
>some clever way to prevent you from having to do all that work every time
>you download new headers?

Right now I am reading the full header file (Xover cache) - and while
reading from disk I am doing some filtering (cancelled msgs, killed
authors,  specific filters).
This is pretty fast as long as the headers are still fitting into memory.
 
Of course I could store them presorted - or maintain index files.
But updating 4 index files with each 500.000 items from a 250 meg
data file at a rate of 300 headers/second seems to be impossible
with current disk subsystems (on user PCs).

So the header download would be throttled.
Or the update is done "later" - or in an asynchronous way after
the headers came in (this is what I'm doing alternatively). 

My problem is that already the filtering and necessary sorting and
inserting (msgids) I'm doing maxes out my PCs.

I'm simply afraid that adding workload at that time would make
the software less attractively....
(There are people paying for online-time - even with DSL  :-)

>Then, when you want to disply the headers, you read and sort the A file to
>get the first records.  Once you have done that, you can display all the
>"A" authors even though you haven't sorted the rest of the files.  Depnding
>on how the rest of the UI works, you may not even need to sort the rest
>yet.  You might be able to put off the sort until they scroll down in the
>list and try to look at other records.

Good approach.
Unfortunately 'sorting' a header-list is always combined with 
threading.....  (Of course I permit to sort by six ways - and still
permit threading on/off) - which is also very useful (the feature 
I've most in nearly all newsreaders ;-).


>So, this idea has issues, but the point of the example is trying to get you
>to realize that there are a lot of tricks you can used based on the needs
>of the application to do the work at different times so the user never has
>to wait for the application to sort the entire 1.5M records.

Yes - and you've initialized a new idea:
I could maintain my existing method - and store the sorted indexes
to disk. As soon as "new headers" arrived it would be only necessary
to sort the "new headers" into the existing list.
If a users reads his groups daily, then it might be only necessary
to sort 5.000 new headers.
If he reads just once a week - well: Then things take simply longer.


>So, maybe you didn't want to hear all this, and it's no simple answer for
>how to huge amounts of article data quickly, but it may give you some
>things to think about that will help you solve your problem....


Thanks for your feedback.
It is necessary to expand the disk-usage. But I'm getting closer.

The feedback from the other gentle guys is still necessary to
to do the incremental "sorting" - and I'm already afraid of "expiry".
But there's new light ahead.

CU
-- 
Juergen

Re: Newsreader programming - sorting one million lines ?
#64614
Author: DS
Date: Mon, 31 Mar 2003 15:16
43 lines
3403 bytes
> 
>>MS Access saves *all* data & indexes from all DB tables in 1 file, and
>>the file size limit on FAT32 partitions is about 2 GiB (2^31 bytes).
>>I think you'll reach that limit faster than you wished...
> 

The above was a reply to my post regarding the use of MS Access table's 
in my newsreader.

I already replied to this msg once, but now have data relating to this.

Each of the group's has it's own database file. Inside each .mdb is a 
table that hold's the group's header information, along with information 
interpereted from said header's.

In a 'clean' database (compacted), each header takes up about 500 bytes 
of filesize, 1/2 a K. So doing the math, this would allow storage of 
ROUGHLY 4,000,000 headers in a 2 GB file.

Believe me, I spent almost 2 months (of spare time) just refining the 
database structure's and managing them, and this is how I got the best 
performance. Having individual db's for each group also help's in case of 
any type of corruption. The 'entire' database will not need to be 
rebuilt, most likely only a single group.

I have also heard about concern's using Jet in a high traffic environment 
with problems of database corruption. I have not suffered any database 
corruption related to this whatsoever throughout development. The only 
time I did have a DB file (only ONE) become corrupt was when a coding 
error put my PC in an infinite loop, that, for some reason, the only way 
to get out of it was to press the reset button.

Also, you have to remember, my newsreader application is intended for 
multi-threaded downloading of multi-part binaries, from multiple servers. 
Anything that is expired from the servers is removed from the db, so the 
chance of seeing 4,000,000 headers in one group XOVER is highly doubtful 
(at this juncture anyway).


Regards,

DS
Re: Newsreader programming - sorting one million lines ?
#64616
Author: Marcus Mönnig
Date: Mon, 31 Mar 2003 16:12
14 lines
1924 bytes
DS wrote in <Xns934F6A37F2940idispcom@216.65.98.9>:

> I have also heard about concern's using Jet in a high traffic environment 
> with problems of database corruption. 

I would be interested to hear how long your application needs to e.g. do an 
XOver for 10.000 articles from a local server (e.g. Hamster), so that 
connection speed is not an issue.

Marcus
-- 
Some people are afraid of heights.  I'm afraid of widths.
		-- Stephen Wright
Re: Newsreader programming - sorting one million lines ?
#64618
Author: DS
Date: Mon, 31 Mar 2003 18:51
70 lines
4023 bytes
> DS wrote in <Xns934F6A37F2940idispcom@216.65.98.9>:
> 
>> I have also heard about concern's using Jet in a high traffic
>> environment with problems of database corruption. 
> 
> I would be interested to hear how long your application needs to e.g.
> do an XOver for 10.000 articles from a local server (e.g. Hamster), so
> that connection speed is not an issue.
> 
> Marcus

I would be interested in that too since I believe that 1 MBit/sec is 
about the limit of Jet. I know this because when d/l'g directly into 
files on the hard-disk, not into a database, I have typically seen 
speed's in excess of 2 MBits/sec, even 3 when the servers are working 
good.

But since you peaked my interest in actual numbers I'm running, I did 
some benchmarking.

First of all, Jeurgen replied to one of my posts saying it was 'great 
that you can process 2-3000 headers' a second. When I read that, I just 
continued on reading. I think the 2-3000 number came to be from my saying 
I process about 1mBit/sec when doing XOVER's. Couple/few hundred bytes 
per header comes out to that ballpark. But I was processing that speed in 
total bytes rx'd from the server's including IP overhead. That's how my 
IP meter works. So take off 20ish%.

So some number's:

    	Group: alt.binaries.multimedia
    	Server's: 4
    	Simultaneous threads: 4

    	Total Number of unique headers d/l'd: 108,450
    	Total Number Processed: 176,205

    	Total time: 10:00, 176,205/600 seconds = 293 headers/sec.
    	    	4 Threads- first 3min 50sec @108 kBYTES/sec.
    	    	Remaining 3 (running average)- @97 kBYTES/sec.

Joining & Expiring: 17 seconds (a little longer than I thought, but I 
don't usually work with this large a group, usually ~50k msg's group)

    	Text Only posts: 315
    	Detected as Multi-part: 108,135
    	
    	Displayed: 315 Text Only, 1424 COMPLETE binaries multi-part (across 
4 servers)


The way I am doing it is only working with the messages to be displayed. 
Even tho there is 108+K unique messages, I'm selecting 1739 of them to 
display. I first select them on a boolean field (display), then sort the 
subset of the entire group. Because of this displaying them and resorting 
them only takes a very small amount of time.

Does any of this sound reasonable, I mean, are these number's way off, 
good, bad ?


Regards,

DS





Re: Newsreader programming - sorting one million lines ?
#64619
Author: Juergen Helbing
Date: Mon, 31 Mar 2003 19:10
51 lines
3053 bytes
DS <t.h.i.s.n.t.h.a.t@a.d.e.l.p.h.i.a..n.e.t> wrote:

>Joining & Expiring: 17 seconds (a little longer than I thought, but I 
>don't usually work with this large a group, usually ~50k msg's group)

>The way I am doing it is only working with the messages to be displayed. 
>Even tho there is 108+K unique messages, I'm selecting 1739 of them to 
>display. I first select them on a boolean field (display), then sort the 
>subset of the entire group. Because of this displaying them and resorting 
>them only takes a very small amount of time.
>
>Does any of this sound reasonable, I mean, are these number's way off, 
>good, bad ?

From my own numbers (which are far worse) I would be jealous.

But I'm still having the hope that you're using the "trick" to join 
complete multiparts and dont keep all those headers. 
At an average of 25-50 segments per multiparts the problem is 
drastically reduced (perhaps even the best approach to solve 
my own problem - which occurs mostly on multiparts).

With 108k+ unique messages reduced to 2000-5000 kept headers 
and just the full msgids I can live and still sleep well.

With handling 108k+ new message headers fully in your database 
I'm close to use  del *.c  on my own sources.   ;-)


btw.: Speed of data handling is strongly a function of total size
and disk fragmentation. My own tool is performing lighting fast
for the first week and slows down significantly (50-70%) after
some months. But I'm not yet so far to write my own virtual
disk management to avoid FAT32 and/or NTFS.  ;-)


I ran an expiry on a.b.s.mp3 with 270.000 headers from some days
(they are having ~ 30.000 per day). This takes close to 1000 secs
and I am still happy because I'm reorganizing the 120 Meg XOVER
cache file in this time and I'm deleting 230.000 msgids from two
databases. 
This was done on a P3/400 with with a 7200rpm IBM deskstar 
80 Gig drive formatted with FAT32 on WinXP with 256 MB ram. 
(The minimum hardware requirements today ;-)


Good work.
-- 
Juergen

Re: Newsreader programming - sorting one million lines ?
#64620
Author: Marcus Mönnig
Date: Mon, 31 Mar 2003 19:48
35 lines
2939 bytes
DS wrote in <Xns934F8EB67D9C6idispcom@216.65.98.9>:

> First of all, Jeurgen replied to one of my posts saying it was 'great 
> that you can process 2-3000 headers' a second. When I read that, I just 
> continued on reading. I think the 2-3000 number came to be from my saying 
> I process about 1mBit/sec when doing XOVER's. Couple/few hundred bytes 
> per header comes out to that ballpark. But I was processing that speed in 
> total bytes rx'd from the server's including IP overhead. That's how my 
> IP meter works. So take off 20ish%.

That would be 1600-2400 hps then, while your test came up with

>     	Total time: 10:00, 176,205/600 seconds = 293 headers/sec.

293 hps. Did you run this over a remote connection or actually with a local 
server?

> Does any of this sound reasonable, I mean, are these number's way off, 
> good, bad ?

Well, there is no need to look left or right if you and your users don't 
need it faster than it is.

If the 293 hps was with a local connection, you are (about) fully using the 
bandwidth of a DSL connection with this, so users with better connections 
or local servers might get turned off.

Personally, I wouldn't do something about it if it's fine for you and your 
users. Btw, on the user side responsiveness is much more important than 
performance anyway IMHO.

Marcus
-- 
God is REAL, unless explicitly declared INTEGER.
Re: Newsreader programming - sorting one million lines ?
#64622
Author: DS
Date: Mon, 31 Mar 2003 21:22
77 lines
4578 bytes
Marcus M�nnig <usenet-mar03@40tude.com> wrote in
news:4lt0oyjp7vbg.dlg@40tude.com: 

> DS wrote in <Xns934F8EB67D9C6idispcom@216.65.98.9>:
> 
>> First of all, Jeurgen replied to one of my posts saying it was 'great
>> that you can process 2-3000 headers' a second. When I read that, I
>> just continued on reading. I think the 2-3000 number came to be from
>> my saying I process about 1mBit/sec when doing XOVER's. Couple/few
>> hundred bytes per header comes out to that ballpark. But I was
>> processing that speed in total bytes rx'd from the server's including
>> IP overhead. That's how my IP meter works. So take off 20ish%.
> 
> That would be 1600-2400 hps then, while your test came up with
> 
>>          Total time: 10:00, 176,205/600 seconds = 293 headers/sec.
> 
> 293 hps. Did you run this over a remote connection or actually with a
> local server?

These were all run to other networks over my cable ISP. One was one of my 
ISP's server, and the other 3 were to the pay-servers I have. 

> 
>> Does any of this sound reasonable, I mean, are these number's way
>> off, good, bad ?
> 
> Well, there is no need to look left or right if you and your users
> don't need it faster than it is.

I couldn't agree more. I don't know what kind of percentage of users 
would be NOT on a DSL or Cable connection, and NOT go thru the internet. 

It's a compromise for the masses, just like many other features. I have 
called other news-readers 'over-featured'. Feature's that MAYBE a couple 
% of user's might utilize. Which, at this point, aren't worth the time 
and effort to try to work in. 

ZaNews (no longer ZNC) is featured for broadband connections, with a 
hopefully easy to use interface, and simple configuration. And the test's 
I did were with just d/l'g and processing headers. This is THE most 
database activity imaginable. When actually d/l'ing multi-part binaries, 
with no simultaneous header download's, I am positive ZaNews will achieve 
MINIMUM 2 mBits/sec. At that point, very limited database activity is 
going on, just a LOT of writing to the hard-drive.

> 
> If the 293 hps was with a local connection, you are (about) fully
> using the bandwidth of a DSL connection with this, so users with
> better connections or local servers might get turned off.
> 

IMO, I can't look at it that way. I'm looking at actual throughput, how 
much I can pump through. 

I also don't have any user's right now, still developing, so I can't get 
any feedback. I was kind of hoping that some of the other developer's 
that frequent this group may have a comparison of numbers.

>users. Btw, on the user side responsiveness is much more important than 
>performance anyway IMHO.

Responsiveness is more a part of overall performance. And this is what 
I'm coding for anyway. As the project started out as a ZeoNews clone, I 
was perturbed about the sometime's 20-30 seconds wait's of ZeoNews just 
to re-sort a group, and whole program stops responding sometime's while 
it combine's and decode's part. And other little 'responsiveness' 
issue's. ZaNews' UI runs in it's own thread, and many of the task's are 
happening on backround thread's. I've taken all step's possible to this 
point to try to keep the UI responsive. No one like's to wait on 
anything.


Regards,

DS
Re: Newsreader programming - sorting one million lines ?
#64624
Author: DS
Date: Mon, 31 Mar 2003 21:49
77 lines
4799 bytes
archiver@i3w.com (Juergen Helbing) wrote in
news:0110l.v33205@archiver.winews.net: 

> From my own numbers (which are far worse) I would be jealous.
> 
> But I'm still having the hope that you're using the "trick" to join 
> complete multiparts and dont keep all those headers. 
> At an average of 25-50 segments per multiparts the problem is 
> drastically reduced (perhaps even the best approach to solve 
> my own problem - which occurs mostly on multiparts).
> 

That is a very good point. Unfortunately, in the database structuring, I 
had no choice to, at this time, save this data. I could go thru some 
'normalization' technique's, but this will dramatically increase the 
complexity of the db functions. I could null the subject's of part's, but 
I still have a record for each part. Since the record's are 'filtered' 
first, then display that subset. I'm not working with them all anyway. 

Also, since I am using multiple server's to assemble part's across 
server's, if a multi-part become's complete on one server, is marked 
complete, joined, and the un-displayed(?) part's record's are removed, 
when that post become's complete on another server a few hours later, it 
will totally screw up all the data.

> With 108k+ unique messages reduced to 2000-5000 kept headers 
> and just the full msgids I can live and still sleep well.
> 
> With handling 108k+ new message headers fully in your database 
> I'm close to use  del *.c  on my own sources.   ;-)
> 
> 
> btw.: Speed of data handling is strongly a function of total size
> and disk fragmentation. My own tool is performing lighting fast
> for the first week and slows down significantly (50-70%) after
> some months. But I'm not yet so far to write my own virtual
> disk management to avoid FAT32 and/or NTFS.  ;-)

This is something I have never thought of, well I have but not in 
relation to my project. The drive I store these db's on has not been 
defragged in probably 9 month's, at least. This is the drive I do ALL my 
work on from d/l'g to CD burning, to EVERYTHING else. I tried a few weeks 
ago again and it said I didn't have enought free sapce to defrag.(OK, 
quick analyze says 'Total Fragmentation' 25%, 'File Fragmentation' 50%.) 
That's not good. I'd probably be kidding myself to think I'd see an 
improvement in performance after a defrag.

> 
> 
> I ran an expiry on a.b.s.mp3 with 270.000 headers from some days
> (they are having ~ 30.000 per day). This takes close to 1000 secs

I expire automatically after header retreival, part of the joining 
process. No sense in having messages there that are expired already. So 
does a.b.s.mp3 typically have 270K headers in the XOVER ? A fresh db 
would contain 270K. At 30K/day, that would be 9 day's at 100% retention. 
Do yo typically see this?

> and I am still happy because I'm reorganizing the 120 Meg XOVER
> cache file in this time and I'm deleting 230.000 msgids from two
> databases. 
> This was done on a P3/400 with with a 7200rpm IBM deskstar 
> 80 Gig drive formatted with FAT32 on WinXP with 256 MB ram. 
> (The minimum hardware requirements today ;-)
> 
My PC is only a 1G Athlon, but 7200 Western Digital, and 512M RAM. I'm a 
little steep on RAM, kind of. I don't have any recent RAM usage 
statistics, but a month or 2 ago, I max'd out at using about 60 Meg, the 
most. I did do a setup package on a Win98 machine that has a K6-2/500 and 
it was a little slower. Maybe 10-20%, but it certainly was 1/2 the speed.

Thanks for sharing your info,


DS

Re: Newsreader programming - sorting one million lines ?
#64627
Author: Marcus Mönnig
Date: Mon, 31 Mar 2003 22:21
54 lines
3709 bytes
>> That would be 1600-2400 hps then, while your test came up with
>> 
>>>          Total time: 10:00, 176,205/600 seconds = 293 headers/sec.
>> 
>> 293 hps. Did you run this over a remote connection or actually with a
>> local server?
> 
> These were all run to other networks over my cable ISP. One was one of my 
> ISP's server, and the other 3 were to the pay-servers I have. 

Ok, then the limiting factor is your connection, not your processing.

> I couldn't agree more. I don't know what kind of percentage of users 
> would be NOT on a DSL or Cable connection, and NOT go thru the internet. 

Quite a few. Hamster is pretty popular and there is a user base that has 
connections faster than DSL.

> When actually d/l'ing multi-part binaries, 
> with no simultaneous header download's, I am positive ZaNews will achieve 
> MINIMUM 2 mBits/sec. 

Just to get this right. Are you feeding the XOver data into your database 
while doing the XOver? 
I doubt that you will see going 2MBits/sec into your db. 
 
>> If the 293 hps was with a local connection, you are (about) fully
>> using the bandwidth of a DSL connection with this, so users with
>> better connections or local servers might get turned off.
> 
> IMO, I can't look at it that way. I'm looking at actual throughput, how 
> much I can pump through. 

Users will compare your hps with other clients (of course plus any other 
processing time you need).

> I also don't have any user's right now, still developing, so I can't get 
> any feedback. 

If you are at this stage, I'd strongly encourage you to install a copy of 
Hamster, suck in a group with about 10000 articles and retrieve headers for 
these from the local Hamster into your client. 

> I was kind of hoping that some of the other developer's 
> that frequent this group may have a comparison of numbers.

600 to 800 hps should be a good value. Up to 1000 should be possible.

Marcus
-- 
I dipped into the future far as human eye could see,
Saw the vision of the world and all the wonder that would be.
		--Alfred Lord Tennyson
Re: Newsreader programming - sorting one million lines ?
#64626
Author: DS
Date: Mon, 31 Mar 2003 23:01
60 lines
3356 bytes
> 
> Ok, then the limiting factor is your connection, not your processing.
> 
Well yes and no. The limiting connection here is ultimately the db 
engine. I can only process roughly 1 mBit/second. With my account, i can 
get that with 4 server's simultaneously.


>> I couldn't agree more. I don't know what kind of percentage of users 
>> would be NOT on a DSL or Cable connection, and NOT go thru the
>> internet. 
> 
> Quite a few. Hamster is pretty popular and there is a user base that
> has connections faster than DSL.

I'll have to research this a little more.

> Just to get this right. Are you feeding the XOver data into your
> database while doing the XOver? 
> I doubt that you will see going 2MBits/sec into your db.

I will never see 2m bit/sec into the database. Yes I am feeding data into 
the database during the XOVER's. At a max around 1 mBit/sec download 
throughput, not 1 mBit/sec of data. During the XOVER here is what is 
happening:

1. RX XOVER data packet
2. add packet to remaining data from previous packet if necessary.
3. parse the packet into header 'dataset's'
4. loop thru it sending each 'dataset' to the parser.
    	for each header 'dataset'-
    	5. parse each 'dataset' into relevent fields
    	6. do some detection to see if it's part of a multi-part
    	7. stuff some interpereted data into a couple fields for use in     
	    	joining
    	8. pass each 'dataset' to the dbstuffer
    	9. check to see if the msgID is existing.
    	10. either add the entire record, if it wasn't added previously,
    	    	or,
    	    	update one field for the duplicate msg on a different server.
    	(loop to step 4 until all full dataset's are processed)
11. store leftover data from the packet to add to the next new packet

step 1 all over again.


> 600 to 800 hps should be a good value. Up to 1000 should be possible.

Sad to say not to me. But I should be able to provide some comparison 
numbers in a week or 2. I'm building a P4 2 GHz PC for someone that I was 
planning to test on.


Regards,

DS



Re: Newsreader programming - sorting one million lines ?
#64633
Author: Juergen Helbing
Date: Tue, 01 Apr 2003 05:08
50 lines
2889 bytes
DS <t.h.i.s.n.t.h.a.t@a.d.e.l.p.h.i.a..n.e.t> wrote:

>I tried a few weeks 
>ago again and it said I didn't have enought free sapce to defrag.(OK, 
>quick analyze says 'Total Fragmentation' 25%, 'File Fragmentation' 50%.) 
>That's not good. I'd probably be kidding myself to think I'd see an 
>improvement in performance after a defrag.

It is possible that your database engine is allocating larger
portions of disk-space at once to avoid fragmentation effects.

However 25/50% is a really cluttered disk - and a newsreader
performing well under such circumstances is good.

>I expire automatically after header retreival, part of the joining 
>process. No sense in having messages there that are expired already. 

My own project includes a network of "personal news-servers" which
can be also accessed. For some newsgroups I'm having access
to >50 hosts - some of them never expire....
So expiry is totally in the hand of the user in my (wierd) case.


>So 
>does a.b.s.mp3 typically have 270K headers in the XOVER ? A fresh db 
>would contain 270K. At 30K/day, that would be 9 day's at 100% retention. 
>Do yo typically see this?

Yes, these are 'typical' numbers for abs.mp3. Some video groups
(and a.b.boneless ;-.) might even have more traffic.

In fact that one group is the reason why I'm trying to solve the
"one million header" problem: I'm usually keeping msgs and hdrs
for 30 days on my own servers. This comes already today close
to one million headers/msgs for a single group.
Already today I am not able to display that groups xover list for
one week (I'm currently restriciting the list to 150.000 entries) 
so rather than raising limits I wanted to 'rework' the header handling.


>Thanks for sharing your info,

My pleasure - our advantage.

CU
-- 
Juergen


Re: Newsreader programming - sorting one million lines ?
#64636
Author: Dr.Ruud
Date: Tue, 01 Apr 2003 06:36
15 lines
1500 bytes
Juergen Helbing skribis:

> As I said in another answer:
> Newsreaders are a very demanding job for a PC when it comes
> to binaries.

Having a good combination of network card and driver can make
a big difference. Some network cards (or their driver) can
really pull down your PC a lot.

-- 
Affijn, Ruud


Re: Newsreader programming - sorting one million lines ?
#64640
Author: JanC
Date: Tue, 01 Apr 2003 12:54
24 lines
2064 bytes
archiver@i3w.com (Juergen Helbing) schreef:

>>There are several open source DB engines with C/C++ APIs for Windows...
> 
> Nice to know.
> Do you have any example (before I choose the wrong one ?)

I haven't really used these so I don't know about performance, reliability 
or if they are the "right one", but some well known embedded DB engines 
(embedded = not using a DB _server_) are:
- SQLite  <http://www.sqlite.org/>
[The following are only free when used in open source software AFAIK]
- BerkeleyDB <http://www.sleepycat.com/>
- libmysql <http://www.mysql.com/>
- Firebird (embedded) <http://firebird.sourceforge.net/>

There must be more available though...

-- 
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads