]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stats: report correct throttling percentage for servers in slowstart
authorWilly Tarreau <w@1wt.eu>
Thu, 21 Nov 2013 14:30:45 +0000 (15:30 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 21 Nov 2013 14:30:45 +0000 (15:30 +0100)
The column used to report the throttle percentage when a server is in
slowstart is based on the time only. This is wrong, because server weights
in slowstart are updated at most once a second, so the reported value is
wrong at least fo rone second during each step, which means all the time
when using short delays (< 20s).

The second point is that it's disturbing to see a weight < 100% without
any throttle at the end of the period (during the last second), because
the effective weight has not yet been updated.

Instead, we now compute the exact ratio between eweight and uweight and
report it. It's always accurate and describes the value being used instead
of using only the date.

It can be backported to 1.4 though it's not particularly important.

include/proto/server.h
src/dumpstats.c

index d19c6ac9fce8748084b863db095d763c344e72eb..9c1dbf7fb634cd6c8ef3af4c7ec6b07fb9f93469 100644 (file)
@@ -64,6 +64,20 @@ void srv_dump_kws(char **out);
  */
 void server_recalc_eweight(struct server *sv);
 
+/* returns the current server throttle rate between 0 and 100% */
+static inline unsigned int server_throttle_rate(struct server *sv)
+{
+       struct proxy *px = sv->proxy;
+
+       /* when uweight is 0, we're in soft-stop so that cannot be a slowstart,
+        * thus the throttle is 100%.
+        */
+       if (!sv->uweight)
+               return 100;
+
+       return 100U * (px->lbprm.wmult * sv->eweight + px->lbprm.wdiv - 1) / (px->lbprm.wdiv * sv->uweight);
+}
+
 /*
  * Parses weight_str and configures sv accordingly.
  * Returns NULL on success, error message string otherwise.
index e23a766aab1e30192dfcb76476415cfbcd2ad49b..99d16d7d814c2d09cc15298fb886e3f7061da519 100644 (file)
@@ -2326,12 +2326,8 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, in
                        chunk_appendf(&trash, "<td colspan=3></td>");
 
                /* throttle */
-               if ((sv->state & SRV_WARMINGUP) &&
-                   now.tv_sec < sv->last_change + sv->slowstart &&
-                   now.tv_sec >= sv->last_change) {
-                       chunk_appendf(&trash, "<td class=ac>%d %%</td></tr>\n",
-                                     (int)MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart));
-               }
+               if (sv->state & SRV_WARMINGUP)
+                       chunk_appendf(&trash, "<td class=ac>%d %%</td></tr>\n", server_throttle_rate(sv));
                else
                        chunk_appendf(&trash, "<td class=ac>-</td></tr>\n");
        }
@@ -2406,10 +2402,8 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, in
                              relative_pid, px->uuid, sv->puid);
 
                /* throttle */
-               if ((sv->state & SRV_WARMINGUP) &&
-                   now.tv_sec < sv->last_change + sv->slowstart &&
-                   now.tv_sec >= sv->last_change)
-                       chunk_appendf(&trash, "%d", (int)MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart));
+               if (sv->state & SRV_WARMINGUP)
+                       chunk_appendf(&trash, "%d", server_throttle_rate(sv));
 
                /* sessions: lbtot */
                chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn);