r932 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Wed Sep 6 23:41:13 CEST 2006


Author: phk
Date: 2006-09-06 23:41:13 +0200 (Wed, 06 Sep 2006)
New Revision: 932

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_acceptor.c
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_main.c
Log:
Move a bunch of work from the acceptor thread to the worker thread
for better scaling.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-09-06 21:15:26 UTC (rev 931)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-09-06 21:41:13 UTC (rev 932)
@@ -299,6 +299,7 @@
 /* cache_acceptor.c */
 void vca_return_session(struct sess *sp);
 void vca_close_session(struct sess *sp, const char *why);
+void VCA_Prep(struct sess *sp);
 void VCA_Init(void);
 
 /* cache_backend.c */
@@ -315,6 +316,7 @@
 
 /* cache_center.c [CNT] */
 void CNT_Session(struct sess *sp);
+void CNT_Init(void);
 
 /* cache_cli.c [CLI] */
 void CLI_Init(void);

Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2006-09-06 21:15:26 UTC (rev 931)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2006-09-06 21:41:13 UTC (rev 932)
@@ -41,7 +41,6 @@
 
 static struct acceptor *vca_act;
 
-static unsigned		xids;
 static pthread_t 	vca_thread_acct;
 
 static struct sess *
@@ -51,7 +50,6 @@
 	struct sockaddr addr[2];	/* XXX: IPv6 hack */
 	struct sess *sp;
 	int i;
-	struct linger linger;
 
 	VSL_stats->client_conn++;
 
@@ -65,11 +63,22 @@
 	sp = SES_New(addr, l);
 	XXXAN(sp);
 
-	(void)clock_gettime(CLOCK_REALTIME, &sp->t_open);
-	sp->acct.first = sp->t_open.tv_sec;
 	sp->fd = i;
 	sp->id = i;
+	(void)clock_gettime(CLOCK_REALTIME, &sp->t_open);
 
+	return (sp);
+}
+
+void
+VCA_Prep(struct sess *sp)
+{
+	struct linger linger;
+
+	TCP_name(sp->sockaddr, sp->sockaddrlen,
+	    sp->addr, sizeof sp->addr, sp->port, sizeof sp->port);
+	VSL(SLT_SessionOpen, sp->fd, "%s %s", sp->addr, sp->port);
+	sp->acct.first = sp->t_open.tv_sec;
 #ifdef SO_LINGER /* XXX Linux*/
 	linger.l_onoff = 0;
 	linger.l_linger = 0;
@@ -93,10 +102,6 @@
 	AZ(setsockopt(sp->fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv));
 	}
 #endif
-
-	TCP_name(addr, l, sp->addr, sizeof sp->addr, sp->port, sizeof sp->port);
-	VSL(SLT_SessionOpen, sp->fd, "%s %s", sp->addr, sp->port);
-	return (sp);
 }
 
 void
@@ -111,8 +116,6 @@
 	}
 	sp->step = STP_RECV;
 	VSL_stats->client_req++;
-	sp->xid = xids++;
-	VSL(SLT_ReqStart, sp->fd, "XID %u", sp->xid);
 	WRK_QueueSession(sp);
 }
 
@@ -181,8 +184,6 @@
 		http_RecvPrep(sp->http);
 		sp->step = STP_FIRST;
 		VSL_stats->client_req++;
-		sp->xid = xids++;
-		VSL(SLT_ReqStart, sp->fd, "XID %u", sp->xid);
 		WRK_QueueSession(sp);
 	}
 }
@@ -194,8 +195,6 @@
 VCA_Init(void)
 {
 
-	srandomdev();
-	xids = random();
 
 	/* XXX: Add selector mechanism at some point */
 	vca_act = vca_acceptors[0];

Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2006-09-06 21:15:26 UTC (rev 931)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2006-09-06 21:41:13 UTC (rev 932)
@@ -38,6 +38,7 @@
 #include "vcl.h"
 #include "cache.h"
 
+static unsigned xids;
 
 /*--------------------------------------------------------------------
  * We have a refcounted object on the session, now deliver it.
@@ -238,6 +239,7 @@
 {
 	int i;
 
+	VCA_Prep(sp);
 	for (;;) {
 		i = http_RecvSome(sp->fd, sp->http);
 		switch (i) {
@@ -590,6 +592,8 @@
 	int done;
 
 	clock_gettime(CLOCK_REALTIME, &sp->t_req);
+	sp->xid = ++xids;
+	VSL(SLT_ReqStart, sp->fd, "XID %u", sp->xid);
 
 	AZ(sp->vcl);
 	sp->vcl = VCL_Get();
@@ -684,3 +688,11 @@
 /*
 DOT }
 */
+
+void
+CNT_Init(void)
+{
+
+	srandomdev();
+	xids = random();
+}

Modified: trunk/varnish-cache/bin/varnishd/cache_main.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_main.c	2006-09-06 21:15:26 UTC (rev 931)
+++ trunk/varnish-cache/bin/varnishd/cache_main.c	2006-09-06 21:41:13 UTC (rev 932)
@@ -25,6 +25,7 @@
 	setbuf(stderr, NULL);
 	printf("Child starts\n");
 
+	CNT_Init();
 	VCL_Init();
 
 	HTTP_Init();




More information about the varnish-commit mailing list