[master] b1ad9cd Move the wthread_stats_rate check into the threadpool, so that it also takes account of fetch jobs.

Poul-Henning Kamp phk at FreeBSD.org
Tue May 20 10:02:31 CEST 2014


commit b1ad9cd6488ecbd7d969542372c9f665125a5f8d
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue May 20 08:01:53 2014 +0000

    Move the wthread_stats_rate check into the threadpool, so that it
    also takes account of fetch jobs.

diff --git a/bin/varnishd/cache/cache_http1_fsm.c b/bin/varnishd/cache/cache_http1_fsm.c
index 3702827..9191d1c 100644
--- a/bin/varnishd/cache/cache_http1_fsm.c
+++ b/bin/varnishd/cache/cache_http1_fsm.c
@@ -240,9 +240,6 @@ http1_cleanup(struct sess *sp, struct worker *wrk, struct req *req)
 		return (SESS_DONE_RET_GONE);
 	}
 
-	if (wrk->stats.client_req >= cache_param->wthread_stats_rate)
-		WRK_SumStat(wrk);
-
 	WS_Reset(req->ws, NULL);
 	WS_Reset(wrk->aws, NULL);
 
diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c
index ce8d526..fd5a43c 100644
--- a/bin/varnishd/cache/cache_pool.c
+++ b/bin/varnishd/cache/cache_pool.c
@@ -255,13 +255,13 @@ void
 Pool_Work_Thread(void *priv, struct worker *wrk)
 {
 	struct pool *pp;
-	int stats_clean;
+	int stats_dirty;
 	struct pool_task *tp;
 	int i;
 
 	CAST_OBJ_NOTNULL(pp, priv, POOL_MAGIC);
 	wrk->pool = pp;
-	stats_clean = 1;
+	stats_dirty = 0;
 	while (1) {
 		Lck_Lock(&pp->mtx);
 
@@ -286,8 +286,10 @@ Pool_Work_Thread(void *priv, struct worker *wrk)
 			wrk->task.func = NULL;
 			wrk->task.priv = wrk;
 			VTAILQ_INSERT_HEAD(&pp->idle_queue, &wrk->task, list);
-			if (!stats_clean)
+			if (stats_dirty) {
 				WRK_SumStat(wrk);
+				stats_dirty = 0;
+			}
 			do {
 				i = Lck_CondWait(&wrk->cond, &pp->mtx,
 				    wrk->vcl == NULL ?  0 : wrk->lastused+60.);
@@ -303,7 +305,12 @@ Pool_Work_Thread(void *priv, struct worker *wrk)
 
 		assert(wrk->pool == pp);
 		tp->func(wrk, tp->priv);
-		stats_clean = WRK_TrySumStat(wrk);
+
+		if (++stats_dirty >= cache_param->wthread_stats_rate) {
+			WRK_SumStat(wrk);
+			stats_dirty = 0;
+		} else if (WRK_TrySumStat(wrk))
+			stats_dirty = 0;
 	}
 	wrk->pool = NULL;
 }
diff --git a/bin/varnishd/cache/cache_wrk.c b/bin/varnishd/cache/cache_wrk.c
index 7f9d410..2c266ce 100644
--- a/bin/varnishd/cache/cache_wrk.c
+++ b/bin/varnishd/cache/cache_wrk.c
@@ -43,12 +43,12 @@ static struct lock		wstat_mtx;
 /*--------------------------------------------------------------------*/
 
 static void
-wrk_sumstat(struct worker *w)
+wrk_sumstat(const struct dstat *ds)
 {
 
 	Lck_AssertHeld(&wstat_mtx);
 #define L0(n)
-#define L1(n) (VSC_C_main->n += w->stats.n)
+#define L1(n) (VSC_C_main->n += ds->n)
 #define VSC_F(n, t, l, f, v, d, e) L##l(n);
 #include "tbl/vsc_f_main.h"
 #undef VSC_F
@@ -61,7 +61,7 @@ WRK_SumStat(struct worker *w)
 {
 
 	Lck_Lock(&wstat_mtx);
-	wrk_sumstat(w);
+	wrk_sumstat(&w->stats);
 	Lck_Unlock(&wstat_mtx);
 	memset(&w->stats, 0, sizeof w->stats);
 }
@@ -71,7 +71,7 @@ WRK_TrySumStat(struct worker *w)
 {
 	if (Lck_Trylock(&wstat_mtx))
 		return (0);
-	wrk_sumstat(w);
+	wrk_sumstat(&w->stats);
 	Lck_Unlock(&wstat_mtx);
 	memset(&w->stats, 0, sizeof w->stats);
 	return (1);
diff --git a/bin/varnishd/mgt/mgt_pool.c b/bin/varnishd/mgt/mgt_pool.c
index b3294f7..f43f019 100644
--- a/bin/varnishd/mgt/mgt_pool.c
+++ b/bin/varnishd/mgt/mgt_pool.c
@@ -183,8 +183,8 @@ struct parspec WRK_parspec[] = {
 		"0", NULL,
 		"Worker threads accumulate statistics, and dump these into "
 		"the global stats counters if the lock is free when they "
-		"finish a request.\n"
-		"This parameters defines the maximum number of requests "
+		"finish a job (request/fetch etc.)\n"
+		"This parameters defines the maximum number of jobs "
 		"a worker thread may handle, before it is forced to dump "
 		"its accumulated stats into the global counters.",
 		EXPERIMENTAL,



More information about the varnish-commit mailing list