r4283 - branches/2.0/varnish-cache/bin/varnishd

tfheen at projects.linpro.no tfheen at projects.linpro.no
Thu Oct 8 12:13:28 CEST 2009


Author: tfheen
Date: 2009-10-08 12:13:28 +0200 (Thu, 08 Oct 2009)
New Revision: 4283

Modified:
   branches/2.0/varnish-cache/bin/varnishd/cache_acceptor.c
   branches/2.0/varnish-cache/bin/varnishd/cache_center.c
   branches/2.0/varnish-cache/bin/varnishd/cache_httpconn.c
   branches/2.0/varnish-cache/bin/varnishd/mgt_param.c
   branches/2.0/varnish-cache/bin/varnishd/steps.h
Log:
Merge r4079, r4080: Make session_linger the default with 50msec timeout.

Change the session handling logic, so that we hand any session back to
the herder, if the session_linger timer fires.

This means that a new session, will get a worker thread, but if
nothing happens within session_linger, it disembarks and lets the
herder handle the assembly of the request.

This actually simplifies the state engine, because the "again" state
(now renamed "wait) can also be used both for the first request.


Modified: branches/2.0/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_acceptor.c	2009-10-08 09:38:45 UTC (rev 4282)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_acceptor.c	2009-10-08 10:13:28 UTC (rev 4283)
@@ -253,6 +253,7 @@
 			sp->fd = i;
 			sp->id = i;
 			sp->t_open = now;
+			sp->t_end = now;
 			sp->mylsock = ls;
 
 			sp->step = STP_FIRST;

Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_center.c	2009-10-08 09:38:45 UTC (rev 4282)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_center.c	2009-10-08 10:13:28 UTC (rev 4283)
@@ -80,17 +80,15 @@
 static unsigned xids;
 
 /*--------------------------------------------------------------------
- * AGAIN
- * We come here when we just completed a request and already have
- * received (part of) the next one.  Instead taking the detour
- * around the acceptor and then back to a worker, just stay in this
- * worker and do what it takes.
+ * WAIT
+ * Wait until we have a full request in our htc.
  */
 
 static int
-cnt_again(struct sess *sp)
+cnt_wait(struct sess *sp)
 {
 	int i;
+	struct pollfd pfd[1];
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	AZ(sp->vcl);
@@ -98,12 +96,32 @@
 	assert(sp->xid == 0);
 
 	i = HTC_Complete(sp->htc);
-	while (i == 0)
+	while (i == 0) {
+		if (params->session_linger > 0) {
+			pfd[0].fd = sp->fd;
+			pfd[0].events = POLLIN;
+			pfd[0].revents = 0;
+			i = poll(pfd, 1, params->session_linger);
+			if (i == 0) {
+				WSL(sp->wrk, SLT_Debug, sp->fd, "herding");
+				VSL_stats->sess_herd++;
+				sp->wrk = NULL;
+				vca_return_session(sp);
+				return (1);
+			}
+		}
 		i = HTC_Rx(sp->htc);
+	}
 	if (i == 1) {
 		sp->step = STP_START;
 	} else {
-		vca_close_session(sp, "overflow");
+		if (i == -2)
+			vca_close_session(sp, "overflow");
+		else if (i == -1 && Tlen(sp->htc->rxbuf) == 0 &&
+		    (errno == 0 || errno == ECONNRESET))
+			vca_close_session(sp, "EOF");
+		else 
+			vca_close_session(sp, "error");
 		sp->step = STP_DONE;
 	}
 	return (0);
@@ -198,7 +216,6 @@
 cnt_done(struct sess *sp)
 {
 	double dh, dp, da;
-	struct pollfd pfd[1];
 	int i;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
@@ -267,19 +284,13 @@
 	}
 	if (Tlen(sp->htc->rxbuf)) {
 		VSL_stats->sess_readahead++;
-		sp->step = STP_AGAIN;
+		sp->step = STP_WAIT;
 		return (0);
 	}
 	if (params->session_linger > 0) {
-		pfd[0].fd = sp->fd;
-		pfd[0].events = POLLIN;
-		pfd[0].revents = 0;
-		i = poll(pfd, 1, params->session_linger);
-		if (i > 0) {
-			VSL_stats->sess_linger++;
-			sp->step = STP_AGAIN;
-			return (0);
-		}
+		VSL_stats->sess_linger++;
+		sp->step = STP_WAIT;
+		return (0);
 	}
 	VSL_stats->sess_herd++;
 	SES_Charge(sp);
@@ -459,7 +470,6 @@
 static int
 cnt_first(struct sess *sp)
 {
-	int i;
 
 	/*
 	 * XXX: If we don't have acceptfilters we are somewhat subject
@@ -480,25 +490,8 @@
 	sp->wrk->lastused = sp->t_open;
 	sp->acct_req.sess++;
 	SES_RefSrcAddr(sp);
-	do
-		i = HTC_Rx(sp->htc);
-	while (i == 0);
 
-	switch (i) {
-	case 1:
-		sp->step = STP_START;
-		break;
-	case -1:
-		vca_close_session(sp, "error");
-		sp->step = STP_DONE;
-		break;
-	case -2:
-		vca_close_session(sp, "blast");
-		sp->step = STP_DONE;
-		break;
-	default:
-		WRONG("Illegal return from HTC_Rx");
-	}
+	sp->step = STP_WAIT;
 	return (0);
 }
 

Modified: branches/2.0/varnish-cache/bin/varnishd/cache_httpconn.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_httpconn.c	2009-10-08 09:38:45 UTC (rev 4282)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_httpconn.c	2009-10-08 10:13:28 UTC (rev 4283)
@@ -92,6 +92,7 @@
 	(void)WS_Reserve(htc->ws, (htc->ws->e - htc->ws->s) / 2);
 	htc->rxbuf.b = ws->f;
 	htc->rxbuf.e = ws->f;
+	*htc->rxbuf.e = '\0';
 	htc->pipeline.b = NULL;
 	htc->pipeline.e = NULL;
 }

Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c	2009-10-08 09:38:45 UTC (rev 4282)
+++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c	2009-10-08 10:13:28 UTC (rev 4283)
@@ -712,7 +712,7 @@
 		"anything for their keep, setting it too low just means that "
 		"more sessions take a detour around the acceptor.",
 		EXPERIMENTAL,
-		"0", "ms" },
+		"50", "ms" },
 	{ "cli_buffer", tweak_uint, &master.cli_buffer, 4096, UINT_MAX,
 		"Size of buffer for CLI input."
 		"\nYou may need to increase this if you have big VCL files "

Modified: branches/2.0/varnish-cache/bin/varnishd/steps.h
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/steps.h	2009-10-08 09:38:45 UTC (rev 4282)
+++ branches/2.0/varnish-cache/bin/varnishd/steps.h	2009-10-08 10:13:28 UTC (rev 4283)
@@ -29,7 +29,7 @@
  * $Id$
  */
 
-STEP(again,	AGAIN)
+STEP(wait,	WAIT)
 STEP(first,	FIRST)
 STEP(recv,	RECV)
 STEP(start,	START)



More information about the varnish-commit mailing list