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

Move the per backend stats counters to "struct backend"



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5089 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent b53d6441
......@@ -455,73 +455,6 @@ VBE_Healthy(double now, const struct director *d, uintptr_t target)
return (d->healthy(now, d, target));
}
/*--------------------------------------------------------------------
* Backend VSC counters
*
* We use a private list, because we do not trust the content of the
* VSM (to hold our refcount).
*
* Backend stats are indexed purely by name, across all VCLs.
*/
struct vbe_cnt {
unsigned magic;
#define CNT_PRIV_MAGIC 0x1acda1f5
VTAILQ_ENTRY(vbe_cnt) list;
char *name;
int refcnt;
struct vsc_vbe *vsc_vbe;
};
static VTAILQ_HEAD(, vbe_cnt) vbe_cnt_head =
VTAILQ_HEAD_INITIALIZER(vbe_cnt_head);
static struct vsc_vbe *
vbe_stat_ref(const char *name)
{
struct vbe_cnt *vc;
ASSERT_CLI();
VTAILQ_FOREACH(vc, &vbe_cnt_head, list) {
if (!strcmp(vc->name, name)) {
vc->refcnt++;
vc->vsc_vbe->vcls = vc->refcnt;
return (vc->vsc_vbe);
}
}
ALLOC_OBJ(vc, CNT_PRIV_MAGIC);
AN(vc);
REPLACE(vc->name, name);
VTAILQ_INSERT_HEAD(&vbe_cnt_head, vc, list);
vc->vsc_vbe = VSM_Alloc(sizeof *vc->vsc_vbe,
VSC_CLASS, VSC_TYPE_VBE, name);
AN(vc->vsc_vbe);
vc->refcnt = 1;
vc->vsc_vbe->vcls = vc->refcnt;
return (vc->vsc_vbe);
}
static void
vbe_stat_deref(const char *name)
{
struct vbe_cnt *vc;
ASSERT_CLI();
VTAILQ_FOREACH(vc, &vbe_cnt_head, list)
if (!strcmp(vc->name, name))
break;
AN(vc);
vc->refcnt--;
vc->vsc_vbe->vcls = vc->refcnt;
if (vc->refcnt > 0)
return;
AZ(vc->refcnt);
VTAILQ_REMOVE(&vbe_cnt_head, vc, list);
VSM_Free(vc->vsc_vbe);
FREE_OBJ(vc);
}
/*--------------------------------------------------------------------
* The "simple" director really isn't, since thats where all the actual
* connections happen. Nontheless, pretend it is simple by sequestering
......@@ -533,7 +466,6 @@ struct vdi_simple {
#define VDI_SIMPLE_MAGIC 0x476d25b7
struct director dir;
struct backend *backend;
struct vsc_vbe *stats;
};
/* Returns the backend if and only if the this is a simple director.
......@@ -593,7 +525,7 @@ vdi_simple_fini(struct director *d)
CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC);
VBE_DropRef(vs->backend);
vbe_stat_deref(vs->dir.vcl_name);
// vbe_stat_deref(vs->dir.vcl_name);
free(vs->dir.vcl_name);
vs->dir.magic = 0;
FREE_OBJ(vs);
......@@ -621,7 +553,6 @@ VRT_init_dir_simple(struct cli *cli, struct director **bp, int idx,
vs->dir.healthy = vdi_simple_healthy;
vs->backend = VBE_AddBackend(cli, t);
vs->stats = vbe_stat_ref(t->vcl_name);
bp[idx] = &vs->dir;
}
......@@ -113,31 +113,34 @@ struct backend {
unsigned magic;
#define BACKEND_MAGIC 0x64c4c7c6
VTAILQ_ENTRY(backend) list;
int refcount;
struct lock mtx;
char *hosthdr;
char *vcl_name;
char *ipv4_addr;
char *ipv6_addr;
char *port;
double connect_timeout;
double first_byte_timeout;
double between_bytes_timeout;
VTAILQ_ENTRY(backend) list;
int refcount;
struct lock mtx;
struct sockaddr *ipv4;
socklen_t ipv4len;
struct sockaddr *ipv6;
socklen_t ipv6len;
unsigned max_conn;
unsigned n_conn;
VTAILQ_HEAD(, vbc) connlist;
struct vbp_target *probe;
unsigned healthy;
VTAILQ_HEAD(, trouble) troublelist;
struct vsc_vbe *vsc;
double connect_timeout;
double first_byte_timeout;
double between_bytes_timeout;
unsigned max_conn;
unsigned saintmode_threshold;
};
......
......@@ -72,6 +72,7 @@ VBE_Nuke(struct backend *b)
free(b->ipv6);
free(b->ipv6_addr);
free(b->port);
VSM_Free(b->vsc);
FREE_OBJ(b);
VSC_main->n_backend--;
}
......@@ -174,6 +175,7 @@ struct backend *
VBE_AddBackend(struct cli *cli, const struct vrt_backend *vb)
{
struct backend *b;
char buf[128];
AN(vb->vcl_name);
assert(vb->ipv4_sockaddr != NULL || vb->ipv6_sockaddr != NULL);
......@@ -203,6 +205,11 @@ VBE_AddBackend(struct cli *cli, const struct vrt_backend *vb)
Lck_New(&b->mtx);
b->refcount = 1;
bprintf(buf, "%s(%s,%s,%s)",
vb->vcl_name, vb->ipv4_addr, vb->ipv6_addr, vb->port);
b->vsc = VSM_Alloc(sizeof *b->vsc, VSC_CLASS, VSC_TYPE_VBE, buf);
VTAILQ_INIT(&b->connlist);
VTAILQ_INIT(&b->troublelist);
......
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