mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-09 16:47:18 +02:00
[MINOR] changed server weight storage from char to unsigned int
This change does not affect memory usage much, but it simplifies the code a lot by removing many +1/-1 operations on weights.
This commit is contained in:
parent
91b6f329eb
commit
417fae0e60
@ -82,8 +82,8 @@ struct server {
|
|||||||
int curfd; /* file desc used for current test, or -1 if not in test */
|
int curfd; /* file desc used for current test, or -1 if not in test */
|
||||||
|
|
||||||
char *id; /* just for identification */
|
char *id; /* just for identification */
|
||||||
unsigned char uweight, eweight; /* user-specified weight-1, and effective weight-1 */
|
unsigned uweight, eweight; /* user-specified weight, and effective weight */
|
||||||
unsigned int wscore; /* weight score, used during srv map computation */
|
unsigned wscore; /* weight score, used during srv map computation */
|
||||||
|
|
||||||
unsigned failed_checks, down_trans; /* failed checks and up-down transitions */
|
unsigned failed_checks, down_trans; /* failed checks and up-down transitions */
|
||||||
unsigned failed_conns, failed_resp; /* failed connect() and responses */
|
unsigned failed_conns, failed_resp; /* failed connect() and responses */
|
||||||
|
@ -59,10 +59,10 @@ void recount_servers(struct proxy *px)
|
|||||||
if (srv->state & SRV_RUNNING) {
|
if (srv->state & SRV_RUNNING) {
|
||||||
if (srv->state & SRV_BACKUP) {
|
if (srv->state & SRV_BACKUP) {
|
||||||
px->srv_bck++;
|
px->srv_bck++;
|
||||||
px->tot_wbck += srv->eweight + 1;
|
px->tot_wbck += srv->eweight;
|
||||||
} else {
|
} else {
|
||||||
px->srv_act++;
|
px->srv_act++;
|
||||||
px->tot_wact += srv->eweight + 1;
|
px->tot_wact += srv->eweight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ void recalc_server_map(struct proxy *px)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
cur->wscore += cur->eweight + 1;
|
cur->wscore += cur->eweight;
|
||||||
v = (cur->wscore + tot) / tot; /* result between 0 and 3 */
|
v = (cur->wscore + tot) / tot; /* result between 0 and 3 */
|
||||||
if (best == NULL || v > max) {
|
if (best == NULL || v > max) {
|
||||||
max = v;
|
max = v;
|
||||||
|
@ -1197,6 +1197,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args)
|
|||||||
newsrv->rise = DEF_RISETIME;
|
newsrv->rise = DEF_RISETIME;
|
||||||
newsrv->fall = DEF_FALLTIME;
|
newsrv->fall = DEF_FALLTIME;
|
||||||
newsrv->health = newsrv->rise; /* up, but will fall down at first failure */
|
newsrv->health = newsrv->rise; /* up, but will fall down at first failure */
|
||||||
|
newsrv->uweight = 1;
|
||||||
|
|
||||||
cur_arg = 3;
|
cur_arg = 3;
|
||||||
while (*args[cur_arg]) {
|
while (*args[cur_arg]) {
|
||||||
@ -1238,7 +1239,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args)
|
|||||||
file, linenum, newsrv->id, w);
|
file, linenum, newsrv->id, w);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
newsrv->uweight = w - 1;
|
newsrv->uweight = w;
|
||||||
cur_arg += 2;
|
cur_arg += 2;
|
||||||
}
|
}
|
||||||
else if (!strcmp(args[cur_arg], "minconn")) {
|
else if (!strcmp(args[cur_arg], "minconn")) {
|
||||||
@ -2346,11 +2347,11 @@ int readcfgfile(const char *file)
|
|||||||
/* 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
|
||||||
*/
|
*/
|
||||||
pgcd = newsrv->uweight + 1;
|
pgcd = newsrv->uweight;
|
||||||
for (srv = newsrv->next; srv && pgcd > 1; srv = srv->next) {
|
for (srv = newsrv->next; srv && pgcd > 1; srv = srv->next) {
|
||||||
int t, w;
|
int t, w;
|
||||||
|
|
||||||
w = srv->uweight + 1;
|
w = srv->uweight;
|
||||||
while (w) {
|
while (w) {
|
||||||
t = pgcd % w;
|
t = pgcd % w;
|
||||||
pgcd = w;
|
pgcd = w;
|
||||||
@ -2360,11 +2361,11 @@ int readcfgfile(const char *file)
|
|||||||
|
|
||||||
act = bck = 0;
|
act = bck = 0;
|
||||||
for (srv = newsrv; srv; srv = srv->next) {
|
for (srv = newsrv; srv; srv = srv->next) {
|
||||||
srv->eweight = ((srv->uweight + 1) / pgcd) - 1;
|
srv->eweight = srv->uweight / pgcd;
|
||||||
if (srv->state & SRV_BACKUP)
|
if (srv->state & SRV_BACKUP)
|
||||||
bck += srv->eweight + 1;
|
bck += srv->eweight;
|
||||||
else
|
else
|
||||||
act += srv->eweight + 1;
|
act += srv->eweight;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this is the largest map we will ever need for this servers list */
|
/* this is the largest map we will ever need for this servers list */
|
||||||
|
@ -3512,7 +3512,7 @@ int produce_content_stats_proxy(struct session *s, struct proxy *px)
|
|||||||
/* act, bck */
|
/* act, bck */
|
||||||
"<td>%s</td><td>%s</td>"
|
"<td>%s</td><td>%s</td>"
|
||||||
"",
|
"",
|
||||||
sv->uweight+1,
|
sv->uweight,
|
||||||
(sv->state & SRV_BACKUP) ? "-" : "Y",
|
(sv->state & SRV_BACKUP) ? "-" : "Y",
|
||||||
(sv->state & SRV_BACKUP) ? "Y" : "-");
|
(sv->state & SRV_BACKUP) ? "Y" : "-");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user