From: Willy Tarreau Date: Mon, 3 Dec 2007 01:04:00 +0000 (+0100) Subject: [MEDIUM] slowstart: ensure we don't start with a null weight X-Git-Tag: v1.3.14~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5542af65dcc4f89355b06fee6d81afe55671ecf1;p=thirdparty%2Fhaproxy.git [MEDIUM] slowstart: ensure we don't start with a null weight Because of a divide, it was possible to have a null weight during a slowstart, which is pretty annoying, especially with a single server and a long slowstart. Also, fix the way we report the values in the stats page to avoid confusion. --- diff --git a/src/checks.c b/src/checks.c index c72b55f629..6a73504672 100644 --- a/src/checks.c +++ b/src/checks.c @@ -540,7 +540,8 @@ void process_chk(struct task *t, struct timeval *next) } else if (s->proxy->lbprm.algo & BE_LB_PROP_DYN) { /* for dynamic algorithms, let's update the weight */ - s->eweight = BE_WEIGHT_SCALE * (now.tv_sec - s->last_change) / s->slowstart; + s->eweight = (BE_WEIGHT_SCALE * (now.tv_sec - s->last_change) + + s->slowstart - 1) / s->slowstart; s->eweight *= s->uweight; if (s->proxy->lbprm.update_server_eweight) s->proxy->lbprm.update_server_eweight(s); diff --git a/src/dumpstats.c b/src/dumpstats.c index 9531773f7f..6d4ea5440c 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -767,7 +767,7 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri, /* act, bck */ "%s%s" "", - sv->eweight * px->lbprm.wmult / px->lbprm.wdiv, + (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, (sv->state & SRV_BACKUP) ? "-" : "Y", (sv->state & SRV_BACKUP) ? "Y" : "-"); @@ -834,7 +834,7 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri, /* weight, active, backup */ "%d,%d,%d," "", - sv->eweight * px->lbprm.wmult / px->lbprm.wdiv, + (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, (sv->state & SRV_BACKUP) ? 0 : 1, (sv->state & SRV_BACKUP) ? 1 : 0); @@ -910,7 +910,7 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri, human_time(now.tv_sec - px->last_change, 1), (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", - px->lbprm.tot_weight * px->lbprm.wmult / px->lbprm.wdiv, + (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, px->srv_act, px->srv_bck); chunk_printf(&msg, sizeof(trash), @@ -956,7 +956,7 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri, px->failed_conns, px->failed_resp, px->retries, px->redispatches, (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", - px->lbprm.tot_weight * px->lbprm.wmult / px->lbprm.wdiv, + (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, px->srv_act, px->srv_bck, px->down_trans, now.tv_sec - px->last_change, px->srv?be_downtime(px):0,