Mailing List Archive

r2642 - in trunk/varnish-cache: bin/varnishd include lib/libvcl
Author: phk
Date: 2008-05-31 00:18:26 +0200 (Sat, 31 May 2008)
New Revision: 2642

Modified:
trunk/varnish-cache/bin/varnishd/cache_backend.c
trunk/varnish-cache/bin/varnishd/heritage.h
trunk/varnish-cache/bin/varnishd/mgt_param.c
trunk/varnish-cache/include/vrt.h
trunk/varnish-cache/lib/libvcl/vcc_backend.c
trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
Log:
Add a new backend attribute in VCL: "connect_timeout".

This is how long time we wait for a TCP connection to the backend to
become established.

Typical usage:

backend b1 {
.host = "hex";
.port = "80";
.connect_timeout = 500 ms;
}

It can also be used in backends in director declarations.

Also add a parameter called "connect_timeout" which sets the default
to 400 msec (a number pulled out of my old black magicians hat).




Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c 2008-05-30 21:39:56 UTC (rev 2641)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2008-05-30 22:18:26 UTC (rev 2642)
@@ -150,7 +150,7 @@
struct sockaddr_storage ss;
int fam, sockt, proto;
socklen_t alen;
- int s;
+ int s, i, tmo;
char abuf1[TCP_ADDRBUFSIZE], abuf2[TCP_ADDRBUFSIZE];
char pbuf1[TCP_PORTBUFSIZE], pbuf2[TCP_PORTBUFSIZE];

@@ -177,7 +177,16 @@
return (s);
}

- if (connect(s, (void *)&ss, alen) != 0) {
+ tmo = params->connect_timeout;
+ if (sp->backend->vrt->connect_timeout > 10e-3)
+ tmo = sp->backend->vrt->connect_timeout * 1000;
+
+ if (tmo > 0)
+ i = TCP_connect(s, (void *)&ss, alen, tmo);
+ else
+ i = connect(s, (void *)&ss, alen);
+
+ if (i != 0) {
AZ(close(s));
LOCK(&sp->backend->mtx);
return (-1);

Modified: trunk/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/heritage.h 2008-05-30 21:39:56 UTC (rev 2641)
+++ trunk/varnish-cache/bin/varnishd/heritage.h 2008-05-30 22:18:26 UTC (rev 2642)
@@ -140,6 +140,9 @@
/* Cache vbe_conns */
unsigned cache_vbe_conns;

+ /* Default connection_timeout */
+ unsigned connect_timeout;
+
/* CLI buffer size */
unsigned cli_buffer;


Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-05-30 21:39:56 UTC (rev 2641)
+++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-05-30 22:18:26 UTC (rev 2642)
@@ -639,6 +639,14 @@
"Cache vbe_conn's or rely on malloc, that's the question.",
EXPERIMENTAL,
"off", "bool" },
+ { "connect_timeout", tweak_uint,
+ &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.",
+ 0,
+ "400", "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/vrt.h
===================================================================
--- trunk/varnish-cache/include/vrt.h 2008-05-30 21:39:56 UTC (rev 2641)
+++ trunk/varnish-cache/include/vrt.h 2008-05-30 22:18:26 UTC (rev 2642)
@@ -49,6 +49,7 @@
const char *hostname;
const char *vcl_name;
const char *ident;
+ double connect_timeout;
};

/*

Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-05-30 21:39:56 UTC (rev 2641)
+++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-05-30 22:18:26 UTC (rev 2642)
@@ -223,7 +223,7 @@
struct host *h;
struct fld_spec *fs;

- fs = vcc_FldSpec(tl, "!host", "?port", NULL);
+ fs = vcc_FldSpec(tl, "!host", "?port", "?connect_timeout", NULL);
t_first = tl->t;

if (tl->t->tok == ID) {
@@ -273,10 +273,16 @@
t_host = tl->t;
vcc_NextToken(tl);
} else if (vcc_IdIs(t_field, "port")) {
- ExpectErr(tl, CSTR);
assert(tl->t->dec != NULL);
t_port = tl->t;
vcc_NextToken(tl);
+ } else if (vcc_IdIs(t_field, "connect_timeout")) {
+ Fh(tl, 0, "\t.connect_timeout = ");
+ tl->fb = tl->fh;
+ vcc_TimeVal(tl);
+ tl->fb = NULL;
+ ERRCHK(tl);
+ Fh(tl, 0, ",\n");
} else {
ErrInternal(tl);
return;

Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-05-30 21:39:56 UTC (rev 2641)
+++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-05-30 22:18:26 UTC (rev 2642)
@@ -403,6 +403,7 @@
vsb_cat(sb, " const char *hostname;\n");
vsb_cat(sb, " const char *vcl_name;\n");
vsb_cat(sb, " const char *ident;\n");
+ vsb_cat(sb, " double connect_timeout;\n");
vsb_cat(sb, "};\n");
vsb_cat(sb, "\n");
vsb_cat(sb, "/*\n");