From b25098008d3921da1ea5a0e268c841fd98a8801a Mon Sep 17 00:00:00 2001 From: phk Date: Wed, 6 Sep 2006 21:41:13 +0000 Subject: [PATCH] Move a bunch of work from the acceptor thread to the worker thread for better scaling. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@932 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 2 ++ varnish-cache/bin/varnishd/cache_acceptor.c | 27 ++++++++++----------- varnish-cache/bin/varnishd/cache_center.c | 12 +++++++++ varnish-cache/bin/varnishd/cache_main.c | 1 + 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 753967ad..aa4e5017 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -299,6 +299,7 @@ struct backend { /* 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 @@ int BAN_CheckObject(struct object *o, const char *url); /* cache_center.c [CNT] */ void CNT_Session(struct sess *sp); +void CNT_Init(void); /* cache_cli.c [CLI] */ void CLI_Init(void); diff --git a/varnish-cache/bin/varnishd/cache_acceptor.c b/varnish-cache/bin/varnishd/cache_acceptor.c index 078fb360..7504d52e 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor.c +++ b/varnish-cache/bin/varnishd/cache_acceptor.c @@ -41,7 +41,6 @@ static struct acceptor *vca_acceptors[] = { static struct acceptor *vca_act; -static unsigned xids; static pthread_t vca_thread_acct; static struct sess * @@ -51,7 +50,6 @@ vca_accept_sess(int fd) struct sockaddr addr[2]; /* XXX: IPv6 hack */ struct sess *sp; int i; - struct linger linger; VSL_stats->client_conn++; @@ -65,11 +63,22 @@ vca_accept_sess(int fd) 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 @@ vca_accept_sess(int fd) 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 @@ vca_handover(struct sess *sp, int bad) } 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 @@ vca_acct(void *arg) 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 @@ void VCA_Init(void) { - srandomdev(); - xids = random(); /* XXX: Add selector mechanism at some point */ vca_act = vca_acceptors[0]; diff --git a/varnish-cache/bin/varnishd/cache_center.c b/varnish-cache/bin/varnishd/cache_center.c index 86064f94..0416342f 100644 --- a/varnish-cache/bin/varnishd/cache_center.c +++ b/varnish-cache/bin/varnishd/cache_center.c @@ -38,6 +38,7 @@ DOT start -> RECV #include "vcl.h" #include "cache.h" +static unsigned xids; /*-------------------------------------------------------------------- * We have a refcounted object on the session, now deliver it. @@ -238,6 +239,7 @@ cnt_first(struct sess *sp) { int i; + VCA_Prep(sp); for (;;) { i = http_RecvSome(sp->fd, sp->http); switch (i) { @@ -590,6 +592,8 @@ cnt_recv(struct sess *sp) 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 @@ CNT_Session(struct sess *sp) /* DOT } */ + +void +CNT_Init(void) +{ + + srandomdev(); + xids = random(); +} diff --git a/varnish-cache/bin/varnishd/cache_main.c b/varnish-cache/bin/varnishd/cache_main.c index f33edb4a..3200f0cb 100644 --- a/varnish-cache/bin/varnishd/cache_main.c +++ b/varnish-cache/bin/varnishd/cache_main.c @@ -25,6 +25,7 @@ child_main(void) setbuf(stderr, NULL); printf("Child starts\n"); + CNT_Init(); VCL_Init(); HTTP_Init(); -- 2.39.5