r865 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Mon Aug 21 13:18:26 CEST 2006


Author: phk
Date: 2006-08-21 13:18:26 +0200 (Mon, 21 Aug 2006)
New Revision: 865

Modified:
   trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c
Log:
Split the accepting and session-herding functionality into two threads,
this is totally free from a locking point of view, but will cost
in context switches.



Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c	2006-08-21 11:11:02 UTC (rev 864)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c	2006-08-21 11:18:26 UTC (rev 865)
@@ -28,9 +28,12 @@
 #include "cache.h"
 #include "cache_acceptor.h"
 
-static pthread_t vca_kqueue_thread;
+static pthread_t vca_kqueue_thread1;
+static pthread_t vca_kqueue_thread2;
 static int kq = -1;
 
+#define NKEV	100
+
 static void
 vca_kq_sess(struct sess *sp, int arm)
 {
@@ -64,17 +67,6 @@
 	int i;
 	struct sess *sp;
 
-	if (kp->udata == vca_accept_sess) {
-		while (kp->data-- > 0) {
-			sp = vca_accept_sess(kp->ident);
-			if (sp == NULL)
-				return (NULL);
-			clock_gettime(CLOCK_MONOTONIC, &sp->t_idle);
-			http_RecvPrep(sp->http);
-			vca_kq_sess(sp, EV_ADD);
-		}
-		return (NULL);
-	}
 	if (kp->udata == NULL) {
 		VSL(SLT_Debug, 0,
 		    "KQ RACE %s flags %x fflags %x data %x",
@@ -125,10 +117,8 @@
 }
 
 
-#define NKEV	100
-
 static void *
-vca_main(void *arg)
+vca_kqueue_main(void *arg)
 {
 	struct kevent ke[NKEV], *kp;
 	int i, j, n;
@@ -139,12 +129,6 @@
 	kq = kqueue();
 	assert(kq >= 0);
 
-
-	assert(heritage.socket >= 0);
-	EV_SET(&ke[0], heritage.socket,
-	    EVFILT_READ, EV_ADD, 0, 0, vca_accept_sess);
-	AZ(kevent(kq, &ke[0], 1, NULL, 0, NULL));
-
 	while (1) {
 		n = kevent(kq, NULL, 0, ke, NKEV, NULL);
 		assert(n >= 1 && n <= NKEV);
@@ -162,6 +146,22 @@
 	INCOMPL();
 }
 
+static void *
+vca_kqueue_acct(void *arg)
+{
+	struct sess *sp;
+
+	(void)arg;
+	while (1) {
+		sp = vca_accept_sess(heritage.socket);
+		if (sp == NULL)
+			continue;
+		clock_gettime(CLOCK_MONOTONIC, &sp->t_idle);
+		http_RecvPrep(sp->http);
+		vca_kq_sess(sp, EV_ADD);
+	}
+}
+
 /*--------------------------------------------------------------------*/
 
 static void
@@ -183,7 +183,8 @@
 static void
 vca_kqueue_init(void)
 {
-	AZ(pthread_create(&vca_kqueue_thread, NULL, vca_main, NULL));
+	AZ(pthread_create(&vca_kqueue_thread1, NULL, vca_kqueue_main, NULL));
+	AZ(pthread_create(&vca_kqueue_thread2, NULL, vca_kqueue_acct, NULL));
 }
 
 struct acceptor acceptor_kqueue = {




More information about the varnish-commit mailing list