[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 c72b55f..6a73504 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -540,7 +540,8 @@
}
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 9531773..6d4ea54 100644
--- a/src/dumpstats.c
+++ b/src/dumpstats.c
@@ -767,7 +767,7 @@
/* act, bck */
"<td>%s</td><td>%s</td>"
"",
- 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 @@
/* 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 @@
human_time(now.tv_sec - px->last_change, 1),
(px->lbprm.tot_weight > 0 || !px->srv) ? "UP" :
"<font color=\"red\"><b>DOWN</b></font>",
- 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 @@
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,