Welcome! Log In Create A New Profile

Advanced

Re: Use primes for hashtable size

Maxim Dounin
June 01, 2017 01:40PM
Hello!

On Thu, Jun 01, 2017 at 04:54:50PM +0500, Andrew Borodin wrote:

> Hi, Maxim!
>
> 2017-05-30 18:01 GMT+05:00 Maxim Dounin <mdounin@mdounin.ru>:
> >
> > The maximum size of hash table as specified by the hinit->max_size
> > field is indeed maximum size, and not the size of the hash table.
> > Following code in the ngx_hash_init() will try hard to find to
> > find out an optimal hash size for a given set of values within the
> > maximum size specified, and will test all the prime numbers as
> > well.
> >
> > I see no reasons to additionally limit the maximum size to a prime
> > number. If you think there are some, please be more specific.
> >
> > You are right. I've modified patch to checkout primes first, then proceed
> to "hard work" . Also I've kolhozed some perf prove of improvement.
> This test creates a hash table of 5000 semirandom strings (not very random,
> just bytes permutated).
> On my Ubuntu VM without patch hash creation is 92-96ms, with patch it's
> strictly 0. "hard work" search tries about 2k sizes before success, primes
> search hits at second.
>
> Docs say some words about startup speed and I wanted to apply primes
> somewhere, so here we go.

Thanks, though suggested change will certainly modify current
nginx (documented) approach of searching for minimum possible
hash sizes.

It might be a better solution for large hashes though, as
currently optimized by using a larger start size:

if (hinit->max_size > 10000 && nelts && hinit->max_size / nelts < 100) {
start = hinit->max_size - 1000;
}

Not sure it is at all needed though, as I don't remember any
"words about startup speed" in the documentation and startup
speed of hashes wasn't a practical problem as far as I remember.

--
Maxim Dounin
http://nginx.org/
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Use primes for hashtable size Attachments

Andrew Borodin 740 May 30, 2017 06:30AM

Re: Use primes for hashtable size

Maxim Dounin 492 May 30, 2017 09:04AM

Re: Use primes for hashtable size

Andrew Borodin 485 June 01, 2017 07:56AM

Re: Use primes for hashtable size

Maxim Dounin 451 June 01, 2017 01:40PM

Re: Use primes for hashtable size

Andrew Borodin 430 June 01, 2017 01:58PM

Re: Use primes for hashtable size

splitice 551 June 01, 2017 08:58PM

Re: Use primes for hashtable size

Maxim Dounin 393 June 02, 2017 07:48AM

Re: Use primes for hashtable size

splitice 561 June 02, 2017 07:52AM

Re: Use primes for hashtable size

Andrew Borodin 463 June 03, 2017 02:02AM

Re: Use primes for hashtable size

Andrew Borodin 471 June 04, 2017 02:24PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 241
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready