Mailing List Archive

r982 - trunk/varnish-cache/bin/varnishd
Author: phk
Date: 2006-09-15 09:37:20 +0200 (Fri, 15 Sep 2006)
New Revision: 982

Modified:
trunk/varnish-cache/bin/varnishd/cache_acceptor.c
trunk/varnish-cache/bin/varnishd/cache_center.c
trunk/varnish-cache/bin/varnishd/steps.h
Log:
If after handling a request we find anything in our input buffer,
don't waste time putting the session on the herder, but go right
back and take the next request in the current worker thread.



Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2006-09-15 07:14:37 UTC (rev 981)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2006-09-15 07:37:20 UTC (rev 982)
@@ -158,14 +158,6 @@
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
AZ(sp->obj);
AZ(sp->vcl);
- if (sp->fd >= 0) {
- VSL(SLT_SessionReuse, sp->fd, "%s %s", sp->addr, sp->port);
- sp->t_open = sp->t_end;
- if (http_RecvPrepAgain(sp->http)) {
- vca_handover(sp, 0);
- return;
- }
- }
vca_act->recycle(sp);
}


Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c 2006-09-15 07:14:37 UTC (rev 981)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c 2006-09-15 07:37:20 UTC (rev 982)
@@ -41,6 +41,39 @@
static unsigned xids;

/*--------------------------------------------------------------------
+ * The very first request
+ */
+static int
+cnt_again(struct sess *sp)
+{
+ int i;
+
+ assert(sp->xid == 0);
+ sp->wrk->idle = sp->t_open.tv_sec;
+
+ if (http_RecvPrepAgain(sp->http)) {
+ sp->step = STP_RECV;
+ return (0);
+ }
+ do
+ i = http_RecvSome(sp->fd, sp->http);
+ while (i == -1);
+ if (i == 0) {
+ sp->step = STP_RECV;
+ return (0);
+ }
+ if (i == 1)
+ vca_close_session(sp, "overflow");
+ else if (i == 2)
+ vca_close_session(sp, "no request");
+ else
+ INCOMPL();
+ sp->step = STP_DONE;
+ return (0);
+}
+
+
+/*--------------------------------------------------------------------
* We have a refcounted object on the session, now deliver it.
*
DOT subgraph cluster_deliver {
@@ -120,6 +153,23 @@
(long)sp->t_end.tv_sec, (long)sp->t_end.tv_nsec,
dh, dp, da);

+ sp->xid = 0;
+ sp->t_open = sp->t_end;
+ if (sp->fd > 0) {
+ VSL(SLT_SessionReuse, sp->fd, "%s %s", sp->addr, sp->port);
+
+ /* If we have anything in the input buffer, start over */
+ /*
+ * XXX: we might even want to do a short timed read (poll)
+ * XXX: here to see if something is pending in the kernel
+ */
+
+ if (sp->http->t < sp->http->v) {
+ sp->step = STP_AGAIN;
+ return (0);
+ }
+ }
+
SES_Charge(sp);
vca_return_session(sp);
return (1);

Modified: trunk/varnish-cache/bin/varnishd/steps.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/steps.h 2006-09-15 07:14:37 UTC (rev 981)
+++ trunk/varnish-cache/bin/varnishd/steps.h 2006-09-15 07:37:20 UTC (rev 982)
@@ -1,5 +1,6 @@
/* $Id$ */

+STEP(again, AGAIN)
STEP(first, FIRST)
STEP(recv, RECV)
STEP(pipe, PIPE)
r982 - trunk/varnish-cache/bin/varnishd [ In reply to ]
phk at projects.linpro.no writes:
> If after handling a request we find anything in our input buffer,
> don't waste time putting the session on the herder, but go right
> back and take the next request in the current worker thread.

This should reduce lock contention under high load, shouldn't it?

DES
--
Dag-Erling Sm?rgrav
Senior Software Developer
Linpro AS - www.linpro.no
r982 - trunk/varnish-cache/bin/varnishd [ In reply to ]
In message <ujr3battvhg.fsf at cat.linpro.no>, Dag-Erling =?iso-8859-1?Q?Sm=F8rgra
v?= writes:
>phk at projects.linpro.no writes:
>> If after handling a request we find anything in our input buffer,
>> don't waste time putting the session on the herder, but go right
>> back and take the next request in the current worker thread.
>
>This should reduce lock contention under high load, shouldn't it?

I think the bigger saving is context switches, basically a void
a write, a read and a context switch for any session which
pipelines. This is mostly Opera at this point in time.

I'm considering putting in a .1 second timed read there to give
the other browsers a chance as well.

--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.