]> err.no Git - varnish/commitdiff
Move a bunch of work from the acceptor thread to the worker thread
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 6 Sep 2006 21:41:13 +0000 (21:41 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 6 Sep 2006 21:41:13 +0000 (21:41 +0000)
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
varnish-cache/bin/varnishd/cache_acceptor.c
varnish-cache/bin/varnishd/cache_center.c
varnish-cache/bin/varnishd/cache_main.c

index 753967adf771105fde4f7e5dfcc742bd847e31c9..aa4e501744d932ef816795ff34cd14ef1495edfa 100644 (file)
@@ -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);
index 078fb360d4435d8065fb9a2ff8fb9aeb7bb6fdf4..7504d52e976f5747f4deca082af20e08d16f57c8 100644 (file)
@@ -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];
index 86064f947cd042f82e34e743bb95f9ba62f95419..0416342f8e7711d91c3b2939c4739c1618fc6f3e 100644 (file)
@@ -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();
+}
index f33edb4ab2032cb18371140336a497d0033b5734..3200f0cbc2fc0f7a8e53d7255d284bd794abc094 100644 (file)
@@ -25,6 +25,7 @@ child_main(void)
        setbuf(stderr, NULL);
        printf("Child starts\n");
 
+       CNT_Init();
        VCL_Init();
 
        HTTP_Init();