Welcome! Log In Create A New Profile


consistent hashing using split_clients

October 31, 2012 10:31AM
I'm looking for a way to do consistent hashing without any 3rd-party modules or perl/lua. I came up with the idea of generating a split_clients and list of upstreams via script, so we can add/remove backends without blowing out the cache on each upstream when a backend server is added, removed or otherwise offline.

What I have looks like the config below. The example only includes 16 upstreams for clarity, and is generated by sorting by the SHA1 hash of server names for each upstream bucket along with the bucket name.

Unfortunately, to get an even distribution of requests to upstream buckets with consistent hashing, I am actually going to need at least 4096 upstreams, and the corresponding number of entries in split_clients.

Will 4096 entries in single split_clients block pose a performance issue? Will split_clients have a distribution problem with a small percentage like "0.0244140625%"? How many "buckets" does the hash table for split_clients have (it doesn't seem to be configurable)?

Thanks for any insights. I haven't actually built a test environment for this yet as the setup is quite a bit of work, so I want to find out if I am doing something stupid before committing a lot of time and resources.

upstream hash0 {server; server backup;}
upstream hash1 {server; server backup;}
upstream hash2 {server; server backup;}
upstream hash3 {server; server backup;}
upstream hash4 {server; server backup;}
upstream hash5 {server; server backup;}
upstream hash6 {server; server backup;}
upstream hash7 {server; server backup;}
upstream hash8 {server; server backup;}
upstream hash9 {server; server backup;}
upstream hashA {server; server backup;}
upstream hashB {server; server backup;}
upstream hashC {server; server backup;}
upstream hashD {server; server backup;}
upstream hashE {server; server backup;}
upstream hashF {server; server backup;}

split_clients "${scheme}://${host}${request_uri}" $uhash {
6.25% hash0;
6.25% hash1;
6.25% hash2;
6.25% hash3;
6.25% hash4;
6.25% hash5;
6.25% hash6;
6.25% hash7;
6.25% hash8;
6.25% hash9;
6.25% hashA;
6.25% hashB;
6.25% hashC;
6.25% hashD;
6.25% hashE;
* hashF;}

location /foo {
proxy_pass http://$uhash;}

consistent hashing using split_clients

rmalayterOctober 31, 2012 10:31AM

Re: consistent hashing using split_clients

Maxim DouninOctober 31, 2012 10:52AM

Re: consistent hashing using split_clients

rmalayterOctober 31, 2012 12:46PM

Re: consistent hashing using split_clients

姚伟斌November 01, 2012 01:46AM

Re: consistent hashing using split_clients

Maxim DouninNovember 01, 2012 06:00AM

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 118
Record Number of Users: 5 on August 04, 2015
Record Number of Guests: 244 on October 02, 2015
Powered by nginx    Powered by FreeBSD    PHP Powered    Powered by Percona     ipv6 ready