r4966 - in trunk/varnish-cache: bin/varnishd include lib/libvarnishapi

phk at varnish-cache.org phk at varnish-cache.org
Wed Jun 16 22:23:12 CEST 2010


Author: phk
Date: 2010-06-16 22:23:12 +0200 (Wed, 16 Jun 2010)
New Revision: 4966

Modified:
   trunk/varnish-cache/bin/varnishd/cache_backend.c
   trunk/varnish-cache/include/vsc.h
   trunk/varnish-cache/include/vsc_fields.h
   trunk/varnish-cache/lib/libvarnishapi/vsc.c
Log:
Introduce the first per-backend stats counter:  number of VCLs referencing
this set of counters.

Backend stats counters are indexed purely by the backend name,
across all VCLs:  If you redefine or have conflicting definitions
of a backend with a given name, in different VCLs loaded at the
same time, they will share stats counters.

Not optimal, but I think the alternative would be worse.



Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c	2010-06-16 12:47:07 UTC (rev 4965)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c	2010-06-16 20:23:12 UTC (rev 4966)
@@ -456,6 +456,73 @@
 }
 
 /*--------------------------------------------------------------------
+ * Backend VSC counters
+ *
+ * We use a private list, because we do not trust the content of the
+ * VSM (to hold our refcount).
+ *
+ * Backend stats are indexed purely by name, across all VCLs.
+ */
+
+struct vbe_cnt {
+	unsigned		magic;
+#define CNT_PRIV_MAGIC		0x1acda1f5
+	VTAILQ_ENTRY(vbe_cnt)	list;
+	char			*name;
+	int			refcnt;
+	struct vsc_vbe		*vsc_vbe;
+};
+
+static VTAILQ_HEAD(, vbe_cnt) vbe_cnt_head =
+     VTAILQ_HEAD_INITIALIZER(vbe_cnt_head);
+
+static struct vsc_vbe *
+vbe_stat_ref(const char *name)
+{
+	struct vbe_cnt *vc;
+
+	ASSERT_CLI();
+	VTAILQ_FOREACH(vc, &vbe_cnt_head, list) {
+		if (!strcmp(vc->name, name)) {
+			vc->refcnt++;
+			vc->vsc_vbe->vcls = vc->refcnt;
+			return (vc->vsc_vbe);
+		}
+	}
+	ALLOC_OBJ(vc, CNT_PRIV_MAGIC);
+	AN(vc);
+	REPLACE(vc->name, name);
+	VTAILQ_INSERT_HEAD(&vbe_cnt_head, vc, list);
+	vc->vsc_vbe = VSM_Alloc(sizeof *vc->vsc_vbe,
+	    VSC_CLASS, VSC_TYPE_VBE, name);
+	AN(vc->vsc_vbe);
+	vc->refcnt = 1;
+	vc->vsc_vbe->vcls = vc->refcnt;
+	return (vc->vsc_vbe);
+}
+
+static void
+vbe_stat_deref(const char *name)
+{
+	struct vbe_cnt *vc;
+
+	ASSERT_CLI();
+	VTAILQ_FOREACH(vc, &vbe_cnt_head, list)
+		if (!strcmp(vc->name, name))
+			break;
+	AN(vc);
+	vc->refcnt--;
+	vc->vsc_vbe->vcls = vc->refcnt;
+	if (vc->refcnt > 0)
+		return;
+	AZ(vc->refcnt);
+	VTAILQ_REMOVE(&vbe_cnt_head, vc, list);
+	VSM_Free(vc->vsc_vbe);
+	FREE_OBJ(vc);
+}
+
+
+/*--------------------------------------------------------------------
  * The "simple" director really isn't, since thats where all the actual
  * connections happen.  Nontheless, pretend it is simple by sequestering
  * the directoricity of it under this line.
@@ -466,6 +533,7 @@
 #define VDI_SIMPLE_MAGIC	0x476d25b7
 	struct director		dir;
 	struct backend		*backend;
+	struct vsc_vbe		*stats;
 };
 
 static struct vbe_conn *
@@ -507,6 +575,7 @@
 	CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC);
 
 	VBE_DropRef(vs->backend);
+	vbe_stat_deref(vs->dir.vcl_name);
 	free(vs->dir.vcl_name);
 	vs->dir.magic = 0;
 	FREE_OBJ(vs);
@@ -534,6 +603,7 @@
 	vs->dir.healthy = vdi_simple_healthy;
 
 	vs->backend = VBE_AddBackend(cli, t);
+	vs->stats = vbe_stat_ref(t->vcl_name);
 
 	bp[idx] = &vs->dir;
 }

Modified: trunk/varnish-cache/include/vsc.h
===================================================================
--- trunk/varnish-cache/include/vsc.h	2010-06-16 12:47:07 UTC (rev 4965)
+++ trunk/varnish-cache/include/vsc.h	2010-06-16 20:23:12 UTC (rev 4966)
@@ -48,3 +48,11 @@
 #include "vsc_fields.h"
 #undef VSC_F_SMA
 };
+
+#define VSC_TYPE_VBE	"VBE"
+
+struct vsc_vbe {
+#define VSC_F_VBE(n, t, l, f, e)	t n;
+#include "vsc_fields.h"
+#undef VSC_F_VBE
+};

Modified: trunk/varnish-cache/include/vsc_fields.h
===================================================================
--- trunk/varnish-cache/include/vsc_fields.h	2010-06-16 12:47:07 UTC (rev 4965)
+++ trunk/varnish-cache/include/vsc_fields.h	2010-06-16 20:23:12 UTC (rev 4966)
@@ -32,12 +32,12 @@
  * stats structure.
  */
 
+/**********************************************************************/
 #ifndef VSC_F_MAIN
 #define VSC_F_MAIN(a, b, c, d, e)
 #define __VSC_F_MAIN
 #endif
 
-
 VSC_F_MAIN(client_conn,		uint64_t, 0, 'a', "Client connections accepted")
 VSC_F_MAIN(client_drop,		uint64_t, 0, 'a',
 					"Connection dropped, no sess/wrk")
@@ -161,6 +161,8 @@
 #undef __VSC_F_MAIN
 #endif
 
+/**********************************************************************/
+
 #ifndef VSC_F_SMA
 #define VSC_F_SMA(a, b, c, d, e)
 #define __VSC_F_SMA
@@ -176,3 +178,17 @@
 #undef VSC_F_SMA
 #undef __VSC_F_SMA
 #endif
+
+/**********************************************************************/
+
+#ifndef VSC_F_VBE
+#define VSC_F_VBE(a, b, c, d, e)
+#define __VSC_F_VBE
+#endif
+
+VSC_F_VBE(vcls,			uint64_t, 0, 'i', "VCL references")
+
+#ifdef __VSC_F_VBE
+#undef VSC_F_VBE
+#undef __VSC_F_VBE
+#endif

Modified: trunk/varnish-cache/lib/libvarnishapi/vsc.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsc.c	2010-06-16 12:47:07 UTC (rev 4965)
+++ trunk/varnish-cache/lib/libvarnishapi/vsc.c	2010-06-16 20:23:12 UTC (rev 4966)
@@ -339,6 +339,34 @@
 	return (0);
 }
 
+static int
+iter_vbe(const struct vsc *vsc, struct vsm_chunk *sha, vsc_iter_f *func,
+    void *priv)
+{
+	struct vsc_vbe *st;
+	struct vsc_point sp;
+	int i;
+
+	CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC);
+	CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC);
+	st = VSM_PTR(sha);
+
+	sp.class = VSC_TYPE_VBE;
+	sp.ident = sha->ident;
+#define VSC_F_VBE(nn, tt, ll, ff, dd)				\
+	sp.name = #nn;							\
+	sp.fmt = #tt;							\
+	sp.flag = ff;							\
+	sp.desc = dd;							\
+	sp.ptr = &st->nn;						\
+	i = iter_call(vsc, func, priv, &sp);				\
+	if (i)								\
+		return(i);
+#include "vsc_fields.h"
+#undef VSC_F_VBE
+	return (0);
+}
+
 int
 VSC_Iter(struct VSM_data *vd, vsc_iter_f *func, void *priv)
 {
@@ -359,6 +387,8 @@
 			i = iter_main(vsc, sha, func, priv);
 		else if (!strcmp(sha->type, VSC_TYPE_SMA))
 			i = iter_sma(vsc, sha, func, priv);
+		else if (!strcmp(sha->type, VSC_TYPE_VBE))
+			i = iter_vbe(vsc, sha, func, priv);
 		else
 			i = -1;
 		if (i != 0)




More information about the varnish-commit mailing list