[master] 7de67d2 Backend fetch counters

Martin Blix Grydeland martin at varnish-software.com
Mon Mar 31 11:28:00 CEST 2014


commit 7de67d2d327c8e255e1900f62ee784b7dfdc4e66
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Sun Mar 30 16:00:03 2014 +0200

    Backend fetch counters
    
    Add per-backend VSC counters for traffic going in/out of this backend.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index bf28983..c8d8d89 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -806,8 +806,8 @@ void VBE_DiscardHealth(const struct director *vdi);
 
 struct vbc *VDI_GetFd(struct busyobj *);
 int VDI_Healthy(const struct director *);
-void VDI_CloseFd(struct vbc **vbp);
-void VDI_RecycleFd(struct vbc **vbp);
+void VDI_CloseFd(struct vbc **vbp, const struct acct_bereq *);
+void VDI_RecycleFd(struct vbc **vbp, const struct acct_bereq *);
 void VDI_AddHostHeader(struct http *to, const struct vbc *vbc);
 void VBE_Poll(void);
 void VDI_Init(void);
diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index 3725e89..6622f4b 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -288,7 +288,7 @@ vbe_GetVbe(struct busyobj *bo, struct vdi_simple *vs)
 		VSL_Flush(bo->vsl, 0);
 
 		VTCP_close(&vc->fd);
-		VBE_DropRefConn(bp);
+		VBE_DropRefConn(bp, NULL);
 		vc->backend = NULL;
 		VBE_ReleaseConn(vc);
 	}
diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h
index c339563..c9ce112 100644
--- a/bin/varnishd/cache/cache_backend.h
+++ b/bin/varnishd/cache/cache_backend.h
@@ -152,9 +152,9 @@ struct vbc {
 void VBE_ReleaseConn(struct vbc *vc);
 
 /* cache_backend_cfg.c */
-void VBE_DropRefConn(struct backend *);
+void VBE_DropRefConn(struct backend *, const struct acct_bereq *);
 void VBE_DropRefVcl(struct backend *);
-void VBE_DropRefLocked(struct backend *b);
+void VBE_DropRefLocked(struct backend *b, const struct acct_bereq *);
 unsigned VBE_Healthy(const struct backend *b, double *changed);
 
 /* cache_backend_poll.c */
diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c
index 5a43c2e..9adb616 100644
--- a/bin/varnishd/cache/cache_backend_cfg.c
+++ b/bin/varnishd/cache/cache_backend_cfg.c
@@ -97,7 +97,7 @@ VBE_Poll(void)
  */
 
 void
-VBE_DropRefLocked(struct backend *b)
+VBE_DropRefLocked(struct backend *b, const struct acct_bereq *acct)
 {
 	int i;
 	struct vbc *vbe, *vbe2;
@@ -105,6 +105,13 @@ VBE_DropRefLocked(struct backend *b)
 	CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC);
 	assert(b->refcount > 0);
 
+	if (acct != NULL) {
+#define ACCT(foo) \
+		b->vsc->foo += acct->foo;
+#include "tbl/acct_fields_bereq.h"
+#undef ACCT
+	}
+
 	i = --b->refcount;
 	Lck_Unlock(&b->mtx);
 	if (i > 0)
@@ -131,11 +138,11 @@ VBE_DropRefVcl(struct backend *b)
 
 	Lck_Lock(&b->mtx);
 	b->vsc->vcls--;
-	VBE_DropRefLocked(b);
+	VBE_DropRefLocked(b, NULL);
 }
 
 void
-VBE_DropRefConn(struct backend *b)
+VBE_DropRefConn(struct backend *b, const struct acct_bereq *acct)
 {
 
 	CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC);
@@ -143,7 +150,7 @@ VBE_DropRefConn(struct backend *b)
 	Lck_Lock(&b->mtx);
 	assert(b->n_conn > 0);
 	b->n_conn--;
-	VBE_DropRefLocked(b);
+	VBE_DropRefLocked(b, acct);
 }
 
 /*--------------------------------------------------------------------
diff --git a/bin/varnishd/cache/cache_dir.c b/bin/varnishd/cache/cache_dir.c
index 94ef47d..7491d44 100644
--- a/bin/varnishd/cache/cache_dir.c
+++ b/bin/varnishd/cache/cache_dir.c
@@ -40,7 +40,7 @@
 /* Close a connection ------------------------------------------------*/
 
 void
-VDI_CloseFd(struct vbc **vbp)
+VDI_CloseFd(struct vbc **vbp, const struct acct_bereq *acct)
 {
 	struct backend *bp;
 	struct vbc *vc;
@@ -64,7 +64,7 @@ VDI_CloseFd(struct vbc **vbp)
 	vc->vsl = NULL;
 
 	VTCP_close(&vc->fd);
-	VBE_DropRefConn(bp);
+	VBE_DropRefConn(bp, acct);
 	vc->backend = NULL;
 	VBE_ReleaseConn(vc);
 }
@@ -72,7 +72,7 @@ VDI_CloseFd(struct vbc **vbp)
 /* Recycle a connection ----------------------------------------------*/
 
 void
-VDI_RecycleFd(struct vbc **vbp)
+VDI_RecycleFd(struct vbc **vbp, const struct acct_bereq *acct)
 {
 	struct backend *bp;
 	struct vbc *vc;
@@ -95,7 +95,7 @@ VDI_RecycleFd(struct vbc **vbp)
 	Lck_Lock(&bp->mtx);
 	VSC_C_main->backend_recycle++;
 	VTAILQ_INSERT_HEAD(&bp->connlist, vc, list);
-	VBE_DropRefLocked(bp);
+	VBE_DropRefLocked(bp, acct);
 }
 
 /* Get a connection --------------------------------------------------*/
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index cd627cd..775d66c 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -319,7 +319,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
 
 	if (bo->htc.body_status == BS_ERROR) {
 		AN (bo->vbc);
-		VDI_CloseFd(&bo->vbc);
+		VDI_CloseFd(&bo->vbc, &bo->acct);
 		VSLb(bo->vsl, SLT_VCL_Error, "Body cannot be fetched");
 		return (F_STP_ERROR);
 	}
@@ -351,7 +351,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
 
 	if (wrk->handling == VCL_RET_RETRY) {
 		AN (bo->vbc);
-		VDI_CloseFd(&bo->vbc);
+		VDI_CloseFd(&bo->vbc, &bo->acct);
 		bo->retries++;
 		if (bo->retries <= cache_param->max_retries)
 			return (F_STP_RETRY);
@@ -471,7 +471,7 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 
 	if (vbf_beresp2obj(bo)) {
 		(void)VFP_Error(bo, "Could not get storage");
-		VDI_CloseFd(&bo->vbc);
+		VDI_CloseFd(&bo->vbc, &bo->acct);
 		return (F_STP_ERROR);
 	}
 
@@ -761,9 +761,9 @@ vbf_fetch_thread(struct worker *wrk, void *priv)
 
 	if (bo->vbc != NULL) {
 		if (bo->should_close)
-			VDI_CloseFd(&bo->vbc);
+			VDI_CloseFd(&bo->vbc, &bo->acct);
 		else
-			VDI_RecycleFd(&bo->vbc);
+			VDI_RecycleFd(&bo->vbc, &bo->acct);
 		AZ(bo->vbc);
 	}
 
diff --git a/bin/varnishd/cache/cache_http1_fetch.c b/bin/varnishd/cache/cache_http1_fetch.c
index b6fac38..4ddacb1 100644
--- a/bin/varnishd/cache/cache_http1_fetch.c
+++ b/bin/varnishd/cache/cache_http1_fetch.c
@@ -350,7 +350,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo, struct req *req)
 		VSLb(bo->vsl, SLT_FetchError, "backend write error: %d (%s)",
 		    errno, strerror(errno));
 		VSLb_ts_busyobj(bo, "Bereq", W_TIM_real(wrk));
-		VDI_CloseFd(&bo->vbc);
+		VDI_CloseFd(&bo->vbc, &bo->acct);
 		/* XXX: other cleanup ? */
 		return (retry);
 	}
@@ -376,7 +376,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo, struct req *req)
 			VSLb(bo->vsl, SLT_FetchError,
 			    "http %sread error: overflow",
 			    first ? "first " : "");
-			VDI_CloseFd(&bo->vbc);
+			VDI_CloseFd(&bo->vbc, &bo->acct);
 			/* XXX: other cleanup ? */
 			return (-1);
 		}
@@ -384,7 +384,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo, struct req *req)
 			bo->acct.beresp_hdrbytes += Tlen(htc->rxbuf);
 			VSLb(bo->vsl, SLT_FetchError, "http %sread error: EOF",
 			    first ? "first " : "");
-			VDI_CloseFd(&bo->vbc);
+			VDI_CloseFd(&bo->vbc, &bo->acct);
 			/* XXX: other cleanup ? */
 			return (retry);
 		}
@@ -401,7 +401,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo, struct req *req)
 
 	if (HTTP1_DissectResponse(hp, htc)) {
 		VSLb(bo->vsl, SLT_FetchError, "http format error");
-		VDI_CloseFd(&bo->vbc);
+		VDI_CloseFd(&bo->vbc, &bo->acct);
 		/* XXX: other cleanup ? */
 		return (-1);
 	}
diff --git a/bin/varnishd/cache/cache_pipe.c b/bin/varnishd/cache/cache_pipe.c
index 05b8d0a..02d6c21 100644
--- a/bin/varnishd/cache/cache_pipe.c
+++ b/bin/varnishd/cache/cache_pipe.c
@@ -70,7 +70,7 @@ rdf(int fd0, int fd1, ssize_t *pcnt)
 }
 
 static void
-pipecharge(struct req *req, const struct acct_pipe *a)
+pipecharge(struct req *req, const struct acct_pipe *a, struct VSC_C_vbe *b)
 {
 
 	VSLb(req->vsl, SLT_PipeAcct, "%ju %ju %ju %ju",
@@ -83,6 +83,11 @@ pipecharge(struct req *req, const struct acct_pipe *a)
 	VSC_C_main->s_pipe_hdrbytes += a->req;
 	VSC_C_main->s_pipe_in += a->in;
 	VSC_C_main->s_pipe_out += a->out;
+	if (b != NULL) {
+		b->pipe_hdrbytes += a->bereq;
+		b->pipe_out += a->in;
+		b->pipe_in += a->out;
+	}
 	Lck_Unlock(&pipestat_mtx);
 }
 
@@ -110,7 +115,7 @@ PipeRequest(struct req *req, struct busyobj *bo)
 
 	vc = VDI_GetFd(bo);
 	if (vc == NULL) {
-		pipecharge(req, &acct);
+		pipecharge(req, &acct, NULL);
 		SES_Close(req->sp, SC_OVERLOAD);
 		return;
 	}
@@ -133,9 +138,9 @@ PipeRequest(struct req *req, struct busyobj *bo)
 	VSLb_ts_req(req, "Pipe", W_TIM_real(wrk));
 
 	if (i) {
-		pipecharge(req, &acct);
+		pipecharge(req, &acct, vc->backend->vsc);
 		SES_Close(req->sp, SC_TX_PIPE);
-		VDI_CloseFd(&vc);
+		VDI_CloseFd(&vc, NULL);
 		return;
 	}
 
@@ -173,9 +178,9 @@ PipeRequest(struct req *req, struct busyobj *bo)
 		}
 	}
 	VSLb_ts_req(req, "PipeSess", W_TIM_real(wrk));
-	pipecharge(req, &acct);
+	pipecharge(req, &acct, vc->backend->vsc);
 	SES_Close(req->sp, SC_TX_PIPE);
-	VDI_CloseFd(&vc);
+	VDI_CloseFd(&vc, NULL);
 	bo->vbc = NULL;
 }
 
diff --git a/include/tbl/vsc_fields.h b/include/tbl/vsc_fields.h
index c05d428..64e63a3 100644
--- a/include/tbl/vsc_fields.h
+++ b/include/tbl/vsc_fields.h
@@ -184,6 +184,36 @@ VSC_F(happy,			uint64_t, 0, 'b', info,
     "Happy health probes",
 	""
 )
+VSC_F(bereq_hdrbytes,		uint64_t, 0, 'a', info,
+    "Request header bytes",
+	"Total backend request header bytes sent"
+)
+VSC_F(bereq_bodybytes,		uint64_t, 0, 'a', info,
+    "Request body bytes",
+	"Total backend request body bytes sent"
+)
+VSC_F(beresp_hdrbytes,		uint64_t, 0, 'a', info,
+    "Response header bytes",
+	"Total backend response header bytes received"
+)
+VSC_F(beresp_bodybytes,		uint64_t, 0, 'a', info,
+    "Response body bytes",
+	"Total backend response body bytes received"
+)
+VSC_F(pipe_hdrbytes,		uint64_t, 0, 'a', info,
+    "Pipe request header bytes",
+	"Total request bytes sent for piped sessions"
+)
+VSC_F(pipe_out,			uint64_t, 0, 'a', info,
+    "Piped bytes to backend",
+	"Total number of bytes forwarded to backend in"
+	" pipe sessions"
+)
+VSC_F(pipe_in,			uint64_t, 0, 'a', info,
+    "Piped bytes from backend",
+	"Total number of bytes forwarded from backend in"
+	" pipe sessions"
+)
 
 #endif
 



More information about the varnish-commit mailing list