r4215 - in trunk/varnish-cache: bin/varnishd include

phk at projects.linpro.no phk at projects.linpro.no
Fri Aug 28 16:44:02 CEST 2009


Author: phk
Date: 2009-08-28 16:44:02 +0200 (Fri, 28 Aug 2009)
New Revision: 4215

Modified:
   trunk/varnish-cache/bin/varnishd/acct_fields.h
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_hash.c
   trunk/varnish-cache/bin/varnishd/cache_session.c
   trunk/varnish-cache/include/stat_field.h
Log:
Work over the stats while I wait for -spersistent to crash:

Move most of the stat fields used in cache_center.c into the workers
private stats, hopefully reducing the lock contention and stats
precision at the same time.



Modified: trunk/varnish-cache/bin/varnishd/acct_fields.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/acct_fields.h	2009-08-28 14:19:41 UTC (rev 4214)
+++ trunk/varnish-cache/bin/varnishd/acct_fields.h	2009-08-28 14:44:02 UTC (rev 4215)
@@ -27,6 +27,10 @@
  * SUCH DAMAGE.
  *
  * $Id$
+ *
+ * These are the stats we keep track of per session.  They will be summed,
+ * via the sp->wrk->stats into the s_<name> fields in the SHM file.
+ * NB: Remember to mark those in stat_field.h to be included in struct dstat.
  */
 
 ACCT(sess)

Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2009-08-28 14:19:41 UTC (rev 4214)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2009-08-28 14:44:02 UTC (rev 4215)
@@ -105,7 +105,8 @@
 			i = poll(pfd, 1, params->session_linger);
 			if (i == 0) {
 				WSL(sp->wrk, SLT_Debug, sp->fd, "herding");
-				VSL_stats->sess_herd++;
+				sp->wrk->stats->sess_herd++;
+				SES_Charge(sp);
 				sp->wrk = NULL;
 				vca_return_session(sp);
 				return (1);
@@ -254,9 +255,11 @@
 	sp->t_resp = NAN;
 	WSL_Flush(sp->wrk, 0);
 
-	/* If we did an ESI include, don't mess up our state */
-	if (sp->esis > 0)
+	/* If we did an ESI include, don't mess up our state */ 
+	if (sp->esis > 0) {
+		SES_Charge(sp);
 		return (1);
+	}
 
 	sp->t_req = NAN;
 
@@ -269,8 +272,8 @@
 		vca_close_session(sp, sp->doclose);
 	}
 	if (sp->fd < 0) {
+		sp->wrk->stats->sess_closed++;
 		SES_Charge(sp);
-		VSL_stats->sess_closed++;
 		sp->wrk = NULL;
 		SES_Delete(sp);
 		return (1);
@@ -281,21 +284,21 @@
 
 	i = HTC_Reinit(sp->htc);
 	if (i == 1) {
-		VSL_stats->sess_pipeline++;
+		sp->wrk->stats->sess_pipeline++;
 		sp->step = STP_START;
 		return (0);
 	}
 	if (Tlen(sp->htc->rxbuf)) {
-		VSL_stats->sess_readahead++;
+		sp->wrk->stats->sess_readahead++;
 		sp->step = STP_WAIT;
 		return (0);
 	}
 	if (params->session_linger > 0) {
-		VSL_stats->sess_linger++;
+		sp->wrk->stats->sess_linger++;
 		sp->step = STP_WAIT;
 		return (0);
 	}
-	VSL_stats->sess_herd++;
+	sp->wrk->stats->sess_herd++;
 	SES_Charge(sp);
 	sp->wrk = NULL;
 	vca_return_session(sp);
@@ -745,6 +748,7 @@
 		 * worker thread.   The hash code to restart the session,
 		 * still in STP_LOOKUP, later when the busy object isn't.
 		 */
+		AZ(sp->wrk);
 		return (1);
 	}
 
@@ -753,7 +757,7 @@
 
 	/* If we inserted a new object it's a miss */
 	if (oc->flags & OC_F_BUSY) {
-		VSL_stats->cache_miss++;
+		sp->wrk->stats->cache_miss++;
 
 		AZ(oc->obj);
 		sp->objhead = oh;
@@ -767,7 +771,7 @@
 	sp->obj = o;
 
 	if (oc->flags & OC_F_PASS) {
-		VSL_stats->cache_hitpass++;
+		sp->wrk->stats->cache_hitpass++;
 		WSP(sp, SLT_HitPass, "%u", sp->obj->xid);
 		HSH_Deref(sp->wrk, &sp->obj);
 		sp->objcore = NULL;
@@ -776,7 +780,7 @@
 		return (0);
 	}
 
-	VSL_stats->cache_hit++;
+	sp->wrk->stats->cache_hit++;
 	WSP(sp, SLT_Hit, "%u", sp->obj->xid);
 	sp->step = STP_HIT;
 	return (0);
@@ -1045,7 +1049,7 @@
 	AZ(sp->vcl);
 
 	/* Update stats of various sorts */
-	VSL_stats->client_req++;			/* XXX not locked */
+	sp->wrk->stats->client_req++;
 	sp->t_req = TIM_real();
 	sp->wrk->lastused = sp->t_req;
 	sp->acct_req.req++;

Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c	2009-08-28 14:19:41 UTC (rev 4214)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c	2009-08-28 14:44:02 UTC (rev 4215)
@@ -530,6 +530,7 @@
 		if (params->diag_bitmap & 0x20)
 			WSP(sp, SLT_Debug,
 				"on waiting list <%s>", oh->hash);
+		SES_Charge(sp);
 		sp->objhead = oh;
 		sp->wrk = NULL;
 		Lck_Unlock(&oh->mtx);

Modified: trunk/varnish-cache/bin/varnishd/cache_session.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_session.c	2009-08-28 14:19:41 UTC (rev 4214)
+++ trunk/varnish-cache/bin/varnishd/cache_session.c	2009-08-28 14:44:02 UTC (rev 4215)
@@ -80,27 +80,17 @@
 
 /*--------------------------------------------------------------------*/
 
-static void
-ses_sum_acct(struct acct *sum, const struct acct *inc)
-{
-
-#define ACCT(foo)	sum->foo += inc->foo;
-#include "acct_fields.h"
-#undef ACCT
-}
-
 void
 SES_Charge(struct sess *sp)
 {
 	struct acct *a = &sp->acct_req;
 
-	ses_sum_acct(&sp->acct, a);
-	Lck_Lock(&stat_mtx);
-#define ACCT(foo)	VSL_stats->s_##foo += a->foo;
+#define ACCT(foo)	\
+	sp->wrk->stats->s_##foo += a->foo; 	\
+	sp->acct.foo += a->foo;		\
+	a->foo = 0;
 #include "acct_fields.h"
 #undef ACCT
-	Lck_Unlock(&stat_mtx);
-	memset(a, 0, sizeof *a);
 }
 
 /*--------------------------------------------------------------------*/

Modified: trunk/varnish-cache/include/stat_field.h
===================================================================
--- trunk/varnish-cache/include/stat_field.h	2009-08-28 14:19:41 UTC (rev 4214)
+++ trunk/varnish-cache/include/stat_field.h	2009-08-28 14:44:02 UTC (rev 4215)
@@ -27,15 +27,18 @@
  * SUCH DAMAGE.
  *
  * $Id$
+ *
+ * 3rd argument marks fields for inclusion in the per worker-thread
+ * stats structure.
  */
 
 MAC_STAT(client_conn,		uint64_t, 0, 'a', "Client connections accepted")
 MAC_STAT(client_drop,		uint64_t, 0, 'a', "Connection dropped, no sess")
-MAC_STAT(client_req,		uint64_t, 0, 'a', "Client requests received")
+MAC_STAT(client_req,		uint64_t, 1, 'a', "Client requests received")
 
-MAC_STAT(cache_hit,		uint64_t, 0, 'a', "Cache hits")
-MAC_STAT(cache_hitpass,		uint64_t, 0, 'a', "Cache hits for pass")
-MAC_STAT(cache_miss,		uint64_t, 0, 'a', "Cache misses")
+MAC_STAT(cache_hit,		uint64_t, 1, 'a', "Cache hits")
+MAC_STAT(cache_hitpass,		uint64_t, 1, 'a', "Cache hits for pass")
+MAC_STAT(cache_miss,		uint64_t, 1, 'a', "Cache misses")
 
 MAC_STAT(backend_conn,		uint64_t, 0, 'a', "Backend conn. success")
 MAC_STAT(backend_unhealthy,	uint64_t, 0, 'a', "Backend conn. not attempted")
@@ -75,19 +78,19 @@
 MAC_STAT(n_objwrite,		uint64_t, 0, 'a', "Objects sent with write")
 MAC_STAT(n_objoverflow,		uint64_t, 0, 'a', "Objects overflowing workspace")
 
-MAC_STAT(s_sess,		uint64_t, 0, 'a', "Total Sessions")
-MAC_STAT(s_req,			uint64_t, 0, 'a', "Total Requests")
-MAC_STAT(s_pipe,		uint64_t, 0, 'a', "Total pipe")
-MAC_STAT(s_pass,		uint64_t, 0, 'a', "Total pass")
-MAC_STAT(s_fetch,		uint64_t, 0, 'a', "Total fetch")
-MAC_STAT(s_hdrbytes,		uint64_t, 0, 'a', "Total header bytes")
-MAC_STAT(s_bodybytes,		uint64_t, 0, 'a', "Total body bytes")
+MAC_STAT(s_sess,		uint64_t, 1, 'a', "Total Sessions")
+MAC_STAT(s_req,			uint64_t, 1, 'a', "Total Requests")
+MAC_STAT(s_pipe,		uint64_t, 1, 'a', "Total pipe")
+MAC_STAT(s_pass,		uint64_t, 1, 'a', "Total pass")
+MAC_STAT(s_fetch,		uint64_t, 1, 'a', "Total fetch")
+MAC_STAT(s_hdrbytes,		uint64_t, 1, 'a', "Total header bytes")
+MAC_STAT(s_bodybytes,		uint64_t, 1, 'a', "Total body bytes")
 
-MAC_STAT(sess_closed,		uint64_t, 0, 'a', "Session Closed")
-MAC_STAT(sess_pipeline,		uint64_t, 0, 'a', "Session Pipeline")
-MAC_STAT(sess_readahead,	uint64_t, 0, 'a', "Session Read Ahead")
-MAC_STAT(sess_linger,		uint64_t, 0, 'a', "Session Linger")
-MAC_STAT(sess_herd,		uint64_t, 0, 'a', "Session herd")
+MAC_STAT(sess_closed,		uint64_t, 1, 'a', "Session Closed")
+MAC_STAT(sess_pipeline,		uint64_t, 1, 'a', "Session Pipeline")
+MAC_STAT(sess_readahead,	uint64_t, 1, 'a', "Session Read Ahead")
+MAC_STAT(sess_linger,		uint64_t, 1, 'a', "Session Linger")
+MAC_STAT(sess_herd,		uint64_t, 1, 'a', "Session herd")
 
 MAC_STAT(shm_records,		uint64_t, 0, 'a', "SHM records")
 MAC_STAT(shm_writes,		uint64_t, 0, 'a', "SHM writes")



More information about the varnish-commit mailing list