From: menglong8.dong@gmail.com
To: kuba@kernel.org
Cc: horms@verge.net.au, ja@ssi.bg, pablo@netfilter.org,
kadlec@netfilter.org, fw@strlen.de, davem@davemloft.net,
edumazet@google.com, pabeni@redhat.com, netdev@vger.kernel.org,
lvs-devel@vger.kernel.org, linux-kernel@vger.kernel.org,
netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
Menglong Dong <imagedong@tencent.com>
Subject: [PATCH net-next] net: ipvs: random start for RR scheduler
Date: Mon, 9 May 2022 20:22:13 +0800 [thread overview]
Message-ID: <20220509122213.19508-1-imagedong@tencent.com> (raw)
From: Menglong Dong <imagedong@tencent.com>
For now, the start of the RR scheduler is in the order of dest
service added, it will result in imbalance if the load balance
is done in client side and long connect is used.
For example, we have client1, client2, ..., client5 and real service
service1, service2, service3. All clients have the same ipvs config,
and each of them will create 2 long TCP connect to the virtual
service. Therefore, all the clients will connect to service1 and
service2, leaving service3 free.
Fix this by randomize the start of dest service to RR scheduler when
IP_VS_SVC_F_SCHED_RR_RANDOM is set.
Signed-off-by: Menglong Dong <imagedong@tencent.com>
---
include/uapi/linux/ip_vs.h | 2 ++
net/netfilter/ipvs/ip_vs_rr.c | 25 ++++++++++++++++++++++++-
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/include/uapi/linux/ip_vs.h b/include/uapi/linux/ip_vs.h
index 4102ddcb4e14..7f74bafd3211 100644
--- a/include/uapi/linux/ip_vs.h
+++ b/include/uapi/linux/ip_vs.h
@@ -28,6 +28,8 @@
#define IP_VS_SVC_F_SCHED_SH_FALLBACK IP_VS_SVC_F_SCHED1 /* SH fallback */
#define IP_VS_SVC_F_SCHED_SH_PORT IP_VS_SVC_F_SCHED2 /* SH use port */
+#define IP_VS_SVC_F_SCHED_RR_RANDOM IP_VS_SVC_F_SCHED1 /* random start */
+
/*
* Destination Server Flags
*/
diff --git a/net/netfilter/ipvs/ip_vs_rr.c b/net/netfilter/ipvs/ip_vs_rr.c
index 38495c6f6c7c..e309d97bdd08 100644
--- a/net/netfilter/ipvs/ip_vs_rr.c
+++ b/net/netfilter/ipvs/ip_vs_rr.c
@@ -22,13 +22,36 @@
#include <net/ip_vs.h>
+static void ip_vs_rr_random_start(struct ip_vs_service *svc)
+{
+ struct list_head *cur;
+ u32 start;
+
+ if (!(svc->flags | IP_VS_SVC_F_SCHED_RR_RANDOM) ||
+ svc->num_dests <= 1)
+ return;
+
+ spin_lock_bh(&svc->sched_lock);
+ start = get_random_u32() % svc->num_dests;
+ cur = &svc->destinations;
+ while (start--)
+ cur = cur->next;
+ svc->sched_data = cur;
+ spin_unlock_bh(&svc->sched_lock);
+}
static int ip_vs_rr_init_svc(struct ip_vs_service *svc)
{
svc->sched_data = &svc->destinations;
+ ip_vs_rr_random_start(svc);
return 0;
}
+static int ip_vs_rr_add_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest)
+{
+ ip_vs_rr_random_start(svc);
+ return 0;
+}
static int ip_vs_rr_del_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest)
{
@@ -104,7 +127,7 @@ static struct ip_vs_scheduler ip_vs_rr_scheduler = {
.module = THIS_MODULE,
.n_list = LIST_HEAD_INIT(ip_vs_rr_scheduler.n_list),
.init_service = ip_vs_rr_init_svc,
- .add_dest = NULL,
+ .add_dest = ip_vs_rr_add_dest,
.del_dest = ip_vs_rr_del_dest,
.schedule = ip_vs_rr_schedule,
};
--
2.36.0
next reply other threads:[~2022-05-09 12:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-09 12:22 menglong8.dong [this message]
2022-05-09 18:17 ` [PATCH net-next] net: ipvs: random start for RR scheduler Julian Anastasov
2022-05-10 2:55 ` Menglong Dong
2022-05-10 20:18 ` Julian Anastasov
2022-05-12 22:23 ` Julian Anastasov
2022-05-10 3:21 ` Menglong Dong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220509122213.19508-1-imagedong@tencent.com \
--to=menglong8.dong@gmail.com \
--cc=coreteam@netfilter.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fw@strlen.de \
--cc=horms@verge.net.au \
--cc=imagedong@tencent.com \
--cc=ja@ssi.bg \
--cc=kadlec@netfilter.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lvs-devel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).