In another thread "Dynamically change server maxconn possible?",
someone raised the possibility of setting a per-server maxconn via the
stats socket. I believe the below patch implements this functionality.
I'd appreciate any feedback, since I'm not really familiar with this
part of the code. However, I've tested it by curling slow endpoints
(the nginx echo_sleep module, specifically) and can confirm that NOSRV
is returned appropriately according to whatever maxconn settings are
set via the socket.
- Andrew Hayworth
From 186f4a33fea210e63ef25b023adab9abf133004d Mon Sep 17 00:00:00 2001
From: Andrew Hayworth <andrew.hayworth@getbraintree.com>
Date: Mon, 19 Oct 2015 19:15:56 +0000
Subject: [PATCH] MINOR: cli: ability to set per-server maxconn
This commit adds support for setting a per-server maxconn from the stats
socket. The only really notable part of this commit is that we need to
check if maxconn == minconn before changing things, as this indicates
that we are NOT using dynamic maxconn. When we are not using dynamic
maxconn, we should update maxconn/minconn in lockstep.
---
src/dumpstats.c | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/src/dumpstats.c b/src/dumpstats.c
index e80e45c..b2bd13b 100644
--- a/src/dumpstats.c
+++ b/src/dumpstats.c
@@ -1646,6 +1646,35 @@ static int stats_sock_parse_request(struct
stream_interface *si, char *line)
return 1;
}
+ else if (strcmp(args[2], "server") == 0) {
+ struct server *sv;
+ int v;
+
+ sv = expect_server_admin(s, si, args[3]);
+ if (!sv)
+ return 1;
+
+ if (!*args[4]) {
+ appctx->ctx.cli.msg = "Integer value expected.\n";
+ appctx->st0 = STAT_CLI_PRINT;
+ return 1;
+ }
+
+ v = atoi(args[4]);
+ if (v < 0) {
+ appctx->ctx.cli.msg = "Value out of range.\n";
+ appctx->st0 = STAT_CLI_PRINT;
+ return 1;
+ }
+
+ if (sv->maxconn == sv->minconn) { // static maxconn
+ sv->maxconn = sv->minconn = v;
+ } else { // dynamic maxconn
+ sv->maxconn = v;
+ }
+
+ return 1;
+ }
else if (strcmp(args[2], "global") == 0) {
int v;
@@ -1681,7 +1710,7 @@ static int stats_sock_parse_request(struct
stream_interface *si, char *line)
return 1;
}
else {
- appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend' and
'global'.\n";
+ appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend',
'server', and 'global'.\n";
appctx->st0 = STAT_CLI_PRINT;
return 1;
}
--
2.1.3
someone raised the possibility of setting a per-server maxconn via the
stats socket. I believe the below patch implements this functionality.
I'd appreciate any feedback, since I'm not really familiar with this
part of the code. However, I've tested it by curling slow endpoints
(the nginx echo_sleep module, specifically) and can confirm that NOSRV
is returned appropriately according to whatever maxconn settings are
set via the socket.
- Andrew Hayworth
From 186f4a33fea210e63ef25b023adab9abf133004d Mon Sep 17 00:00:00 2001
From: Andrew Hayworth <andrew.hayworth@getbraintree.com>
Date: Mon, 19 Oct 2015 19:15:56 +0000
Subject: [PATCH] MINOR: cli: ability to set per-server maxconn
This commit adds support for setting a per-server maxconn from the stats
socket. The only really notable part of this commit is that we need to
check if maxconn == minconn before changing things, as this indicates
that we are NOT using dynamic maxconn. When we are not using dynamic
maxconn, we should update maxconn/minconn in lockstep.
---
src/dumpstats.c | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/src/dumpstats.c b/src/dumpstats.c
index e80e45c..b2bd13b 100644
--- a/src/dumpstats.c
+++ b/src/dumpstats.c
@@ -1646,6 +1646,35 @@ static int stats_sock_parse_request(struct
stream_interface *si, char *line)
return 1;
}
+ else if (strcmp(args[2], "server") == 0) {
+ struct server *sv;
+ int v;
+
+ sv = expect_server_admin(s, si, args[3]);
+ if (!sv)
+ return 1;
+
+ if (!*args[4]) {
+ appctx->ctx.cli.msg = "Integer value expected.\n";
+ appctx->st0 = STAT_CLI_PRINT;
+ return 1;
+ }
+
+ v = atoi(args[4]);
+ if (v < 0) {
+ appctx->ctx.cli.msg = "Value out of range.\n";
+ appctx->st0 = STAT_CLI_PRINT;
+ return 1;
+ }
+
+ if (sv->maxconn == sv->minconn) { // static maxconn
+ sv->maxconn = sv->minconn = v;
+ } else { // dynamic maxconn
+ sv->maxconn = v;
+ }
+
+ return 1;
+ }
else if (strcmp(args[2], "global") == 0) {
int v;
@@ -1681,7 +1710,7 @@ static int stats_sock_parse_request(struct
stream_interface *si, char *line)
return 1;
}
else {
- appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend' and
'global'.\n";
+ appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend',
'server', and 'global'.\n";
appctx->st0 = STAT_CLI_PRINT;
return 1;
}
--
2.1.3