IP Upstream Hash

chateau Xiao chateau.xiao at gmail.com
Thu Jul 21 03:11:59 UTC 2011


fist of all, 89, 113 and 6271  are all primes.
prime has a very import feature when we use to judge whether the bucket is
right place for the data to store.It simple made a hash more efficient and
less conflict.

the princple of "why prime" can be dicussed more detial in the URL below

http://computinglife.wordpress.com/2008/11/20/why-do-hash-functions-use-prime-numbers/




On Thu, Jul 21, 2011 at 5:18 AM, Matthieu Tourne
<matthieu.tourne at gmail.com>wrote:

> Hi all,
>
> I was looking at the code in ngx_http_upstream_ip_hash_module.c
> And I'm not sure where the hashing algorithm for IPs is coming from,
> especially those lines :
>
>             iphp->hash = 89;
>
>             hash = (hash * 113 + iphp->addr[i]) % 6271;
>
> Just wondering if those constants are arbitrary chosen, or if there is
> something there to guarantee a good distribution ?
>
> If you have some links explaining this algorithm, it would be greatly
> appreciated!
> Also, how would you get a good distribution on IPv6. Maybe it would make
> sense to use murmur ?
>
> Thank you,
>
> Matthieu.
>
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20110721/7d36a1dc/attachment.html>


More information about the nginx-devel mailing list