Re: [PATCHv2] ipvs: improved SH fallback strategy

2013-10-14 Thread Simon Horman
On Fri, Sep 27, 2013 at 10:20:42PM +0300, Julian Anastasov wrote:
> 
>   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 
> 
>   Thanks! Looks good to me.
> 
> Acked-by: Julian Anastasov 

Sorry for letting this one slip.
I have queued it up.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCHv2] ipvs: improved SH fallback strategy

2013-10-14 Thread Simon Horman
On Fri, Sep 27, 2013 at 10:20:42PM +0300, Julian Anastasov wrote:
 
   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 a...@eldamar.org.uk
 
   Thanks! Looks good to me.
 
 Acked-by: Julian Anastasov j...@ssi.bg

Sorry for letting this one slip.
I have queued it up.
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCHv2] ipvs: improved SH fallback strategy

2013-09-27 Thread Julian Anastasov

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 

Thanks! Looks good to me.

Acked-by: Julian Anastasov 

> --
> diff --git a/net/netfilter/ipvs/ip_vs_sh.c b/net/netfilter/ipvs/ip_vs_sh.c
> index 3588fae..cc65b2f 100644
> --- a/net/netfilter/ipvs/ip_vs_sh.c
> +++ b/net/netfilter/ipvs/ip_vs_sh.c
> @@ -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
> + *
> + * The fallback strategy loops around the table starting from a "random"
> + * point (in fact, it is chosen to be the original hash value to make the
> + * algorithm deterministic) to find a new server.
> + */
>  static inline struct ip_vs_dest *
>  ip_vs_sh_get_fallback(struct ip_vs_service *svc, struct ip_vs_sh_state *s,
> const union nf_inet_addr *addr, __be16 port)
>  {
> - unsigned int offset;
> - unsigned int hash;
> + unsigned int offset, roffset;
> + unsigned int hash, ihash;
>   struct ip_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)
> + return NULL;
> + if (!is_unavailable(dest))
> + return dest;
> +
> + IP_VS_DBG_BUF(6, "SH: selected unavailable server %s:%d, reselecting",
> +   IP_VS_DBG_ADDR(svc->af, >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++) {
> - 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, >addr),
> -   ntohs(dest->port), offset);
> - else
> + if (!is_unavailable(dest))
>   return dest;
> + IP_VS_DBG_BUF(6, "SH: selected unavailable "
> +   "server %s:%d (offset %d), reselecting",
> +   IP_VS_DBG_ADDR(svc->af, >addr),
> +   ntohs(dest->port), roffset);
>   }
>  
>   return NULL;

Regards

--
Julian Anastasov 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCHv2] ipvs: improved SH fallback strategy

2013-09-27 Thread Alexander Frolkin
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 

--
diff --git a/net/netfilter/ipvs/ip_vs_sh.c b/net/netfilter/ipvs/ip_vs_sh.c
index 3588fae..cc65b2f 100644
--- a/net/netfilter/ipvs/ip_vs_sh.c
+++ b/net/netfilter/ipvs/ip_vs_sh.c
@@ -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
+ *
+ * The fallback strategy loops around the table starting from a "random"
+ * point (in fact, it is chosen to be the original hash value to make the
+ * algorithm deterministic) to find a new server.
+ */
 static inline struct ip_vs_dest *
 ip_vs_sh_get_fallback(struct ip_vs_service *svc, struct ip_vs_sh_state *s,
  const union nf_inet_addr *addr, __be16 port)
 {
-   unsigned int offset;
-   unsigned int hash;
+   unsigned int offset, roffset;
+   unsigned int hash, ihash;
struct ip_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)
+   return NULL;
+   if (!is_unavailable(dest))
+   return dest;
+
+   IP_VS_DBG_BUF(6, "SH: selected unavailable server %s:%d, reselecting",
+ IP_VS_DBG_ADDR(svc->af, >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++) {
-   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, >addr),
- ntohs(dest->port), offset);
-   else
+   if (!is_unavailable(dest))
return dest;
+   IP_VS_DBG_BUF(6, "SH: selected unavailable "
+ "server %s:%d (offset %d), reselecting",
+ IP_VS_DBG_ADDR(svc->af, >addr),
+ ntohs(dest->port), roffset);
}
 
return NULL;

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCHv2] ipvs: improved SH fallback strategy

2013-09-27 Thread Alexander Frolkin
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 a...@eldamar.org.uk

--
diff --git a/net/netfilter/ipvs/ip_vs_sh.c b/net/netfilter/ipvs/ip_vs_sh.c
index 3588fae..cc65b2f 100644
--- a/net/netfilter/ipvs/ip_vs_sh.c
+++ b/net/netfilter/ipvs/ip_vs_sh.c
@@ -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
+ *
+ * The fallback strategy loops around the table starting from a random
+ * point (in fact, it is chosen to be the original hash value to make the
+ * algorithm deterministic) to find a new server.
+ */
 static inline struct ip_vs_dest *
 ip_vs_sh_get_fallback(struct ip_vs_service *svc, struct ip_vs_sh_state *s,
  const union nf_inet_addr *addr, __be16 port)
 {
-   unsigned int offset;
-   unsigned int hash;
+   unsigned int offset, roffset;
+   unsigned int hash, ihash;
struct ip_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)
+   return NULL;
+   if (!is_unavailable(dest))
+   return 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++) {
-   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))
return 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), roffset);
}
 
return NULL;

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCHv2] ipvs: improved SH fallback strategy

2013-09-27 Thread Julian Anastasov

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 a...@eldamar.org.uk

Thanks! Looks good to me.

Acked-by: Julian Anastasov j...@ssi.bg

 --
 diff --git a/net/netfilter/ipvs/ip_vs_sh.c b/net/netfilter/ipvs/ip_vs_sh.c
 index 3588fae..cc65b2f 100644
 --- a/net/netfilter/ipvs/ip_vs_sh.c
 +++ b/net/netfilter/ipvs/ip_vs_sh.c
 @@ -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
 + *
 + * The fallback strategy loops around the table starting from a random
 + * point (in fact, it is chosen to be the original hash value to make the
 + * algorithm deterministic) to find a new server.
 + */
  static inline struct ip_vs_dest *
  ip_vs_sh_get_fallback(struct ip_vs_service *svc, struct ip_vs_sh_state *s,
 const union nf_inet_addr *addr, __be16 port)
  {
 - unsigned int offset;
 - unsigned int hash;
 + unsigned int offset, roffset;
 + unsigned int hash, ihash;
   struct ip_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)
 + return NULL;
 + if (!is_unavailable(dest))
 + return 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++) {
 - 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))
   return 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), roffset);
   }
  
   return NULL;

Regards

--
Julian Anastasov j...@ssi.bg
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/