r2663 - in trunk/varnish-cache: bin/varnishd include

phk at projects.linpro.no phk at projects.linpro.no
Wed Jun 11 23:12:26 CEST 2008


Author: phk
Date: 2008-06-11 23:12:26 +0200 (Wed, 11 Jun 2008)
New Revision: 2663

Modified:
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/heritage.h
   trunk/varnish-cache/bin/varnishd/mgt_param.c
   trunk/varnish-cache/include/stat_field.h
Log:
Add an optional shortcut:

The parameter session_linger determines how many milliseconds the
workerthread waits to see if another request has arrived, before
handing the session over to the session herder.

If we manage to catch the next request this way, we save a number
of semi-expensive steps, if we hang around too long, the worker-thread
gets to goof off.

A relatively small sample of data from a live server, indicates
that 20% of all requests arrive within 50 msec of the previous
request and 50% within 100msec.

It is not clear at present how these timeintervals relate to client
RTT, or if they are systematically too high, due to the duration
of the detour over the herder.

There is a new line in varnishstat keeping track of how many times
this gamble succeeds.

Experimentation is encouraged.




Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2008-06-11 20:50:55 UTC (rev 2662)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2008-06-11 21:12:26 UTC (rev 2663)
@@ -61,6 +61,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include <math.h>
+#include <poll.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -198,6 +199,7 @@
 cnt_done(struct sess *sp)
 {
 	double dh, dp, da;
+	struct pollfd pfd[1];
 	int i;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
@@ -267,6 +269,17 @@
 		sp->step = STP_AGAIN;
 		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_herd++;
 	SES_Charge(sp);
 	assert(!isnan(sp->wrk->used));

Modified: trunk/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/heritage.h	2008-06-11 20:50:55 UTC (rev 2662)
+++ trunk/varnish-cache/bin/varnishd/heritage.h	2008-06-11 21:12:26 UTC (rev 2663)
@@ -148,6 +148,9 @@
 	/* Default connection_timeout */
 	unsigned		connect_timeout;
 
+	/* How long to linger on sessions */
+	unsigned		session_linger;
+
 	/* CLI buffer size */
 	unsigned		cli_buffer;
 

Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_param.c	2008-06-11 20:50:55 UTC (rev 2662)
+++ trunk/varnish-cache/bin/varnishd/mgt_param.c	2008-06-11 21:12:26 UTC (rev 2663)
@@ -718,6 +718,18 @@
 		"VCL can override this default value for each backend.",
 		0,
 		"400", "ms" },
+	{ "session_linger", tweak_uint,
+		&master.session_linger,0, UINT_MAX,
+		"How long time the workerthread lingers on the session "
+		"to see if a new request appears right away.\n"
+		"If sessions are reused, as much as half of all reuses "
+		"happen within the first 100 msec of the previous request "
+		"completing.\n"
+		"Setting this too high results in worker threads not doing "
+		"anything for their keep, setting it too low just means that "
+		"more sessions take a detour around the acceptor.",
+		EXPERIMENTAL,
+		"0", "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/include/stat_field.h
===================================================================
--- trunk/varnish-cache/include/stat_field.h	2008-06-11 20:50:55 UTC (rev 2662)
+++ trunk/varnish-cache/include/stat_field.h	2008-06-11 21:12:26 UTC (rev 2663)
@@ -85,6 +85,7 @@
 MAC_STAT(sess_closed,		uint64_t, 'a', "Session Closed")
 MAC_STAT(sess_pipeline,		uint64_t, 'a', "Session Pipeline")
 MAC_STAT(sess_readahead,	uint64_t, 'a', "Session Read Ahead")
+MAC_STAT(sess_linger,		uint64_t, 'a', "Session Linger")
 MAC_STAT(sess_herd,		uint64_t, 'a', "Session herd")
 
 MAC_STAT(shm_records,		uint64_t, 'a', "SHM records")




More information about the varnish-commit mailing list