Commit 1873136b authored by Kristian Lyngstøl's avatar Kristian Lyngstøl

Add saintmode_threshold to backend definitions

git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4336 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 774fe5f7
......@@ -35,6 +35,7 @@
#include "svnid.h"
SVNID("$Id$")
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -245,15 +246,23 @@ backend_is_healthy(const struct sess *sp, struct backend *backend)
struct trouble *tr2;
struct trouble *old = NULL;
unsigned i = 0;
unsigned int threshold;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(backend, BACKEND_MAGIC);
if (!backend->healthy)
return 0;
/* VRT/VCC sets threshold to UINT_MAX to mark that it's not
* specified by VCL (thus use param).
*/
if (backend->saintmode_threshold == UINT_MAX)
threshold = params->saintmode_threshold;
else
threshold = backend->saintmode_threshold;
/* Saintmode is disabled */
if (params->saintmode_threshold == 0)
if (threshold == 0)
return 1;
/* No need to test if we don't have an object head to test against.
......@@ -280,7 +289,7 @@ backend_is_healthy(const struct sess *sp, struct backend *backend)
* will disable the backend. Since 0 is disable, ++i
* instead of i++ to allow this behavior.
*/
if (++i >= params->saintmode_threshold) {
if (++i >=threshold) {
Lck_Unlock(&backend->mtx);
return 0;
}
......
......@@ -137,6 +137,7 @@ struct backend {
struct vbp_target *probe;
unsigned healthy;
VTAILQ_HEAD(, trouble) troublelist;
unsigned saintmode_threshold;
};
/* cache_backend.c */
......
......@@ -240,6 +240,7 @@ VBE_AddBackend(struct cli *cli, const struct vrt_backend *vb)
b->first_byte_timeout = vb->first_byte_timeout;
b->between_bytes_timeout = vb->between_bytes_timeout;
b->max_conn = vb->max_connections;
b->saintmode_threshold = vb->saintmode_threshold;
/*
* Copy over the sockaddrs
......
# $Id$
test "Test that saintmode_threshold in VCL"
server s1 {
rxreq
txresp
rxreq
txresp
rxreq
txresp
rxreq
txresp
rxreq
txresp -hdr "X-Saint: yes"
rxreq
txresp -hdr "X-Saint: yes"
rxreq
txresp -hdr "X-Saint: yes"
rxreq
txresp -hdr "X-Saint: yes"
} -start
varnish v1 -arg "-p saintmode_threshold=10" -vcl {
backend foo {
.host = "127.0.0.1";
.port = "9080";
.saintmode_threshold = 2;
}
sub vcl_recv {
set req.backend = foo;
set req.grace = 1h;
}
sub vcl_fetch {
if (beresp.http.X-Saint == "yes") {
set beresp.saintmode = 20s;
restart;
}
set beresp.grace = 1h;
set beresp.ttl = 1s;
}
sub vcl_deliver {
set resp.http.X-Restarts = req.restarts;
}
} -start
client c1 {
txreq -url "/one"
rxresp
expect resp.status == 200
expect resp.http.X-Saint != "yes"
expect resp.http.X-Restarts == "0"
txreq -url "/two"
rxresp
expect resp.status == 200
expect resp.http.X-Saint != "yes"
expect resp.http.X-Restarts == "0"
txreq -url "/three"
rxresp
expect resp.status == 200
expect resp.http.X-Saint != "yes"
expect resp.http.X-Restarts == "0"
txreq -url "/four"
rxresp
expect resp.status == 200
expect resp.http.X-Saint != "yes"
expect resp.http.X-Restarts == "0"
delay 2
txreq -url "/one"
rxresp
expect resp.status == 200
expect resp.http.X-Saint != "yes"
expect resp.http.X-Restarts == "1"
txreq -url "/two"
rxresp
expect resp.status == 200
expect resp.http.X-Saint != "yes"
expect resp.http.X-Restarts == "1"
txreq -url "/three"
rxresp
expect resp.status == 200
expect resp.http.X-Saint != "yes"
expect resp.http.X-Restarts == "0"
txreq -url "/four"
rxresp
expect resp.status == 200
expect resp.http.X-Saint != "yes"
expect resp.http.X-Restarts == "0"
} -run
......@@ -73,6 +73,7 @@ struct vrt_backend {
double first_byte_timeout;
double between_bytes_timeout;
unsigned max_connections;
unsigned saintmode_threshold;
struct vrt_backend_probe probe;
};
......
......@@ -56,6 +56,7 @@ SVNID("$Id$")
#include <sys/types.h>
#include <sys/socket.h>
#include <limits.h>
#include <netdb.h>
#include <stdio.h>
#include <stdarg.h>
......@@ -476,6 +477,7 @@ vcc_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name,
struct token *t_host = NULL;
struct token *t_port = NULL;
struct token *t_hosthdr = NULL;
unsigned saint = UINT_MAX;
const char *ep;
struct fld_spec *fs;
struct vsb *vsb;
......@@ -490,6 +492,7 @@ vcc_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name,
"?between_bytes_timeout",
"?probe",
"?max_connections",
"?saintmode_threshold",
NULL);
t_first = tl->t;
......@@ -573,6 +576,22 @@ vcc_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name,
ExpectErr(tl, ';');
vcc_NextToken(tl);
Fb(tl, 0, "\t.max_connections = %u,\n", u);
} else if (vcc_IdIs(t_field, "saintmode_threshold")) {
u = vcc_UintVal(tl);
/* UINT_MAX == magic number to mark as unset, so
* not allowed here.
*/
if (u == UINT_MAX) {
vsb_printf(tl->sb, "Value outside allowed range: ");
vcc_ErrToken(tl, tl->t);
vsb_printf(tl->sb, " at\n");
vcc_ErrWhere(tl, tl->t);
}
vcc_NextToken(tl);
ERRCHK(tl);
saint = u;
ExpectErr(tl, ';');
vcc_NextToken(tl);
} else if (vcc_IdIs(t_field, "probe")) {
vcc_ParseProbe(tl);
ERRCHK(tl);
......@@ -623,6 +642,8 @@ vcc_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name,
EncToken(tl->fb, t_host);
Fb(tl, 0, ",\n");
Fb(tl, 0, "\t.saintmode_threshold = %d,\n",saint);
/* Close the struct */
Fb(tl, 0, "};\n");
......
......@@ -251,6 +251,7 @@ vcl_output_lang_h(struct vsb *sb)
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, "\tunsigned\t\t\tsaintmode_threshold;\n");
vsb_cat(sb, "\tstruct vrt_backend_probe\tprobe;\n");
vsb_cat(sb, "};\n\n/*\n * A director with a predictable reply\n");
vsb_cat(sb, " */\n\nstruct vrt_dir_simple {\n");
......
......@@ -120,6 +120,14 @@ backend www {
.between_bytes_timeout = 2s;
}
.Ed
.Pp
To stop using a backend after number of items have been added to it's
saintmode list
.Fa .saintmode_threshold
can be set to the maximum list size. Setting a value of 0 disables
saintmode checking entirely for that backend. The value in the backend
declaration overrides the parameter.
.Ss Directors
Directors choose from different backends based on health status and a
per-director algorithm.
......
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