From 26cae562e98d761d708cc851df6733e0424ff8db Mon Sep 17 00:00:00 2001 From: phk Date: Tue, 19 Aug 2008 07:46:40 +0000 Subject: [PATCH] Add exponential average of responsetime to output git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3103 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- .../bin/varnishd/cache_backend_poll.c | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_backend_poll.c b/varnish-cache/bin/varnishd/cache_backend_poll.c index bfc5eaf9..2d76a1d4 100644 --- a/varnish-cache/bin/varnishd/cache_backend_poll.c +++ b/varnish-cache/bin/varnishd/cache_backend_poll.c @@ -54,6 +54,9 @@ #include "vrt.h" #include "cache_backend.h" +/* Default averaging rate, we want something pretty responsive */ +#define AVG_RATE 4 + struct vbp_target { unsigned magic; #define VBP_TARGET_MAGIC 0x6b7cb656 @@ -71,6 +74,10 @@ struct vbp_target { #include "cache_backend_poll.h" #undef BITMAP + double last; + double avg; + double rate; + VTAILQ_ENTRY(vbp_target) list; pthread_t thread; }; @@ -205,6 +212,7 @@ vbp_poke(struct vbp_target *vt) TCP_close(&s); t_now = TIM_real(); + vt->last = t_now - t_start; vt->good_recv |= 1; /* XXX: Check reponse status */ vt->happy |= 1; @@ -255,8 +263,16 @@ vbp_wrk_poll_backend(void *priv) #define BITMAP(n, c, t, b) vt->n <<= 1; #include "cache_backend_poll.h" #undef BITMAP + vt->last = 0; vbp_poke(vt); + /* Calculate exponential average */ + if (vt->happy & 1) { + if (vt->rate < AVG_RATE) + vt->rate += 1.0; + vt->avg += (vt->last - vt->avg) / vt->rate; + } + i = 0; #define BITMAP(n, c, t, b) bits[i++] = (vt->n & 1) ? c : '-'; #include "cache_backend_poll.h" @@ -284,9 +300,10 @@ vbp_wrk_poll_backend(void *priv) logmsg = "Still sick"; vt->backend->healthy = 0; } - VSL(SLT_Backend_health, 0, "%s %s %s %u %u %u", + VSL(SLT_Backend_health, 0, "%s %s %s %u %u %u %.6f %.6f", vt->backend->vcl_name, logmsg, bits, - vt->good, vt->probe.threshold, vt->probe.window); + vt->good, vt->probe.threshold, vt->probe.window, + vt->last, vt->avg); if (!vt->stop) dsleep(vt->probe.interval); @@ -325,6 +342,7 @@ vbp_health_one(struct cli *cli, const struct vbp_target *vt) vt->backend->healthy ? "Healthy" : "Sick"); cli_out(cli, "Current states good: %2u threshold: %2u window: %2u\n", vt->good, vt->probe.threshold, vt->probe.window); + cli_out(cli, "Average responsetime of good probes: %.6f\n", vt->avg); cli_out(cli, "Oldest " " Newest\n"); -- 2.39.5