r4071 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Mon May 11 11:48:56 CEST 2009


Author: phk
Date: 2009-05-11 11:48:55 +0200 (Mon, 11 May 2009)
New Revision: 4071

Modified:
   trunk/varnish-cache/bin/varnishd/cache_acceptor.c
   trunk/varnish-cache/bin/varnishd/cache_session.c
Log:
Shift the responsibility for washing used sessions.

Instead of the acceptor thread doing it when reusing the session, have the
worker threads clean it out before putting it on the free list.

It could be, and probably was, argued that this is a performance
pessimization, but having thought much about it, I can't spot the
argument any longer, and certainly moving load off the acceptor thread
to the massively parallel worker threads is a good idea.



Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2009-05-11 09:25:12 UTC (rev 4070)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2009-05-11 09:48:55 UTC (rev 4071)
@@ -108,13 +108,17 @@
 	need_test = 0;
 }
 
+/*--------------------------------------------------------------------
+ * Called once the workerthread gets hold of the session, to do setup
+ * setup overhead, we don't want to bother the acceptor thread with.
+ */
+
 void
 VCA_Prep(struct sess *sp)
 {
 	char addr[TCP_ADDRBUFSIZE];
 	char port[TCP_PORTBUFSIZE];
 
-
 	TCP_name(sp->sockaddr, sp->sockaddrlen,
 	    addr, sizeof addr, port, sizeof port);
 	sp->addr = WS_Dup(sp->ws, addr);

Modified: trunk/varnish-cache/bin/varnishd/cache_session.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_session.c	2009-05-11 09:25:12 UTC (rev 4070)
+++ trunk/varnish-cache/bin/varnishd/cache_session.c	2009-05-11 09:48:55 UTC (rev 4071)
@@ -122,6 +122,8 @@
 		sm = malloc(sizeof *sm + u);
 		if (sm == NULL)
 			return (NULL);
+		/* Don't waste time zeroing the workspace */
+		memset(sm, 0, sizeof *sm);
 		sm->magic = SESSMEM_MAGIC;
 		sm->workspace = u;
 		VSL_stats->n_sess_mem++;
@@ -129,7 +131,6 @@
 	CHECK_OBJ_NOTNULL(sm, SESSMEM_MAGIC);
 	VSL_stats->n_sess++;
 	sp = &sm->sess;
-	memset(sp, 0, sizeof *sp);
 	sp->magic = SESS_MAGIC;
 	sp->mem = sm;
 	sp->sockaddr = (void*)(&sm->sockaddr[0]);
@@ -201,6 +202,7 @@
 {
 	struct acct *b = &sp->acct;
 	struct sessmem *sm;
+	unsigned workspace;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	sm = sp->mem;
@@ -219,6 +221,12 @@
 		VSL_stats->n_sess_mem--;
 		free(sm);
 	} else {
+		/* Clean and prepare for reuse */
+		workspace = sm->workspace;
+		memset(sm, 0, sizeof *sm);
+		sm->magic = SESSMEM_MAGIC;
+		sm->workspace = workspace;
+
 		Lck_Lock(&ses_mem_mtx);
 		VTAILQ_INSERT_HEAD(&ses_free_mem[1 - ses_qp], sm, list);
 		Lck_Unlock(&ses_mem_mtx);



More information about the varnish-commit mailing list