# I'm not sure how "hash $cachekey" works

**URL:** <https://www.ruby-forum.com/t/im-not-sure-how-hash-cachekey-works/243879>\
**Category:** NGINX\
**Created:** [January 21, 2016, 1:41pm UTC](https://www.ruby-forum.com/t/im-not-sure-how-hash-cachekey-works/243879 "2016-01-21T13:41:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [January 21, 2016, 1:41pm UTC](https://www.ruby-forum.com/t/im-not-sure-how-hash-cachekey-works/243879/1 "2016-01-21T13:41:54Z")

</div>

I have a question about “hash $cachekey” consistent;  
Would the following Config 1, Config 2, Config 3 be exactly the same of  
different?  
i.e. if I swap the configurations would the cache keys stay consistent?  
The reason I am asking is I have a large configuration similar to Config  
2  
and am not sure it would be “safe” to clean up the order and merge  
duplicates as weighted config values.

Thank you.

Would the following be different of the same?  
Config 1:  
upstream ImageCluster {  
server 10.1.1.1;  
server 10.1.1.1;  
server 10.1.1.2;  
server 10.1.1.2;  
server 10.1.1.3;  
server 10.1.1.3;

hash $cachekey consistent;  
}

Config 2:  
upstream ImageCluster {  
server 10.1.1.2;  
server 10.1.1.2;  
server 10.1.1.1;  
server 10.1.1.1;  
server 10.1.1.3;  
server 10.1.1.3;

hash $cachekey consistent;  
}

Config 3:  
upstream ImageCluster {  
server 10.1.1.1 weight=2;  
server 10.1.1.2 weight=2;  
server 10.1.1.3 weight=2;

hash $cachekey consistent;  
}

---

<div class="post-metadata">

**Author:** ![highclass99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f05b48/32.png) [@highclass99](https://www.ruby-forum.com/u/highclass99)\
**Post date:** [January 21, 2016, 5:06pm UTC](https://www.ruby-forum.com/t/im-not-sure-how-hash-cachekey-works/243879/2 "2016-01-21T17:06:23Z")

</div>

Hi,

> Config 1:
> 
> }  
> These two are the same. With consistent hash balancer the order of  
> servers  
> does not matter.

> Config 3:  
> upstream ImageCluster {  
> server 10.1.1.1 weight=2;  
> server 10.1.1.2 weight=2;  
> server 10.1.1.3 weight=2;
> 
> hash $cachekey consistent;  
> }

This one is different.

With Config1 and Config2 you have 160 hash points per each server  
(duplicates are removed).  
With Config3 you have 320 points per each server.

Statistically all configurations are similar.

–  
Roman A.

---

<div class="post-metadata">

**Author:** ![highclass99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f05b48/32.png) [@highclass99](https://www.ruby-forum.com/u/highclass99)\
**Post date:** [January 22, 2016, 1:49am UTC](https://www.ruby-forum.com/t/im-not-sure-how-hash-cachekey-works/243879/3 "2016-01-22T01:49:14Z")

</div>

Thank you for your reply.

You replied:

> With Config1 and Config2 you have 160 hash points per each server  
> (duplicates are removed)

Does that mean  
I could just shorten the whole config to  
upstream ImageCluster {  
server 10.1.1.1;  
server 10.1.1.2;  
server 10.1.1.3;  
hash $cachekey consistent;  
}  
and it would be exactly the same and keep the hashes exactly the same as  
before?

If I wanted to “weight” the servers to all initially weight=4 and then  
slowly optimize the weightings.  
Would it be a good idea to slowly add the weightings as  
weight=2 -restart and wait-\> weight=3 -restart and wait-\> weight=4  
(the servers have really high load, and sudden changes in hash can cause  
problems)  
or would it be okay to just change at once like  
upstream ImageCluster {  
server 10.1.1.1 weight=4;  
server 10.1.1.2 weight=4;  
server 10.1.1.3 weight=4;

hash $cachekey consistent;  
}

Again, thanks for your reply.
