Commit d3badb52 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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).




git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2642 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 61366214
......@@ -150,7 +150,7 @@ VBE_TryConnect(const struct sess *sp, const struct addrinfo *ai)
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 @@ VBE_TryConnect(const struct sess *sp, const struct addrinfo *ai)
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);
......
......@@ -140,6 +140,9 @@ struct params {
/* Cache vbe_conns */
unsigned cache_vbe_conns;
/* Default connection_timeout */
unsigned connect_timeout;
/* CLI buffer size */
unsigned cli_buffer;
......
......@@ -639,6 +639,14 @@ static const struct parspec parspec[] = {
"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 "
......
......@@ -49,6 +49,7 @@ struct vrt_backend {
const char *hostname;
const char *vcl_name;
const char *ident;
double connect_timeout;
};
/*
......
......@@ -223,7 +223,7 @@ vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *qual, i
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 @@ vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *qual, i
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;
......
......@@ -403,6 +403,7 @@ vcl_output_lang_h(struct vsb *sb)
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");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment