mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-15 11:37:01 +02:00
[MEDIUM] support setting a server weight to zero
Sometimes it is useful to be able to set a server's weight to zero.
It allows the server to receive only persistent traffic but never
normal traffic.
(cherry picked from commit 6704d67d65
)
This commit is contained in:
parent
de5ba00c9a
commit
1c2f47166c
@ -4400,11 +4400,12 @@ weight <weight>
|
|||||||
The "weight" parameter is used to adjust the server's weight relative to
|
The "weight" parameter is used to adjust the server's weight relative to
|
||||||
other servers. All servers will receive a load proportional to their weight
|
other servers. All servers will receive a load proportional to their weight
|
||||||
relative to the sum of all weights, so the higher the weight, the higher the
|
relative to the sum of all weights, so the higher the weight, the higher the
|
||||||
load. The default weight is 1, and the maximal value is 255. If this
|
load. The default weight is 1, and the maximal value is 256. A value of 0
|
||||||
parameter is used to distribute the load according to server's capacity, it
|
means the server will not participate in load-balancing but will still accept
|
||||||
is recommended to start with values which can both grow and shrink, for
|
persistent connections. If this parameter is used to distribute the load
|
||||||
instance between 10 and 100 to leave enough room above and below for later
|
according to server's capacity, it is recommended to start with values which
|
||||||
adjustments.
|
can both grow and shrink, for instance between 10 and 100 to leave enough
|
||||||
|
room above and below for later adjustments.
|
||||||
|
|
||||||
|
|
||||||
6. HTTP header manipulation
|
6. HTTP header manipulation
|
||||||
|
@ -201,7 +201,8 @@ void recalc_server_map(struct proxy *px)
|
|||||||
int max = 0;
|
int max = 0;
|
||||||
best = NULL;
|
best = NULL;
|
||||||
for (cur = px->srv; cur; cur = cur->next) {
|
for (cur = px->srv; cur; cur = cur->next) {
|
||||||
if (flag == (cur->state &
|
if (cur->eweight &&
|
||||||
|
flag == (cur->state &
|
||||||
(SRV_RUNNING | SRV_GOINGDOWN | SRV_BACKUP))) {
|
(SRV_RUNNING | SRV_GOINGDOWN | SRV_BACKUP))) {
|
||||||
int v;
|
int v;
|
||||||
|
|
||||||
@ -248,15 +249,24 @@ void init_server_map(struct proxy *p)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* We will factor the weights to reduce the table,
|
/* We will factor the weights to reduce the table,
|
||||||
* using Euclide's largest common divisor algorithm
|
* using Euclide's largest common divisor algorithm.
|
||||||
|
* Since we may have zero weights, we have to first
|
||||||
|
* find a non-zero weight server.
|
||||||
*/
|
*/
|
||||||
pgcd = p->srv->uweight;
|
pgcd = 1;
|
||||||
for (srv = p->srv->next; srv && pgcd > 1; srv = srv->next) {
|
srv = p->srv;
|
||||||
int w = srv->uweight;
|
while (srv && !srv->uweight)
|
||||||
while (w) {
|
srv = srv->next;
|
||||||
int t = pgcd % w;
|
|
||||||
pgcd = w;
|
if (srv) {
|
||||||
w = t;
|
pgcd = srv->uweight; /* note: cannot be zero */
|
||||||
|
while (pgcd > 1 && (srv = srv->next)) {
|
||||||
|
int w = srv->uweight;
|
||||||
|
while (w) {
|
||||||
|
int t = pgcd % w;
|
||||||
|
pgcd = w;
|
||||||
|
w = t;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,6 +291,9 @@ void init_server_map(struct proxy *p)
|
|||||||
if (act < bck)
|
if (act < bck)
|
||||||
act = bck;
|
act = bck;
|
||||||
|
|
||||||
|
if (!act)
|
||||||
|
act = 1;
|
||||||
|
|
||||||
p->lbprm.map.srv = (struct server **)calloc(act, sizeof(struct server *));
|
p->lbprm.map.srv = (struct server **)calloc(act, sizeof(struct server *));
|
||||||
/* recounts servers and their weights */
|
/* recounts servers and their weights */
|
||||||
p->lbprm.map.state = PR_MAP_RECALC;
|
p->lbprm.map.state = PR_MAP_RECALC;
|
||||||
|
@ -2126,8 +2126,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int inv)
|
|||||||
else if (!strcmp(args[cur_arg], "weight")) {
|
else if (!strcmp(args[cur_arg], "weight")) {
|
||||||
int w;
|
int w;
|
||||||
w = atol(args[cur_arg + 1]);
|
w = atol(args[cur_arg + 1]);
|
||||||
if (w < 1 || w > 256) {
|
if (w < 0 || w > 256) {
|
||||||
Alert("parsing [%s:%d] : weight of server %s is not within 1 and 256 (%d).\n",
|
Alert("parsing [%s:%d] : weight of server %s is not within 0 and 256 (%d).\n",
|
||||||
file, linenum, newsrv->id, w);
|
file, linenum, newsrv->id, w);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user