🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #90619

Re: INN performance curve - why so much time dealing with the history file?

#90619
From: go-while
Date: Wed, 26 Jul 2023 10:33
103 lines
6861 bytes
On 26.07.23 05:41, Russ Allbery wrote:
> (If I remember correctly, the dbz algorithm uses linear probing for hash
> collisions, so you really want a sparse hash.  If the linear probe goes
> for too long, it goes to a separate overflow table, and once that happens,
> the performance really tanks *and* the history file size bloats.  It's
> just a bad time all around, sort of like a system going to swap.  I'm
> betting your history file went to multiple overflow tables because it
> started massively undersized.)

https://manpages.debian.org/testing/inn2-dev/dbz.3.en.html

DESCRIPTION
These functions provide an indexing system for rapid random access to a 
text file (the base file).

Dbz stores offsets into the base text file for rapid retrieval. All 
retrievals are keyed on a hash value that is generated by the 
HashMessageID() function.

Dbzinit opens a database, an index into the base file base, consisting 
of files base.dir , base.index , and base.hash which must already exist. 
(If the database is new, they should be zero-length files.) Subsequent 
accesses go to that database until dbzclose is called to close the database.

Dbzfetch searches the database for the specified key, returning the 
corresponding value if any, if <--enable-tagged-hash at configure> is 
specified. If <--enable-tagged-hash at configure> is not specified, it 
returns true and content of ivalue is set. Dbzstore stores the key - 
value pair in the database, if <--enable-tagged-hash at configure> is 
specified. If <--enable-tagged-hash at configure> is not specified, it 
stores the content of ivalue. Dbzstore will fail unless the database 
files are writable. Dbzexists will verify whether or not the given hash 
exists or not. Dbz is optimized for this operation and it may be 
significantly faster than dbzfetch().

Dbzfresh is a variant of dbzinit for creating a new database with more 
control over details.

Dbzfresh's size parameter specifies the size of the first hash table 
within the database, in key-value pairs. Performance will be best if the 
number of key-value pairs stored in the database does not exceed about 
2/3 of size. (The dbzsize function, given the expected number of 
key-value pairs, will suggest a database size that meets these 
criteria.) Assuming that an fseek offset is 4 bytes, the .index file 
will be 4 * size bytes. The .hash file will be DBZ_INTERNAL_HASH_SIZE * 
size bytes (the .dir file is tiny and roughly constant in size) until 
the number of key-value pairs exceeds about 80% of size. (Nothing awful 
will happen if the database grows beyond 100% of size, but accesses will 
slow down quite a bit and the .index and .hash files will grow somewhat.)

Dbz stores up to DBZ_INTERNAL_HASH_SIZE bytes of the message-id's hash 
in the .hash file to confirm a hit. This eliminates the need to read the 
base file to handle collisions. This replaces the tagmask feature in 
previous dbz releases.

A size of ``0'' given to dbzfresh is synonymous with the local default; 
the normal default is suitable for tables of 5,000,000 key-value pairs. 
Calling dbzinit(name) with the empty name is equivalent to calling 
dbzfresh(name, 0).

When databases are regenerated periodically, as in news, it is simplest 
to pick the parameters for a new database based on the old one. This 
also permits some memory of past sizes of the old database, so that a 
new database size can be chosen to cover expected fluctuations. Dbzagain 
is a variant of dbzinit for creating a new database as a new generation 
of an old database. The database files for oldbase must exist. Dbzagain 
is equivalent to calling dbzfresh with a size equal to the result of 
applying dbzsize to the largest number of entries in the oldbase 
database and its previous 10 generations.

When many accesses are being done by the same program, dbz is massively 
faster if its first hash table is in memory. If the ``pag_incore'' flag 
is set to INCORE_MEM, an attempt is made to read the table in when the 
database is opened, and dbzclose writes it out to disk again (if it was 
read successfully and has been modified). Dbzsetoptions can be used to 
set the pag_incore and exists_incore flag to new value which should be 
``INCORE_NO'', ``INCORE_MEM'', or ``INCORE_MMAP'' for the .hash and 
.index files separately; this does not affect the status of a database 
that has already been opened. The default is ``INCORE_NO'' for the 
.index file and ``INCORE_MMAP'' for the .hash file. The attempt to read 
the table in may fail due to memory shortage; in this case dbz fails 
with an error. Stores to an in-memory database are not (in general) 
written out to the file until dbzclose or dbzsync, so if robustness in 
the presence of crashes or concurrent accesses is crucial, in-memory 
databases should probably be avoided or the writethrough option should 
be set to ``true'';

If the nonblock option is ``true'', then writes to the .hash and .index 
files will be done using non-blocking I/O. This can be significantly 
faster if your platform supports non-blocking I/O with files.

Dbzsync causes all buffers etc. to be flushed out to the files. It is 
typically used as a precaution against crashes or concurrent accesses 
when a dbz-using process will be running for a long time. It is a 
somewhat expensive operation, especially for an in-memory database.

Concurrent reading of databases is fairly safe, but there is no 
(inter)locking, so concurrent updating is not.

An open database occupies three stdio streams and two file descriptors; 
Memory consumption is negligible (except for stdio buffers) except for 
in-memory databases.
Technical Details
Message-ID: <I16wM.75152$wsc3.46118@fx13.ams4>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!apf1.newsdeef.eu!not-for-mail
References: <u9q0c8$28ja$1@nnrp.usenet.blueworldhosting.com> <87351bz91n.fsf@hope.eyrie.org> <u9q2rs$1d3h$1@nnrp.usenet.blueworldhosting.com> <87y1j3xsl4.fsf@hope.eyrie.org> <u9q49m$k3t$1@nnrp.usenet.blueworldhosting.com> <87tttrxrtv.fsf@hope.eyrie.org>

Show Full Headers
Complete Article Headers
Message-ID: <I16wM.75152$wsc3.46118@fx13.ams4>
Subject: Re: INN performance curve - why so much time dealing with the history file?
Date: Wed, 26 Jul 2023 12:33:49 +0200
From: go-while <no-reply@no.spam>
References: <u9q0c8$28ja$1@nnrp.usenet.blueworldhosting.com> <87351bz91n.fsf@hope.eyrie.org> <u9q2rs$1d3h$1@nnrp.usenet.blueworldhosting.com> <87y1j3xsl4.fsf@hope.eyrie.org> <u9q49m$k3t$1@nnrp.usenet.blueworldhosting.com> <87tttrxrtv.fsf@hope.eyrie.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!apf1.newsdeef.eu!not-for-mail
Mime-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0
Content-Language: en-US
Newsgroups: news.software.nntp
In-Reply-To: <87tttrxrtv.fsf@hope.eyrie.org>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 104
X-Complaints-To: abuse@blocknews.net
Nntp-Posting-Date: Wed, 26 Jul 2023 09:52:40 UTC
Organization: blocknews - www.blocknews.net