]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] slowstart: ensure we don't start with a null weight
authorWilly Tarreau <w@1wt.eu>
Mon, 3 Dec 2007 01:04:00 +0000 (02:04 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 3 Dec 2007 01:04:00 +0000 (02:04 +0100)
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.

src/checks.c
src/dumpstats.c

index c72b55f629181f19e779548787c227c931dad4dd..6a735046721b24815e24f35a7ccb11c618e1bbaa 100644 (file)
@@ -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);
index 9531773f7f7bf01c6584e2330c05dbaf96c5bd8c..6d4ea5440c44e3fb959c403a69be8900b851e879 100644 (file)
@@ -767,7 +767,7 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri,
                                     /* 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 @@ 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" :
                                             "<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 @@ 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,