so we have to add our own stuff for that.
Without some kind of TTL, we would hit the DNS server once per failed
attempt to connect to the backend.
If the backend were down, we could hit it a LOT.
In the VCL code:
backend foobar {
[...]
set backend.dnsttl = 20s;
}
will assign a TTL for DNS lookups of this backends hostname+port
combination, we will not hit the DNS server more often that this.
The default is set at 30 seconds, short enough to make things are
workable in a load-balancing-via-DNS setups, yet long enough to not
pound the DNS server flat in case of backend failures.
NOTE that as long as we succeed in connecting to the backend we
do not perform new DNS lookups. That will have to be revisited
along with possible load-balancing schemes for the backend(s).
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1237
d4fa192b-c00b-0410-8231-
f00ffab90ce4
struct addrinfo *last_addr;
TAILQ_HEAD(,vbe_conn) connlist;
+
+ double dnsttl;
+ double dnstime;
#if 0
double responsetime;
double timeout;
static MTX vbemtx;
+/*--------------------------------------------------------------------*/
+/* XXX: belongs a more general place */
+
+static double
+Uptime(void)
+{
+ struct timespec ts;
+
+ assert(clock_gettime(CLOCK_MONOTONIC, &ts) == 0);
+ return (ts.tv_sec + ts.tv_nsec * 1e-9);
+}
+
/*--------------------------------------------------------------------*/
static struct vbe_conn *
vbe_new_conn(void)
{
struct vbe_conn *vbc;
- unsigned char *p, space;
+ unsigned char *p;
+ unsigned space;
space = params->mem_workspace;
vbc = calloc(sizeof *vbc + space * 2, 1);
if (bp->addr != NULL) {
freeaddrinfo(bp->addr);
bp->addr = NULL;
+ bp->last_addr = NULL;
}
memset(&hint, 0, sizeof hint);
error = getaddrinfo(bp->hostname,
bp->portname == NULL ? "http" : bp->portname,
&hint, &res);
+ bp->dnstime = Uptime();
if (error) {
if (res != NULL)
freeaddrinfo(res);
printf("getaddrinfo: %s\n", gai_strerror(error)); /* XXX */
- bp->addr = NULL;
return;
}
+ bp->last_addr = res;
bp->addr = res;
}
int s;
s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
- if (s < 0)
- return (s);
- else if (connect(s, ai->ai_addr, ai->ai_addrlen)) {
+ if (s >= 0 && connect(s, ai->ai_addr, ai->ai_addrlen)) {
AZ(close(s));
s = -1;
}
}
}
+ if (bp->dnstime + bp->dnsttl >= Uptime())
+ return (-1);
+
/* Then do another lookup to catch DNS changes */
vbe_lookup(bp);
cp->backend[i] = calloc(sizeof *cp->backend[i], 1);
XXXAN(cp->backend[i]);
cp->backend[i]->magic = BACKEND_MAGIC;
+ cp->backend[i]->dnsttl = 30;
TAILQ_INIT(&cp->backend[i]->connlist);
}
}
VBACKEND(const char *, host, hostname)
VBACKEND(const char *, port, portname)
+VBACKEND(double, dnsttl, dnsttl)
/*--------------------------------------------------------------------
* XXX: Working relative to t_req is maybe not the right thing, we could
void VRT_l_backend_host(struct backend *, const char *);
const char * VRT_r_backend_port(struct backend *);
void VRT_l_backend_port(struct backend *, const char *);
+double VRT_r_backend_dnsttl(struct backend *);
+void VRT_l_backend_dnsttl(struct backend *, double);
const unsigned char * VRT_r_client_ip(struct sess *);
void VRT_l_client_ip(struct sess *, const unsigned char *);
const char * VRT_r_req_request(struct sess *);
-printf_code( ju, long long unsigned)
-printf_code( jx, long long unsigned)
++libh ../../config.h
-header(../../config.h)
-sem(lbv_assert, r_no)
-sem(strchr, 1p, type(1), 2n == 0 ? (@p < 1p) : (@p < 1p || @p == 0 ))
t->e = strchr(s, '\0');
t->tok = METHOD;
AddRef(tl, t, type);
+ /* XXX: possibly leaking t */
}
void
static void
Backend(struct tokenlist *tl)
{
+ unsigned a;
struct var *vp;
struct token *t_be = NULL;
struct token *t_host = NULL;
Fc(tl, 0, ");\n");
vcc_NextToken(tl);
break;
+#if 0
+ case INT:
+ case SIZE:
+ case RATE:
+ case FLOAT:
+#endif
+ case TIME:
+ Fc(tl, 1, "\t%s ", vp->lname);
+ a = tl->t->tok;
+ if (a == T_MUL || a == T_DIV)
+ Fc(tl, 0, "%g", DoubleVal(tl));
+ else if (vp->fmt == TIME)
+ TimeVal(tl);
+ else if (vp->fmt == SIZE)
+ SizeVal(tl);
+ else if (vp->fmt == RATE)
+ RateVal(tl);
+ else
+ Fc(tl, 0, "%g", DoubleVal(tl));
+ Fc(tl, 0, ");\n");
+ break;
default:
vsb_printf(tl->sb,
"Assignments not possible for '%s'\n", vp->name);
# Objects which operate on backends
set beobj {
- { backend.host HOSTNAME }
- { backend.port PORTNAME }
+ { backend.host HOSTNAME }
+ { backend.port PORTNAME }
+ { backend.dnsttl TIME }
}
# Objects which operate on sessions
set spobj {
- { client.ip IP }
- { req.request STRING }
- { req.host STRING }
- { req.url STRING }
- { req.proto STRING }
- { req.backend BACKEND }
- { obj.valid BOOL }
- { obj.cacheable BOOL }
- { obj.ttl TIME }
- { req.http. HEADER }
- { resp.http. HEADER }
+ { client.ip IP }
+ { req.request STRING }
+ { req.host STRING }
+ { req.url STRING }
+ { req.proto STRING }
+ { req.backend BACKEND }
+ { obj.valid BOOL }
+ { obj.cacheable BOOL }
+ { obj.ttl TIME }
+ { req.http. HEADER }
+ { resp.http. HEADER }
}
set tt(IP) "const unsigned char *"
"VRT_r_backend_port(backend)",
"VRT_l_backend_port(backend, ",
},
+ { "backend.dnsttl", TIME, 14,
+ "VRT_r_backend_dnsttl(backend)",
+ "VRT_l_backend_dnsttl(backend, ",
+ },
{ NULL }
};
"void VRT_l_backend_host(struct backend *, const char *);\n"
"const char * VRT_r_backend_port(struct backend *);\n"
"void VRT_l_backend_port(struct backend *, const char *);\n"
+ "double VRT_r_backend_dnsttl(struct backend *);\n"
+ "void VRT_l_backend_dnsttl(struct backend *, double);\n"
"const unsigned char * VRT_r_client_ip(struct sess *);\n"
"void VRT_l_client_ip(struct sess *, const unsigned char *);\n"
"const char * VRT_r_req_request(struct sess *);\n"