From eb43c98588b566e6c8d9c7c3008403cfe80ef643 Mon Sep 17 00:00:00 2001 From: phk Date: Mon, 21 Aug 2006 11:18:26 +0000 Subject: [PATCH] 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. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@865 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- .../bin/varnishd/cache_acceptor_kqueue.c | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c b/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c index 4be68271..488ec416 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c +++ b/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c @@ -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 @@ vca_kev(struct kevent *kp) 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 @@ vca_kev(struct kevent *kp) } -#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 @@ vca_main(void *arg) 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 @@ vca_main(void *arg) 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 @@ vca_kqueue_recycle(struct sess *sp) 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 = { -- 2.39.5