r3616 - in branches/2.0/varnish-cache: bin/varnishd bin/varnishtest/tests include lib/libvarnish lib/libvcl

tfheen at projects.linpro.no tfheen at projects.linpro.no
Thu Feb 5 12:43:21 CET 2009


Author: tfheen
Date: 2009-02-05 12:43:20 +0100 (Thu, 05 Feb 2009)
New Revision: 3616

Added:
   branches/2.0/varnish-cache/bin/varnishtest/tests/b00020.vtc
   branches/2.0/varnish-cache/bin/varnishtest/tests/b00021.vtc
   branches/2.0/varnish-cache/bin/varnishtest/tests/b00022.vtc
   branches/2.0/varnish-cache/bin/varnishtest/tests/b00023.vtc
   branches/2.0/varnish-cache/bin/varnishtest/tests/b00024.vtc
   branches/2.0/varnish-cache/bin/varnishtest/tests/b00025.vtc
   branches/2.0/varnish-cache/bin/varnishtest/tests/b00026.vtc
Modified:
   branches/2.0/varnish-cache/bin/varnishd/cache.h
   branches/2.0/varnish-cache/bin/varnishd/cache_backend.c
   branches/2.0/varnish-cache/bin/varnishd/cache_backend.h
   branches/2.0/varnish-cache/bin/varnishd/cache_backend_cfg.c
   branches/2.0/varnish-cache/bin/varnishd/cache_center.c
   branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c
   branches/2.0/varnish-cache/bin/varnishd/cache_session.c
   branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c
   branches/2.0/varnish-cache/bin/varnishd/heritage.h
   branches/2.0/varnish-cache/bin/varnishd/mgt_param.c
   branches/2.0/varnish-cache/include/libvarnish.h
   branches/2.0/varnish-cache/include/vrt.h
   branches/2.0/varnish-cache/include/vrt_obj.h
   branches/2.0/varnish-cache/lib/libvarnish/tcp.c
   branches/2.0/varnish-cache/lib/libvcl/vcc_backend.c
   branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c
   branches/2.0/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
   branches/2.0/varnish-cache/lib/libvcl/vcc_obj.c
Log:
Merge r3406: Added support for setting read timeouts for backend requests

Added support for setting read timeouts for backend requests
(first_byte_timeout and between_bytes_timeout), in addition to make the
connect_timeout available for the bereq object in vcl_miss and vcl_fetch.

first_byte_timeout is a read timeout from the connection to the backend is
created to when the first byte arrives. It can be set as a parameter to
varnish, as a field in the backend declaration or as bereq.first_byte_timeout
in vcl_miss and vcl_pass.

between_bytes_timeout is a read timeout between each read from the backend. It
can be set as a parameter to varnish, as a field in the backend declaration or
as bereq.between_bytes_timeout in vcl_miss and vcl_pass.

The time unit for these timeout values are seconds. NOTE: The connect_timeout
previously used milliseconds as time unit, so beware.



Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache.h	2009-02-05 11:38:45 UTC (rev 3615)
+++ branches/2.0/varnish-cache/bin/varnishd/cache.h	2009-02-05 11:43:20 UTC (rev 3616)
@@ -337,6 +337,11 @@
 	double			t_resp;
 	double			t_end;
 
+	/* Timeouts */
+	double connect_timeout;
+	double first_byte_timeout;
+	double between_bytes_timeout;
+
 	/* Acceptable grace period */
 	double			grace;
 
@@ -538,6 +543,8 @@
 void SES_Delete(struct sess *sp);
 void SES_RefSrcAddr(struct sess *sp);
 void SES_Charge(struct sess *sp);
+void SES_ResetBackendTimeouts(struct sess *sp);
+void SES_InheritBackendTimeouts(struct sess *sp);
 
 /* cache_shmlog.c */
 void VSL_Init(void);

Modified: branches/2.0/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_backend.c	2009-02-05 11:38:45 UTC (rev 3615)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_backend.c	2009-02-05 11:43:20 UTC (rev 3616)
@@ -95,7 +95,7 @@
 	if (s < 0)
 		return (s);
 
-	tmo = params->connect_timeout;
+	tmo = (int)(sp->connect_timeout * 1000);
 	if (bp->connect_timeout > 10e-3)
 		tmo = (int)(bp->connect_timeout * 1000);
 

Modified: branches/2.0/varnish-cache/bin/varnishd/cache_backend.h
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_backend.h	2009-02-05 11:38:45 UTC (rev 3615)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_backend.h	2009-02-05 11:43:20 UTC (rev 3616)
@@ -104,6 +104,8 @@
 	char			*ident;
 	char			*vcl_name;
 	double			connect_timeout;
+	double			first_byte_timeout;
+	double			between_bytes_timeout;
 
 	uint32_t		hash;
 

Modified: branches/2.0/varnish-cache/bin/varnishd/cache_backend_cfg.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_backend_cfg.c	2009-02-05 11:38:45 UTC (rev 3615)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_backend_cfg.c	2009-02-05 11:43:20 UTC (rev 3616)
@@ -222,6 +222,8 @@
 	REPLACE(b->hosthdr, vb->hosthdr);
 
 	b->connect_timeout = vb->connect_timeout;
+	b->first_byte_timeout = vb->first_byte_timeout;
+	b->between_bytes_timeout = vb->between_bytes_timeout;
 	b->max_conn = vb->max_connections;
 
 	/*

Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_center.c	2009-02-05 11:38:45 UTC (rev 3615)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_center.c	2009-02-05 11:43:20 UTC (rev 3616)
@@ -845,6 +845,8 @@
 	CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC);
 	AZ(sp->obj);
 
+	SES_ResetBackendTimeouts(sp);
+
 	/* By default we use the first backend */
 	AZ(sp->director);
 	sp->director = sp->vcl->director[0];

Modified: branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c	2009-02-05 11:38:45 UTC (rev 3615)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c	2009-02-05 11:43:20 UTC (rev 3616)
@@ -336,6 +336,8 @@
 	if (sp->vbe == NULL)
 		return (__LINE__);
 	vc = sp->vbe;
+	/* Inherit the backend timeouts from the selected backend */
+	SES_InheritBackendTimeouts(sp);
 
 	/*
 	 * Now that we know our backend, we can set a default Host:
@@ -369,8 +371,11 @@
 	VSL_stats->backend_req++;
 
 	HTC_Init(htc, bereq->ws, vc->fd);
-	do
+	TCP_set_read_timeout(vc->fd, sp->first_byte_timeout);
+	do {
 		i = HTC_Rx(htc);
+		TCP_set_read_timeout(vc->fd, sp->between_bytes_timeout);
+	}
 	while (i == 0);
 
 	if (i < 0) {

Modified: branches/2.0/varnish-cache/bin/varnishd/cache_session.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_session.c	2009-02-05 11:38:45 UTC (rev 3615)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_session.c	2009-02-05 11:43:20 UTC (rev 3616)
@@ -58,6 +58,7 @@
 
 #include "shmlog.h"
 #include "cache.h"
+#include "cache_backend.h"
 
 /*--------------------------------------------------------------------*/
 
@@ -316,6 +317,8 @@
 	sp->http = &sm->http[0];
 	sp->http0 = &sm->http[1];
 
+	SES_ResetBackendTimeouts(sp);
+
 	return (sp);
 }
 
@@ -367,3 +370,38 @@
 	Lck_New(&stat_mtx);
 	Lck_New(&ses_mem_mtx);
 }
+
+void
+SES_ResetBackendTimeouts(struct sess *sp)
+{
+	sp->connect_timeout = params->connect_timeout;
+	sp->first_byte_timeout = params->first_byte_timeout;
+	sp->between_bytes_timeout = params->between_bytes_timeout;
+}
+
+void
+SES_InheritBackendTimeouts(struct sess *sp)
+{
+	struct backend *be = NULL;
+
+	AN(sp);
+	AN(sp->vbe);
+	AN(sp->vbe->backend);
+
+	be = sp->vbe->backend;
+	/* 
+	 * We only inherit the backend's timeout if the session timeout
+	 * has not already been set in the VCL, as the order of precedence
+	 * is parameter < backend definition < VCL.
+	 */
+	if (be->connect_timeout > 1e-3 && 
+			sp->connect_timeout == params->connect_timeout)
+		sp->connect_timeout = be->connect_timeout;
+	if (be->first_byte_timeout > 1e-3 && 
+			sp->first_byte_timeout == params->first_byte_timeout)
+		sp->first_byte_timeout = be->first_byte_timeout;
+	if (be->between_bytes_timeout > 1e-3 
+			&& sp->between_bytes_timeout == params->between_bytes_timeout)
+		sp->between_bytes_timeout = be->between_bytes_timeout;
+}
+

Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c	2009-02-05 11:38:45 UTC (rev 3615)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c	2009-02-05 11:43:20 UTC (rev 3616)
@@ -299,6 +299,48 @@
 	return (atoi(sp->http->hd[HTTP_HDR_STATUS].b));
 }
 
+void
+VRT_l_bereq_connect_timeout(struct sess *sp, double num)
+{
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	sp->connect_timeout = (num > 0 ? num : 0);
+}
+
+double
+VRT_r_bereq_connect_timeout(struct sess *sp)
+{
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	return sp->connect_timeout;
+}
+
+void
+VRT_l_bereq_first_byte_timeout(struct sess *sp, double num)
+{
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	sp->first_byte_timeout = (num > 0 ? num : 0);
+}
+
+double
+VRT_r_bereq_first_byte_timeout(struct sess *sp)
+{
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	return sp->first_byte_timeout;
+}
+
+void
+VRT_l_bereq_between_bytes_timeout(struct sess *sp, double num)
+{
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	sp->between_bytes_timeout = (num > 0 ? num : 0);
+}
+
+double
+VRT_r_bereq_between_bytes_timeout(struct sess *sp)
+{
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	return sp->between_bytes_timeout;
+}
+
 /*--------------------------------------------------------------------*/
 
 void

Modified: branches/2.0/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/heritage.h	2009-02-05 11:38:45 UTC (rev 3615)
+++ branches/2.0/varnish-cache/bin/varnishd/heritage.h	2009-02-05 11:43:20 UTC (rev 3616)
@@ -154,8 +154,12 @@
 	unsigned		cache_vbe_conns;
 
 	/* Default connection_timeout */
-	unsigned		connect_timeout;
+	double			connect_timeout;
 
+	/* Read timeouts for backend */
+	double			first_byte_timeout;
+	double	 		between_bytes_timeout;
+
 	/* How long to linger on sessions */
 	unsigned		session_linger;
 

Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c	2009-02-05 11:38:45 UTC (rev 3615)
+++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c	2009-02-05 11:43:20 UTC (rev 3616)
@@ -97,6 +97,24 @@
 		cli_out(cli, "%u", *dst);
 }
 
+static void
+tweak_generic_timeout_double(struct cli *cli, volatile double *dst, const char *arg)
+{
+	double u;
+
+	if (arg != NULL) {
+		u = strtod(arg, NULL);
+		if (u < 0) {
+			cli_out(cli, "Timeout must be greater or equal to zero\n");
+			cli_result(cli, CLIS_PARAM);
+			return;
+		}
+		*dst = u;
+	} else
+		cli_out(cli, "%f", *dst);
+}
+
+
 /*--------------------------------------------------------------------*/
 
 static void
@@ -108,7 +126,14 @@
 	tweak_generic_timeout(cli, dest, arg);
 }
 
+static void
+tweak_timeout_double(struct cli *cli, const struct parspec *par, const char *arg)
+{
+	volatile double *dest;
 
+	dest = par->priv;
+	tweak_generic_timeout_double(cli, dest, arg);
+}
 /*--------------------------------------------------------------------*/
 
 static void
@@ -746,14 +771,31 @@
 		"Cache vbe_conn's or rely on malloc, that's the question.",
 		EXPERIMENTAL,
 		"off", "bool" },
-	{ "connect_timeout", tweak_uint,
+	{ "connect_timeout", tweak_timeout_double,
 		&master.connect_timeout,0, UINT_MAX,
 		"Default connection timeout for backend connections.  "
 		"We only try to connect to the backend for this many "
-		"milliseconds before giving up.  "
-		"VCL can override this default value for each backend.",
+		"seconds before giving up. "
+		"VCL can override this default value for each backend. "
+		"This does not apply to pipe. ",
 		0,
-		"400", "ms" },
+		"0.4", "s" },
+	{ "first_byte_timeout", tweak_timeout_double,
+		&master.first_byte_timeout,0, UINT_MAX,
+		"Default timeout for receiving first byte from backend. "
+		"We only wait for this many seconds for the first "
+		"byte before giving up. A value of 0 means it will never time out. "
+		"VCL can override this default value for each backend request.",
+		0,
+		"60", "s" },
+	{ "between_bytes_timeout", tweak_timeout_double,
+		&master.between_bytes_timeout,0, UINT_MAX,
+		"Default timeout between bytes when receiving data from backend. "
+		"We only wait for this many seconds between bytes "
+		"before giving up. A value of 0 means it will never time out. "
+		"VCL can override this default value for each backend request.",
+		0,
+		"60", "s" },
 	{ "accept_fd_holdoff", tweak_timeout,
 		&master.accept_fd_holdoff, 0,  3600*1000,
 		"If we run out of file descriptors, the accept thread will "

Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/b00020.vtc (from rev 3406, trunk/varnish-cache/bin/varnishtest/tests/b00020.vtc)
===================================================================
--- branches/2.0/varnish-cache/bin/varnishtest/tests/b00020.vtc	                        (rev 0)
+++ branches/2.0/varnish-cache/bin/varnishtest/tests/b00020.vtc	2009-02-05 11:43:20 UTC (rev 3616)
@@ -0,0 +1,34 @@
+# $Id: b00019.vtc 3300 2008-10-15 09:52:15Z tfheen $
+
+test "Check the between_bytes_timeout behaves from parameters"
+
+server s1 {
+	rxreq
+	send "HTTP/1.1 200 Ok\r\nConnection: close\r\n\r\n"
+	delay 1.5
+	send "Baba\n"
+} -start
+
+varnish v1 -vcl+backend {} -start
+varnish v1 -cliok "param.set between_bytes_timeout 1"
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.status == 503
+} -run
+
+server s1 {
+	rxreq
+	send "HTTP/1.1 200 Ok\r\nConnection: close\r\n\r\n"
+	delay 0.5
+	send "Baba\n"
+	delay 0.5
+	send "Baba\n"
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.status == 200
+} -run

Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/b00021.vtc (from rev 3406, trunk/varnish-cache/bin/varnishtest/tests/b00021.vtc)
===================================================================
--- branches/2.0/varnish-cache/bin/varnishtest/tests/b00021.vtc	                        (rev 0)
+++ branches/2.0/varnish-cache/bin/varnishtest/tests/b00021.vtc	2009-02-05 11:43:20 UTC (rev 3616)
@@ -0,0 +1,37 @@
+# $Id: b00019.vtc 3300 2008-10-15 09:52:15Z tfheen $
+
+test "Check the between_bytes_timeout behaves from vcl"
+
+server s1 {
+	rxreq
+	send "HTTP/1.1 200 Ok\r\nConnection: close\r\n\r\n"
+	delay 1.5
+	send "Baba\n"
+} -start
+
+varnish v1 -vcl+backend {
+	sub vcl_miss {
+		set bereq.between_bytes_timeout = 1s;
+	}
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.status == 503
+} -run
+
+server s1 {
+	rxreq
+	send "HTTP/1.1 200 Ok\r\nConnection: close\r\n\r\n"
+	delay 0.5
+	send "Baba\n"
+	delay 0.5
+	send "Baba\n"
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.status == 200
+} -run

Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/b00022.vtc (from rev 3406, trunk/varnish-cache/bin/varnishtest/tests/b00022.vtc)
===================================================================
--- branches/2.0/varnish-cache/bin/varnishtest/tests/b00022.vtc	                        (rev 0)
+++ branches/2.0/varnish-cache/bin/varnishtest/tests/b00022.vtc	2009-02-05 11:43:20 UTC (rev 3616)
@@ -0,0 +1,39 @@
+# $Id: b00019.vtc 3300 2008-10-15 09:52:15Z tfheen $
+
+test "Check the between_bytes_timeout behaves from backend definition"
+
+server s1 {
+	rxreq
+	send "HTTP/1.1 200 Ok\r\nConnection: close\r\n\r\n"
+	delay 1.5
+	send "Baba\n"
+} -start
+
+varnish v1 -vcl {
+	backend b1 {
+		.host = "127.0.0.1";
+		.port = "9080";
+		.between_bytes_timeout = 1s;
+	}
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.status == 503
+} -run
+
+server s1 {
+	rxreq
+	send "HTTP/1.1 200 Ok\r\nConnection: close\r\n\r\n"
+	delay 0.5
+	send "Baba\n"
+	delay 0.5
+	send "Baba\n"
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.status == 200
+} -run

Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/b00023.vtc (from rev 3406, trunk/varnish-cache/bin/varnishtest/tests/b00023.vtc)
===================================================================
--- branches/2.0/varnish-cache/bin/varnishtest/tests/b00023.vtc	                        (rev 0)
+++ branches/2.0/varnish-cache/bin/varnishtest/tests/b00023.vtc	2009-02-05 11:43:20 UTC (rev 3616)
@@ -0,0 +1,31 @@
+# $Id: b00019.vtc 3300 2008-10-15 09:52:15Z tfheen $
+
+test "Check that the first_byte_timeout works from parameters"
+
+server s1 {
+	rxreq
+	delay 1.5
+	txresp
+} -start
+
+varnish v1 -vcl+backend {} -start
+varnish v1 -cliok "param.set first_byte_timeout 1"
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.status == 503
+} -run
+
+
+server s1 {
+	rxreq
+	delay 0.5
+	txresp
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.status == 200
+} -run

Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/b00024.vtc (from rev 3406, trunk/varnish-cache/bin/varnishtest/tests/b00024.vtc)
===================================================================
--- branches/2.0/varnish-cache/bin/varnishtest/tests/b00024.vtc	                        (rev 0)
+++ branches/2.0/varnish-cache/bin/varnishtest/tests/b00024.vtc	2009-02-05 11:43:20 UTC (rev 3616)
@@ -0,0 +1,34 @@
+# $Id: b00019.vtc 3300 2008-10-15 09:52:15Z tfheen $
+
+test "Check that the first_byte_timeout works from vcl"
+
+server s1 {
+	rxreq
+	delay 1.5
+	txresp
+} -start
+
+varnish v1 -vcl+backend {
+	sub vcl_miss {
+		set bereq.first_byte_timeout = 1s;	
+	}
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.status == 503
+} -run
+
+
+server s1 {
+	rxreq
+	delay 0.5
+	txresp
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.status == 200
+} -run

Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/b00025.vtc (from rev 3406, trunk/varnish-cache/bin/varnishtest/tests/b00025.vtc)
===================================================================
--- branches/2.0/varnish-cache/bin/varnishtest/tests/b00025.vtc	                        (rev 0)
+++ branches/2.0/varnish-cache/bin/varnishtest/tests/b00025.vtc	2009-02-05 11:43:20 UTC (rev 3616)
@@ -0,0 +1,36 @@
+# $Id: b00019.vtc 3300 2008-10-15 09:52:15Z tfheen $
+
+test "Check that the first_byte_timeout works from backend definition"
+
+server s1 {
+	rxreq
+	delay 1.5
+	txresp
+} -start
+
+varnish v1 -vcl {
+	backend b1 {
+		.host = "127.0.0.1";
+		.port = "9080";
+		.first_byte_timeout = 1s;
+	}
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.status == 503
+} -run
+
+
+server s1 {
+	rxreq
+	delay 0.5
+	txresp
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.status == 200
+} -run

Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/b00026.vtc (from rev 3406, trunk/varnish-cache/bin/varnishtest/tests/b00026.vtc)
===================================================================
--- branches/2.0/varnish-cache/bin/varnishtest/tests/b00026.vtc	                        (rev 0)
+++ branches/2.0/varnish-cache/bin/varnishtest/tests/b00026.vtc	2009-02-05 11:43:20 UTC (rev 3616)
@@ -0,0 +1,50 @@
+# $Id: b00019.vtc 3300 2008-10-15 09:52:15Z tfheen $
+
+test "Check the precedence for timeouts"
+
+server s1 -listen 127.0.0.1:9080 {
+	rxreq
+	expect req.url == "from_backend"
+	delay 1; 
+	txresp
+} -start
+server s2 -listen 127.0.0.1:9180 {
+	rxreq
+	expect req.url == "from_vcl"
+	delay 1.5;
+	txresp
+} -start
+
+varnish v1 -vcl {
+	backend b1 {
+		.host = "127.0.0.1";
+		.port = "9080";
+		.first_byte_timeout = 2s;
+	}
+	backend b2 {
+		.host = "127.0.0.1";
+		.port = "9180";
+		.first_byte_timeout = 1s;
+	}
+
+	sub vcl_recv {
+		if (req.url  == "from_backend") {
+			set req.backend = b1;
+			pass;
+		}
+		set req.backend = b2;
+	}
+	sub vcl_miss {
+		set bereq.first_byte_timeout = 2s;
+	}
+} -start
+varnish v1 -cliok "param.set first_byte_timeout 0.5"
+
+client c1 {
+	txreq -url "from_backend"
+	rxresp
+	expect resp.status == 200
+	txreq -url "from_vcl"
+	rxresp
+	expect resp.status == 200
+} -run

Modified: branches/2.0/varnish-cache/include/libvarnish.h
===================================================================
--- branches/2.0/varnish-cache/include/libvarnish.h	2009-02-05 11:38:45 UTC (rev 3615)
+++ branches/2.0/varnish-cache/include/libvarnish.h	2009-02-05 11:43:20 UTC (rev 3616)
@@ -65,6 +65,7 @@
 int TCP_connect(int s, const struct sockaddr *name, socklen_t namelen,
     int msec);
 void TCP_close(int *s);
+void TCP_set_read_timeout(int socket, double seconds);
 #endif
 
 /* from libvarnish/time.c */

Modified: branches/2.0/varnish-cache/include/vrt.h
===================================================================
--- branches/2.0/varnish-cache/include/vrt.h	2009-02-05 11:38:45 UTC (rev 3615)
+++ branches/2.0/varnish-cache/include/vrt.h	2009-02-05 11:43:20 UTC (rev 3616)
@@ -69,6 +69,8 @@
 	const unsigned char		*ipv6_sockaddr;
 
 	double				connect_timeout;
+	double				first_byte_timeout;
+	double				between_bytes_timeout;
 	unsigned			max_connections;
 	struct vrt_backend_probe	probe;
 };

Modified: branches/2.0/varnish-cache/include/vrt_obj.h
===================================================================
--- branches/2.0/varnish-cache/include/vrt_obj.h	2009-02-05 11:38:45 UTC (rev 3615)
+++ branches/2.0/varnish-cache/include/vrt_obj.h	2009-02-05 11:43:20 UTC (rev 3616)
@@ -28,6 +28,12 @@
 void VRT_l_bereq_url(const struct sess *, const char *, ...);
 const char * VRT_r_bereq_proto(const struct sess *);
 void VRT_l_bereq_proto(const struct sess *, const char *, ...);
+double VRT_r_bereq_connect_timeout(struct sess *);
+void VRT_l_bereq_connect_timeout(struct sess *, double);
+double VRT_r_bereq_first_byte_timeout(struct sess *);
+void VRT_l_bereq_first_byte_timeout(struct sess *, double);
+double VRT_r_bereq_between_bytes_timeout(struct sess *);
+void VRT_l_bereq_between_bytes_timeout(struct sess *, double);
 const char * VRT_r_obj_proto(const struct sess *);
 void VRT_l_obj_proto(const struct sess *, const char *, ...);
 int VRT_r_obj_status(const struct sess *);

Modified: branches/2.0/varnish-cache/lib/libvarnish/tcp.c
===================================================================
--- branches/2.0/varnish-cache/lib/libvarnish/tcp.c	2009-02-05 11:38:45 UTC (rev 3615)
+++ branches/2.0/varnish-cache/lib/libvarnish/tcp.c	2009-02-05 11:43:20 UTC (rev 3616)
@@ -47,6 +47,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <math.h>
 
 #include "config.h"
 #ifndef HAVE_STRLCPY
@@ -210,3 +211,14 @@
 	    errno == ENOTCONN);
 	*s = -1;
 }
+
+void
+TCP_set_read_timeout(int s, double seconds)
+{
+	struct timeval timeout;
+	timeout.tv_sec = floor(seconds);
+	timeout.tv_usec = 1e6 * (seconds - timeout.tv_sec);
+#ifdef SO_RCVTIMEO_WORKS
+	AZ(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof timeout));
+#endif
+}

Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_backend.c
===================================================================
--- branches/2.0/varnish-cache/lib/libvcl/vcc_backend.c	2009-02-05 11:38:45 UTC (rev 3615)
+++ branches/2.0/varnish-cache/lib/libvcl/vcc_backend.c	2009-02-05 11:43:20 UTC (rev 3616)
@@ -473,6 +473,8 @@
 	    "?port",
 	    "?host_header",
 	    "?connect_timeout",
+	    "?first_byte_timeout",
+	    "?between_bytes_timeout",
 	    "?probe",
 	    "?max_connections",
 	    NULL);
@@ -537,6 +539,20 @@
 			Fb(tl, 0, ",\n");
 			ExpectErr(tl, ';');
 			vcc_NextToken(tl);
+		} else if (vcc_IdIs(t_field, "first_byte_timeout")) {
+			Fb(tl, 0, "\t.first_byte_timeout = ");
+			vcc_TimeVal(tl);
+			ERRCHK(tl);
+			Fb(tl, 0, ",\n");
+			ExpectErr(tl, ';');
+			vcc_NextToken(tl);
+		} else if (vcc_IdIs(t_field, "between_bytes_timeout")) {
+			Fb(tl, 0, "\t.between_bytes_timeout = ");
+			vcc_TimeVal(tl);
+			ERRCHK(tl);
+			Fb(tl, 0, ",\n");
+			ExpectErr(tl, ';');
+			vcc_NextToken(tl);
 		} else if (vcc_IdIs(t_field, "max_connections")) {
 			u = vcc_UintVal(tl);
 			vcc_NextToken(tl);

Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c	2009-02-05 11:38:45 UTC (rev 3615)
+++ branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c	2009-02-05 11:43:20 UTC (rev 3616)
@@ -243,6 +243,8 @@
 	vsb_cat(sb, "\tconst unsigned char\t\t*ipv4_sockaddr;\n");
 	vsb_cat(sb, "\tconst unsigned char\t\t*ipv6_sockaddr;\n");
 	vsb_cat(sb, "\n\tdouble\t\t\t\tconnect_timeout;\n");
+	vsb_cat(sb, "\tdouble\t\t\t\tfirst_byte_timeout;\n");
+	vsb_cat(sb, "\tdouble\t\t\t\tbetween_bytes_timeout;\n");
 	vsb_cat(sb, "\tunsigned\t\t\tmax_connections;\n");
 	vsb_cat(sb, "\tstruct vrt_backend_probe\tprobe;\n");
 	vsb_cat(sb, "};\n\n/*\n * A director with a predictable reply\n");
@@ -309,9 +311,9 @@
 
 	/* ../../include/vrt_obj.h */
 
-	vsb_cat(sb, "/*\n * $Id: vcc_gen_obj.tcl 3580 2009-02-05 08:45:25Z ");
-	vsb_cat(sb, "tfheen $\n *\n * NB:  This file is machine generated, ");
-	vsb_cat(sb, "DO NOT EDIT!\n *\n * Edit vcc_gen_obj.tcl instead\n");
+	vsb_cat(sb, "/*\n * $Id: vrt_obj.h 3169 2008-09-08 09:49:01Z tfheen");
+	vsb_cat(sb, " $\n *\n * NB:  This file is machine generated, DO NOT");
+	vsb_cat(sb, " EDIT!\n *\n * Edit vcc_gen_obj.tcl instead\n");
 	vsb_cat(sb, " */\n\nstruct sockaddr * VRT_r_client_ip(const struct ");
 	vsb_cat(sb, "sess *);\nstruct sockaddr * VRT_r_server_ip(struct ses");
 	vsb_cat(sb, "s *);\nint VRT_r_server_port(struct sess *);\n");
@@ -335,9 +337,16 @@
 	vsb_cat(sb, " const char *, ...);\nconst char * VRT_r_bereq_proto(c");
 	vsb_cat(sb, "onst struct sess *);\nvoid VRT_l_bereq_proto(const str");
 	vsb_cat(sb, "uct sess *, const char *, ...);\n");
-	vsb_cat(sb, "const char * VRT_r_obj_proto(const struct sess *);\n");
-	vsb_cat(sb, "void VRT_l_obj_proto(const struct sess *, const char *");
-	vsb_cat(sb, ", ...);\nint VRT_r_obj_status(const struct sess *);\n");
+	vsb_cat(sb, "double VRT_r_bereq_connect_timeout(struct sess *);\n");
+	vsb_cat(sb, "void VRT_l_bereq_connect_timeout(struct sess *, double");
+	vsb_cat(sb, ");\ndouble VRT_r_bereq_first_byte_timeout(struct sess ");
+	vsb_cat(sb, "*);\nvoid VRT_l_bereq_first_byte_timeout(struct sess *");
+	vsb_cat(sb, ", double);\ndouble VRT_r_bereq_between_bytes_timeout(s");
+	vsb_cat(sb, "truct sess *);\nvoid VRT_l_bereq_between_bytes_timeout");
+	vsb_cat(sb, "(struct sess *, double);\nconst char * VRT_r_obj_proto");
+	vsb_cat(sb, "(const struct sess *);\nvoid VRT_l_obj_proto(const str");
+	vsb_cat(sb, "uct sess *, const char *, ...);\n");
+	vsb_cat(sb, "int VRT_r_obj_status(const struct sess *);\n");
 	vsb_cat(sb, "void VRT_l_obj_status(const struct sess *, int);\n");
 	vsb_cat(sb, "const char * VRT_r_obj_response(const struct sess *);\n");
 	vsb_cat(sb, "void VRT_l_obj_response(const struct sess *, const cha");

Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
===================================================================
--- branches/2.0/varnish-cache/lib/libvcl/vcc_gen_obj.tcl	2009-02-05 11:38:45 UTC (rev 3615)
+++ branches/2.0/varnish-cache/lib/libvcl/vcc_gen_obj.tcl	2009-02-05 11:43:20 UTC (rev 3616)
@@ -127,6 +127,21 @@
 	{     pipe pass      miss     fetch                        }
 	"const struct sess *"
     }
+    { bereq.connect_timeout
+	RW TIME
+	{     pass      miss     }
+	"struct sess *"
+    }
+    { bereq.first_byte_timeout
+	RW TIME
+	{     pass      miss     }
+	"struct sess *"
+    }
+    { bereq.between_bytes_timeout
+	RW TIME
+	{     pass      miss     }
+	"struct sess *"
+    }
 
     # The (possibly) cached object
     { obj.proto

Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_obj.c
===================================================================
--- branches/2.0/varnish-cache/lib/libvcl/vcc_obj.c	2009-02-05 11:38:45 UTC (rev 3615)
+++ branches/2.0/varnish-cache/lib/libvcl/vcc_obj.c	2009-02-05 11:43:20 UTC (rev 3616)
@@ -108,6 +108,21 @@
 	    V_RW,	    "HDR_BEREQ",
 	    VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_MISS | VCL_MET_FETCH
 	},
+	{ "bereq.connect_timeout", TIME, 21,
+	    "VRT_r_bereq_connect_timeout(sp)",	    "VRT_l_bereq_connect_timeout(sp, ",
+	    V_RW,	    0,
+	    VCL_MET_PASS | VCL_MET_MISS
+	},
+	{ "bereq.first_byte_timeout", TIME, 24,
+	    "VRT_r_bereq_first_byte_timeout(sp)",	    "VRT_l_bereq_first_byte_timeout(sp, ",
+	    V_RW,	    0,
+	    VCL_MET_PASS | VCL_MET_MISS
+	},
+	{ "bereq.between_bytes_timeout", TIME, 27,
+	    "VRT_r_bereq_between_bytes_timeout(sp)",	    "VRT_l_bereq_between_bytes_timeout(sp, ",
+	    V_RW,	    0,
+	    VCL_MET_PASS | VCL_MET_MISS
+	},
 	{ "obj.proto", STRING, 9,
 	    "VRT_r_obj_proto(sp)",	    "VRT_l_obj_proto(sp, ",
 	    V_RW,	    0,



More information about the varnish-commit mailing list