r1032 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Sat Sep 16 22:17:15 CEST 2006


Author: phk
Date: 2006-09-16 22:17:15 +0200 (Sat, 16 Sep 2006)
New Revision: 1032

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_expire.c
   trunk/varnish-cache/bin/varnishd/cache_pool.c
   trunk/varnish-cache/bin/varnishd/cache_vcl.c
Log:
VCL configs change relatively seldom so we can cache the requests
VCL reference in the worker thread when the request is done and
with a cheap check reuse it for the next request handled by this
thread.

This should reduce mutex contention.


Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-09-16 19:54:34 UTC (rev 1031)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-09-16 20:17:15 UTC (rev 1032)
@@ -113,6 +113,7 @@
 	size_t			liov;
 
 	struct acct		acct;
+	struct VCL_conf		*vcl;
 };
 
 struct workreq {
@@ -415,8 +416,9 @@
 
 /* cache_vcl.c */
 void VCL_Init(void);
-void VCL_Rel(struct VCL_conf *vc);
-struct VCL_conf *VCL_Get(void);
+void VCL_Refresh(struct VCL_conf **vcc);
+void VCL_Rel(struct VCL_conf **vcc);
+void VCL_Get(struct VCL_conf **vcc);
 
 #define VCL_RET_MAC(l,u,b,n)
 #define VCL_MET_MAC(l,u,b) void VCL_##l##_method(struct sess *);

Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2006-09-16 19:54:34 UTC (rev 1031)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2006-09-16 20:17:15 UTC (rev 1032)
@@ -130,7 +130,9 @@
 		vca_close_session(sp, sp->doclose);
 	sp->backend = NULL;
 	if (sp->vcl != NULL) {
-		VCL_Rel(sp->vcl);
+		if (sp->wrk->vcl != NULL)
+			VCL_Rel(&sp->wrk->vcl);
+		sp->wrk->vcl = sp->vcl;
 		sp->vcl = NULL;
 	}
 
@@ -653,7 +655,9 @@
 	VSL(SLT_ReqStart, sp->fd, "%s %s %u", sp->addr, sp->port,  sp->xid);
 
 	AZ(sp->vcl);
-	sp->vcl = VCL_Get();
+	VCL_Refresh(&sp->wrk->vcl);
+	sp->vcl = sp->wrk->vcl;
+	sp->wrk->vcl = NULL;
 
 	AZ(sp->obj);
 	AZ(sp->vbc);

Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_expire.c	2006-09-16 19:54:34 UTC (rev 1031)
+++ trunk/varnish-cache/bin/varnishd/cache_expire.c	2006-09-16 20:17:15 UTC (rev 1032)
@@ -113,7 +113,7 @@
 	sp = SES_New(NULL, 0);
 	XXXAN(sp);
 	sleep(10);		/* Takes time for VCL to arrive */
-	sp->vcl = VCL_Get();
+	VCL_Get(&sp->vcl);
 	t = time(NULL);
 	while (1) {
 		LOCK(&exp_mtx);
@@ -122,9 +122,9 @@
 			CHECK_OBJ(o, OBJECT_MAGIC);
 		if (o == NULL || o->ttl > t + expearly) {
 			UNLOCK(&exp_mtx);
-			VCL_Rel(sp->vcl);
+			VCL_Rel(&sp->vcl);
 			AZ(sleep(1));
-			sp->vcl = VCL_Get();
+			VCL_Get(&sp->vcl);
 			t = time(NULL);
 			continue;
 		}

Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-09-16 19:54:34 UTC (rev 1031)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-09-16 20:17:15 UTC (rev 1032)
@@ -218,6 +218,8 @@
 	VSL_stats->n_wrk--;
 	UNLOCK(&tmtx);
 	VSL(SLT_WorkThread, 0, "%p end", w);
+	if (w->vcl != NULL)
+		VCL_Rel(&w->vcl);
 	close(w->pipe[0]);
 	close(w->pipe[1]);
 	return (NULL);

Modified: trunk/varnish-cache/bin/varnishd/cache_vcl.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vcl.c	2006-09-16 19:54:34 UTC (rev 1031)
+++ trunk/varnish-cache/bin/varnishd/cache_vcl.c	2006-09-16 20:17:15 UTC (rev 1032)
@@ -41,25 +41,37 @@
 
 /*--------------------------------------------------------------------*/
 
-struct VCL_conf *
-VCL_Get(void)
+void
+VCL_Refresh(struct VCL_conf **vcc)
 {
-	struct VCL_conf *vc;
+	if (*vcc == vcl_active->conf)
+		return;
+	if (*vcc != NULL)
+		VCL_Rel(vcc);
+	VCL_Get(vcc);
+}
 
+void
+VCL_Get(struct VCL_conf **vcc)
+{
+
 	LOCK(&vcl_mtx);
 	AN(vcl_active);
-	vc = vcl_active->conf;
-	AN(vc);
-	vc->busy++;
+	*vcc = vcl_active->conf;
+	AN(*vcc);
+	(*vcc)->busy++;
 	UNLOCK(&vcl_mtx);
-	return (vc);
 }
 
 void
-VCL_Rel(struct VCL_conf *vc)
+VCL_Rel(struct VCL_conf **vcc)
 {
 	struct vcls *vcl;
+	struct VCL_conf *vc;
 
+	vc = *vcc;
+	*vcc = NULL;
+
 	LOCK(&vcl_mtx);
 	assert(vc->busy > 0);
 	vc->busy--;




More information about the varnish-commit mailing list