r4079 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Thu May 14 14:13:00 CEST 2009


Author: phk
Date: 2009-05-14 14:13:00 +0200 (Thu, 14 May 2009)
New Revision: 4079

Modified:
   trunk/varnish-cache/bin/varnishd/cache_acceptor.c
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_httpconn.c
   trunk/varnish-cache/bin/varnishd/mgt_param.c
   trunk/varnish-cache/bin/varnishd/steps.h
Log:
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: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2009-05-14 11:38:17 UTC (rev 4078)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2009-05-14 12:13:00 UTC (rev 4079)
@@ -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: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2009-05-14 11:38:17 UTC (rev 4078)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2009-05-14 12:13:00 UTC (rev 4079)
@@ -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);
@@ -201,7 +219,6 @@
 cnt_done(struct sess *sp)
 {
 	double dh, dp, da;
-	struct pollfd pfd[1];
 	int i;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
@@ -269,19 +286,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);
@@ -590,7 +601,6 @@
 static int
 cnt_first(struct sess *sp)
 {
-	int i;
 
 	/*
 	 * XXX: If we don't have acceptfilters we are somewhat subject
@@ -610,25 +620,8 @@
 	HTC_Init(sp->htc, sp->ws, sp->fd);
 	sp->wrk->lastused = sp->t_open;
 	sp->acct_req.sess++;
-	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: trunk/varnish-cache/bin/varnishd/cache_httpconn.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_httpconn.c	2009-05-14 11:38:17 UTC (rev 4078)
+++ trunk/varnish-cache/bin/varnishd/cache_httpconn.c	2009-05-14 12:13:00 UTC (rev 4079)
@@ -93,6 +93,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: trunk/varnish-cache/bin/varnishd/mgt_param.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_param.c	2009-05-14 11:38:17 UTC (rev 4078)
+++ trunk/varnish-cache/bin/varnishd/mgt_param.c	2009-05-14 12:13:00 UTC (rev 4079)
@@ -696,7 +696,7 @@
 		"anything for their keep, setting it too low just means that "
 		"more sessions take a detour around the waiter.",
 		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: trunk/varnish-cache/bin/varnishd/steps.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/steps.h	2009-05-14 11:38:17 UTC (rev 4078)
+++ trunk/varnish-cache/bin/varnishd/steps.h	2009-05-14 12:13:00 UTC (rev 4079)
@@ -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