From: Alexander Frolkin <hidden> Date: 2013-09-23 12:22:54
Improve the SH fallback realserver selection strategy.
With sh and sh-fallback, if a realserver is down, this attempts to
distribute the traffic that would have gone to that server evenly
among the remaining servers.
Signed-off-by: Alexander Frolkin <redacted>
---
From: Sergei Shtylyov <hidden> Date: 2013-09-23 19:42:54
Hello.
On 09/23/2013 03:51 PM, Alexander Frolkin wrote:
Improve the SH fallback realserver selection strategy.
With sh and sh-fallback, if a realserver is down, this attempts to
distribute the traffic that would have gone to that server evenly
among the remaining servers.
From: Alexander Frolkin <hidden> Date: 2013-09-24 09:32:55
Improve the SH fallback realserver selection strategy.
With sh and sh-fallback, if a realserver is down, this attempts to
distribute the traffic that would have gone to that server evenly
among the remaining servers.
Signed-off-by: Alexander Frolkin <redacted>
--
From: Simon Horman <horms@verge.net.au> Date: 2013-09-25 00:30:43
On Tue, Sep 24, 2013 at 10:32:38AM +0100, Alexander Frolkin wrote:
Improve the SH fallback realserver selection strategy.
With sh and sh-fallback, if a realserver is down, this attempts to
distribute the traffic that would have gone to that server evenly
among the remaining servers.
Signed-off-by: Alexander Frolkin <redacted>
Hi Alexander,
could you add some comments to the code or at least a description of the
algorithm to the above the function. The intent of original code may not
have been obvious to the eye but this version certainly isn't obvious to
mine.
To unsubscribe from this list: send the line "unsubscribe lvs-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Alexander Frolkin <hidden> Date: 2013-09-25 09:02:11
Hi,
could you add some comments to the code or at least a description of the
algorithm to the above the function. The intent of original code may not
have been obvious to the eye but this version certainly isn't obvious to
mine.
Sure. I have a bad habit of assuming that if I understand something,
then others automatically do too. :-)
The original code went through the table, starting at the same place as
the code without fallback and if that returned an unavailable
realserver, it offset the hash by one and repeated the lookup, then added
two, etc., up to IP_VS_SH_TAB_SIZE-1. So the hash offset was 0,
1, ..., IP_VS_SH_TAB_SIZE-1.
The result is that if a server is down, all traffic destined for it
would fall back onto the next server in the list.
The new code also starts at the same place as the old code (offset 0),
but if that fails, it uses the same fallback strategy as the old code,
but the hash offset is now ihash, ihash + 1, ..., IP_VS_SH_TAB_SIZE-1,
0, 1, ..., ihash - 1, i.e., it starts at ihash instead of 0 and loops
around the table. ihash could have been a random number, but choosing
it to be something based on the source IP and port (in which case it may
as well be the same hash [offset 0]) means that the behaviour will be
the same on different directors.
This spreads the load of an unavailable server across the remaining
servers instead of just moving it to the next one in the list.
Hope that makes sense...
I'll submit a patch with a comment shortly.
Alex
From: Alexander Frolkin <hidden> Date: 2013-09-25 09:26:46
Improve the SH fallback realserver selection strategy.
With sh and sh-fallback, if a realserver is down, this attempts to
distribute the traffic that would have gone to that server evenly
among the remaining servers.
Signed-off-by: Alexander Frolkin <redacted>
--
@@ -115,27 +115,47 @@ ip_vs_sh_get(struct ip_vs_service *svc, struct ip_vs_sh_state *s,}-/* As ip_vs_sh_get, but with fallback if selected server is unavailable */+/* As ip_vs_sh_get, but with fallback if selected server is unavailable+*+*Thefallbackstrategyloopsaroundthetablestartingfroma"random"+*point(infact,itischosentobetheoriginalhashvaluetomakethe+*algorithmdeterministic)tofindanewserver.+*/staticinlinestructip_vs_dest*ip_vs_sh_get_fallback(structip_vs_service*svc,structip_vs_sh_state*s,constunionnf_inet_addr*addr,__be16port){-unsignedintoffset;-unsignedinthash;+unsignedintoffset,roffset;+unsignedinthash,ihash;structip_vs_dest*dest;-for(offset=0;offset<IP_VS_SH_TAB_SIZE;offset++){-hash=ip_vs_sh_hashkey(svc->af,addr,port,offset);-dest=rcu_dereference(s->buckets[hash].dest);-if(!dest)-break;-if(is_unavailable(dest))-IP_VS_DBG_BUF(6,"SH: selected unavailable server "-"%s:%d (offset %d)",+/* first try the dest it's supposed to go to */+ihash=ip_vs_sh_hashkey(svc->af,addr,port,0);+dest=rcu_dereference(s->buckets[ihash].dest);+if(!dest)+returnNULL;+if(is_unavailable(dest)){+IP_VS_DBG_BUF(6,"SH: selected unavailable server "+"%s:%d, reselecting",+IP_VS_DBG_ADDR(svc->af,&dest->addr),+ntohs(dest->port));+/* if the original dest is unavailable, loop around the table+*startingfromihashtofindanewdest+*/+for(offset=0;offset<IP_VS_SH_TAB_SIZE;offset++){+roffset=(offset+ihash)%IP_VS_SH_TAB_SIZE;+hash=ip_vs_sh_hashkey(svc->af,addr,port,roffset);+dest=rcu_dereference(s->buckets[hash].dest);+if(is_unavailable(dest))+IP_VS_DBG_BUF(6,"SH: selected unavailable "+"server %s:%d (offset %d), reselecting",IP_VS_DBG_ADDR(svc->af,&dest->addr),-ntohs(dest->port),offset);-else-returndest;+ntohs(dest->port),roffset);+else+returndest;+}+}else{+returndest;}returnNULL;
Hello,
On Wed, 25 Sep 2013, Alexander Frolkin wrote:
quoted hunk
Improve the SH fallback realserver selection strategy.
With sh and sh-fallback, if a realserver is down, this attempts to
distribute the traffic that would have gone to that server evenly
among the remaining servers.
Signed-off-by: Alexander Frolkin <redacted>
--
@@ -115,27 +115,47 @@ ip_vs_sh_get(struct ip_vs_service *svc, struct ip_vs_sh_state *s,}-/* As ip_vs_sh_get, but with fallback if selected server is unavailable */+/* As ip_vs_sh_get, but with fallback if selected server is unavailable+*+*Thefallbackstrategyloopsaroundthetablestartingfroma"random"+*point(infact,itischosentobetheoriginalhashvaluetomakethe+*algorithmdeterministic)tofindanewserver.+*/staticinlinestructip_vs_dest*ip_vs_sh_get_fallback(structip_vs_service*svc,structip_vs_sh_state*s,constunionnf_inet_addr*addr,__be16port){-unsignedintoffset;-unsignedinthash;+unsignedintoffset,roffset;+unsignedinthash,ihash;structip_vs_dest*dest;-for(offset=0;offset<IP_VS_SH_TAB_SIZE;offset++){-hash=ip_vs_sh_hashkey(svc->af,addr,port,offset);-dest=rcu_dereference(s->buckets[hash].dest);-if(!dest)-break;-if(is_unavailable(dest))-IP_VS_DBG_BUF(6,"SH: selected unavailable server "-"%s:%d (offset %d)",+/* first try the dest it's supposed to go to */+ihash=ip_vs_sh_hashkey(svc->af,addr,port,0);+dest=rcu_dereference(s->buckets[ihash].dest);+if(!dest)+returnNULL;
Can we reduce the indentation here, eg:
if (!is_unavailable(dest))
return dest;
IP_VS_DBG_BUF(6, "SH: selected unavailable server "
...
for ()...
...
return NULL;
+ if (is_unavailable(dest)) {
+ IP_VS_DBG_BUF(6, "SH: selected unavailable server "
+ "%s:%d, reselecting",
+ IP_VS_DBG_ADDR(svc->af, &dest->addr),
+ ntohs(dest->port));
+ /* if the original dest is unavailable, loop around the table
+ * starting from ihash to find a new dest
+ */
+ for (offset = 0; offset < IP_VS_SH_TAB_SIZE; offset++) {
+ roffset = (offset + ihash) % IP_VS_SH_TAB_SIZE;
+ hash = ip_vs_sh_hashkey(svc->af, addr, port, roffset);
+ dest = rcu_dereference(s->buckets[hash].dest);
Every result of rcu_dereference should be checked
for NULL (no dests anymore):
if (!dest)
break;
Then make sure there is correct indentation
for IP_VS_DBG_BUF parameters.
From: Alexander Frolkin <hidden> Date: 2013-09-26 10:05:52
Improve the SH fallback realserver selection strategy.
With sh and sh-fallback, if a realserver is down, this attempts to
distribute the traffic that would have gone to that server evenly
among the remaining servers.
Signed-off-by: Alexander Frolkin <redacted>
--
@@ -115,27 +115,49 @@ ip_vs_sh_get(struct ip_vs_service *svc, struct ip_vs_sh_state *s,}-/* As ip_vs_sh_get, but with fallback if selected server is unavailable */+/* As ip_vs_sh_get, but with fallback if selected server is unavailable+*+*Thefallbackstrategyloopsaroundthetablestartingfroma"random"+*point(infact,itischosentobetheoriginalhashvaluetomakethe+*algorithmdeterministic)tofindanewserver.+*/staticinlinestructip_vs_dest*ip_vs_sh_get_fallback(structip_vs_service*svc,structip_vs_sh_state*s,constunionnf_inet_addr*addr,__be16port){-unsignedintoffset;-unsignedinthash;+unsignedintoffset,roffset;+unsignedinthash,ihash;structip_vs_dest*dest;+/* first try the dest it's supposed to go to */+ihash=ip_vs_sh_hashkey(svc->af,addr,port,0);+dest=rcu_dereference(s->buckets[ihash].dest);+if(!dest)+returnNULL;+if(!is_unavailable(dest))+returndest;++IP_VS_DBG_BUF(6,"SH: selected unavailable server "+"%s:%d, reselecting",+IP_VS_DBG_ADDR(svc->af,&dest->addr),+ntohs(dest->port));++/* if the original dest is unavailable, loop around the table+*startingfromihashtofindanewdest+*/for(offset=0;offset<IP_VS_SH_TAB_SIZE;offset++){-hash=ip_vs_sh_hashkey(svc->af,addr,port,offset);+roffset=(offset+ihash)%IP_VS_SH_TAB_SIZE;+hash=ip_vs_sh_hashkey(svc->af,addr,port,roffset);dest=rcu_dereference(s->buckets[hash].dest);if(!dest)break;-if(is_unavailable(dest))-IP_VS_DBG_BUF(6,"SH: selected unavailable server "-"%s:%d (offset %d)",-IP_VS_DBG_ADDR(svc->af,&dest->addr),-ntohs(dest->port),offset);-else+if(!is_unavailable(dest))returndest;+IP_VS_DBG_BUF(6,"SH: selected unavailable "+"server %s:%d (offset %d), reselecting",+IP_VS_DBG_ADDR(svc->af,&dest->addr),+ntohs(dest->port),+roffset);}returnNULL;
Hello,
On Thu, 26 Sep 2013, Alexander Frolkin wrote:
Improve the SH fallback realserver selection strategy.
With sh and sh-fallback, if a realserver is down, this attempts to
distribute the traffic that would have gone to that server evenly
among the remaining servers.
Signed-off-by: Alexander Frolkin <redacted>
Looks correct to me, just fix the below indentations.
Also, please use version number for your patches, eg.
[PATCHv2] ipvs: ...
From: Alexander Frolkin <hidden> Date: 2013-09-27 10:06:45
Improve the SH fallback realserver selection strategy.
With sh and sh-fallback, if a realserver is down, this attempts to
distribute the traffic that would have gone to that server evenly
among the remaining servers.
Signed-off-by: Alexander Frolkin <redacted>
--
@@ -115,27 +115,46 @@ ip_vs_sh_get(struct ip_vs_service *svc, struct ip_vs_sh_state *s,}-/* As ip_vs_sh_get, but with fallback if selected server is unavailable */+/* As ip_vs_sh_get, but with fallback if selected server is unavailable+*+*Thefallbackstrategyloopsaroundthetablestartingfroma"random"+*point(infact,itischosentobetheoriginalhashvaluetomakethe+*algorithmdeterministic)tofindanewserver.+*/staticinlinestructip_vs_dest*ip_vs_sh_get_fallback(structip_vs_service*svc,structip_vs_sh_state*s,constunionnf_inet_addr*addr,__be16port){-unsignedintoffset;-unsignedinthash;+unsignedintoffset,roffset;+unsignedinthash,ihash;structip_vs_dest*dest;+/* first try the dest it's supposed to go to */+ihash=ip_vs_sh_hashkey(svc->af,addr,port,0);+dest=rcu_dereference(s->buckets[ihash].dest);+if(!dest)+returnNULL;+if(!is_unavailable(dest))+returndest;++IP_VS_DBG_BUF(6,"SH: selected unavailable server %s:%d, reselecting",+IP_VS_DBG_ADDR(svc->af,&dest->addr),ntohs(dest->port));++/* if the original dest is unavailable, loop around the table+*startingfromihashtofindanewdest+*/for(offset=0;offset<IP_VS_SH_TAB_SIZE;offset++){-hash=ip_vs_sh_hashkey(svc->af,addr,port,offset);+roffset=(offset+ihash)%IP_VS_SH_TAB_SIZE;+hash=ip_vs_sh_hashkey(svc->af,addr,port,roffset);dest=rcu_dereference(s->buckets[hash].dest);if(!dest)break;-if(is_unavailable(dest))-IP_VS_DBG_BUF(6,"SH: selected unavailable server "-"%s:%d (offset %d)",-IP_VS_DBG_ADDR(svc->af,&dest->addr),-ntohs(dest->port),offset);-else+if(!is_unavailable(dest))returndest;+IP_VS_DBG_BUF(6,"SH: selected unavailable "+"server %s:%d (offset %d), reselecting",+IP_VS_DBG_ADDR(svc->af,&dest->addr),+ntohs(dest->port),roffset);}returnNULL;
Hello,
On Fri, 27 Sep 2013, Alexander Frolkin wrote:
Improve the SH fallback realserver selection strategy.
With sh and sh-fallback, if a realserver is down, this attempts to
distribute the traffic that would have gone to that server evenly
among the remaining servers.
Signed-off-by: Alexander Frolkin <redacted>
Thanks! Looks good to me.
Acked-by: Julian Anastasov <ja@ssi.bg>
@@ -115,27 +115,46 @@ ip_vs_sh_get(struct ip_vs_service *svc, struct ip_vs_sh_state *s,}-/* As ip_vs_sh_get, but with fallback if selected server is unavailable */+/* As ip_vs_sh_get, but with fallback if selected server is unavailable+*+*Thefallbackstrategyloopsaroundthetablestartingfroma"random"+*point(infact,itischosentobetheoriginalhashvaluetomakethe+*algorithmdeterministic)tofindanewserver.+*/staticinlinestructip_vs_dest*ip_vs_sh_get_fallback(structip_vs_service*svc,structip_vs_sh_state*s,constunionnf_inet_addr*addr,__be16port){-unsignedintoffset;-unsignedinthash;+unsignedintoffset,roffset;+unsignedinthash,ihash;structip_vs_dest*dest;+/* first try the dest it's supposed to go to */+ihash=ip_vs_sh_hashkey(svc->af,addr,port,0);+dest=rcu_dereference(s->buckets[ihash].dest);+if(!dest)+returnNULL;+if(!is_unavailable(dest))+returndest;++IP_VS_DBG_BUF(6,"SH: selected unavailable server %s:%d, reselecting",+IP_VS_DBG_ADDR(svc->af,&dest->addr),ntohs(dest->port));++/* if the original dest is unavailable, loop around the table+*startingfromihashtofindanewdest+*/for(offset=0;offset<IP_VS_SH_TAB_SIZE;offset++){-hash=ip_vs_sh_hashkey(svc->af,addr,port,offset);+roffset=(offset+ihash)%IP_VS_SH_TAB_SIZE;+hash=ip_vs_sh_hashkey(svc->af,addr,port,roffset);dest=rcu_dereference(s->buckets[hash].dest);if(!dest)break;-if(is_unavailable(dest))-IP_VS_DBG_BUF(6,"SH: selected unavailable server "-"%s:%d (offset %d)",-IP_VS_DBG_ADDR(svc->af,&dest->addr),-ntohs(dest->port),offset);-else+if(!is_unavailable(dest))returndest;+IP_VS_DBG_BUF(6,"SH: selected unavailable "+"server %s:%d (offset %d), reselecting",+IP_VS_DBG_ADDR(svc->af,&dest->addr),+ntohs(dest->port),roffset);}returnNULL;
From: Simon Horman <horms@verge.net.au> Date: 2013-10-15 01:55:30
On Fri, Sep 27, 2013 at 10:20:42PM +0300, Julian Anastasov wrote:
Hello,
On Fri, 27 Sep 2013, Alexander Frolkin wrote:
quoted
Improve the SH fallback realserver selection strategy.
With sh and sh-fallback, if a realserver is down, this attempts to
distribute the traffic that would have gone to that server evenly
among the remaining servers.
Signed-off-by: Alexander Frolkin <redacted>
Thanks! Looks good to me.
Acked-by: Julian Anastasov <ja@ssi.bg>
Sorry for letting this one slip.
I have queued it up.