r5089 - trunk/varnish-cache/bin/varnishd

phk at varnish-cache.org phk at varnish-cache.org
Wed Aug 11 14:12:48 CEST 2010


Author: phk
Date: 2010-08-11 14:12:47 +0200 (Wed, 11 Aug 2010)
New Revision: 5089

Modified:
   trunk/varnish-cache/bin/varnishd/cache_backend.c
   trunk/varnish-cache/bin/varnishd/cache_backend.h
   trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c
Log:
Move the per backend stats counters to "struct backend"



Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c	2010-08-11 11:37:01 UTC (rev 5088)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c	2010-08-11 12:12:47 UTC (rev 5089)
@@ -456,73 +456,6 @@
 }
 
 /*--------------------------------------------------------------------
- * 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.
@@ -533,7 +466,6 @@
 #define VDI_SIMPLE_MAGIC	0x476d25b7
 	struct director		dir;
 	struct backend		*backend;
-	struct vsc_vbe		*stats;
 };
 
 /* Returns the backend if and only if the this is a simple director.
@@ -593,7 +525,7 @@
 	CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC);
 
 	VBE_DropRef(vs->backend);
-	vbe_stat_deref(vs->dir.vcl_name);
+	// vbe_stat_deref(vs->dir.vcl_name);
 	free(vs->dir.vcl_name);
 	vs->dir.magic = 0;
 	FREE_OBJ(vs);
@@ -621,7 +553,6 @@
 	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/bin/varnishd/cache_backend.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.h	2010-08-11 11:37:01 UTC (rev 5088)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.h	2010-08-11 12:12:47 UTC (rev 5089)
@@ -113,31 +113,34 @@
 	unsigned		magic;
 #define BACKEND_MAGIC		0x64c4c7c6
 
+	VTAILQ_ENTRY(backend)	list;
+	int			refcount;
+	struct lock		mtx;
+
 	char			*hosthdr;
 	char			*vcl_name;
 	char			*ipv4_addr;
 	char			*ipv6_addr;
 	char			*port;
-	double			connect_timeout;
-	double			first_byte_timeout;
-	double			between_bytes_timeout;
 
-	VTAILQ_ENTRY(backend)	list;
-	int			refcount;
-	struct lock		mtx;
-
 	struct sockaddr		*ipv4;
 	socklen_t		ipv4len;
 	struct sockaddr		*ipv6;
 	socklen_t		ipv6len;
 
-	unsigned		max_conn;
 	unsigned		n_conn;
 	VTAILQ_HEAD(, vbc)	connlist;
 
 	struct vbp_target	*probe;
 	unsigned		healthy;
 	VTAILQ_HEAD(, trouble)	troublelist;
+
+	struct vsc_vbe		*vsc;
+
+	double			connect_timeout;
+	double			first_byte_timeout;
+	double			between_bytes_timeout;
+	unsigned		max_conn;
 	unsigned		saintmode_threshold;
 };
 

Modified: trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c	2010-08-11 11:37:01 UTC (rev 5088)
+++ trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c	2010-08-11 12:12:47 UTC (rev 5089)
@@ -72,6 +72,7 @@
 	free(b->ipv6);
 	free(b->ipv6_addr);
 	free(b->port);
+	VSM_Free(b->vsc);
 	FREE_OBJ(b);
 	VSC_main->n_backend--;
 }
@@ -174,6 +175,7 @@
 VBE_AddBackend(struct cli *cli, const struct vrt_backend *vb)
 {
 	struct backend *b;
+	char buf[128];
 
 	AN(vb->vcl_name);
 	assert(vb->ipv4_sockaddr != NULL || vb->ipv6_sockaddr != NULL);
@@ -203,6 +205,11 @@
 	Lck_New(&b->mtx);
 	b->refcount = 1;
 
+	bprintf(buf, "%s(%s,%s,%s)",
+	    vb->vcl_name, vb->ipv4_addr, vb->ipv6_addr, vb->port);
+
+	b->vsc = VSM_Alloc(sizeof *b->vsc, VSC_CLASS, VSC_TYPE_VBE, buf);
+
 	VTAILQ_INIT(&b->connlist);
 
 	VTAILQ_INIT(&b->troublelist);




More information about the varnish-commit mailing list