r1039 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Sat Sep 16 23:35:44 CEST 2006


Author: phk
Date: 2006-09-16 23:35:44 +0200 (Sat, 16 Sep 2006)
New Revision: 1039

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_pool.c
   trunk/varnish-cache/bin/varnishd/cache_session.c
Log:
Preallocate a srcaddr per workerthread to speed up locked section.

Remember to free preallocated storage in workerthread.


Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-09-16 21:20:37 UTC (rev 1038)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-09-16 21:35:44 UTC (rev 1039)
@@ -113,6 +113,7 @@
 	size_t			liov;
 
 	struct VCL_conf		*vcl;
+	struct srcaddr		*srcaddr;
 };
 
 struct workreq {

Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-09-16 21:20:37 UTC (rev 1038)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-09-16 21:35:44 UTC (rev 1039)
@@ -222,6 +222,12 @@
 		VCL_Rel(&w->vcl);
 	close(w->pipe[0]);
 	close(w->pipe[1]);
+	if (w->srcaddr != NULL)
+		free(w->srcaddr);
+	if (w->nobjhead != NULL)
+		free(w->nobjhead);
+	if (w->nobj!= NULL)
+		free(w->nobj);
 	return (NULL);
 }
 

Modified: trunk/varnish-cache/bin/varnishd/cache_session.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_session.c	2006-09-16 21:20:37 UTC (rev 1038)
+++ trunk/varnish-cache/bin/varnishd/cache_session.c	2006-09-16 21:35:44 UTC (rev 1039)
@@ -105,6 +105,10 @@
 	ch = &srchash[v];
 	CHECK_OBJ(ch, SRCADDRHEAD_MAGIC);
 	now = sp->t_open.tv_sec;
+	if (sp->wrk->srcaddr == NULL) {
+		sp->wrk->srcaddr = calloc(sizeof *sp->wrk->srcaddr, 1);
+		XXXAN(sp->wrk->srcaddr);
+	}
 
 	LOCK(&ch->mtx);
 	c3 = NULL;
@@ -117,45 +121,38 @@
 			sp->srcaddr = c;
 			TAILQ_REMOVE(&ch->head, c, list);
 			TAILQ_INSERT_TAIL(&ch->head, c, list);
-			if (0 && c3 != NULL) {
+			if (c3 != NULL) {
 				TAILQ_REMOVE(&ch->head, c3, list);
 				VSL_stats->n_srcaddr--;
-				free(c3);
 			}
 			UNLOCK(&ch->mtx);
+			if (c3 != NULL)
+				free(c3);
 			return;
 		}
 		if (c->nref > 0 || c->ttl > now)
 			continue;
-		if (c3 == NULL) {
+		if (c3 == NULL)
 			c3 = c;
-			continue;
-		}
-		TAILQ_REMOVE(&ch->head, c, list);
-		free(c);
-		VSL_stats->n_srcaddr--;
 	}
 	if (c3 == NULL) {
-		c3 = malloc(sizeof *c3);
-		XXXAN(c3);
-		if (c3 != NULL)
-			VSL_stats->n_srcaddr++;
+		c3 = sp->wrk->srcaddr;
+		sp->wrk->srcaddr = NULL;
+		VSL_stats->n_srcaddr++;
 	} else
 		TAILQ_REMOVE(&ch->head, c3, list);
 	AN(c3);
-	if (c3 != NULL) {
-		memset(c3, 0, sizeof *c3);
-		strcpy(c3->addr, sp->addr);
-		c3->magic = SRCADDR_MAGIC;
-		c3->hash = u;
-		c3->acct.first = now;
-		c3->ttl = now + params->srcaddr_ttl;
-		c3->nref = 1;
-		c3->sah = ch;
-		VSL_stats->n_srcaddr_act++;
-		TAILQ_INSERT_TAIL(&ch->head, c3, list);
-		sp->srcaddr = c3;
-	}
+	memset(c3, 0, sizeof *c3);
+	c3->magic = SRCADDR_MAGIC;
+	strcpy(c3->addr, sp->addr);
+	c3->hash = u;
+	c3->acct.first = now;
+	c3->ttl = now + params->srcaddr_ttl;
+	c3->nref = 1;
+	c3->sah = ch;
+	VSL_stats->n_srcaddr_act++;
+	TAILQ_INSERT_TAIL(&ch->head, c3, list);
+	sp->srcaddr = c3;
 	UNLOCK(&ch->mtx);
 }
 




More information about the varnish-commit mailing list