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

An explanatory comment.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4184 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent e9a93108
......@@ -69,6 +69,13 @@ static struct waiter const *vca_act;
pthread_t VCA_thread;
static struct timeval tv_sndtimeo;
static struct timeval tv_rcvtimeo;
/*
* We want to get out of any kind of touble-hit TCP connections as fast
* as absolutely possible, so we set them LINGER enabled with zero timeout,
* so that even if there are outstanding write data on the socket, a close(2)
* will return immediately.
*/
static const struct linger linger = {
.l_onoff = 1,
};
......
......@@ -242,18 +242,85 @@ vbp_poke(struct vbp_target *vt)
}
/*--------------------------------------------------------------------
* One thread per backend to be poked.
* Record pokings...
*/
static void *
vbp_wrk_poll_backend(void *priv)
static void
vbp_start_poke(struct vbp_target *vt)
{
CHECK_OBJ_NOTNULL(vt, VBP_TARGET_MAGIC);
#define BITMAP(n, c, t, b) vt->n <<= 1;
#include "cache_backend_poll.h"
#undef BITMAP
vt->last = 0;
vt->resp_buf[0] = '\0';
}
static void
vbp_has_poked(struct vbp_target *vt)
{
struct vbp_target *vt;
unsigned i, j;
uint64_t u;
const char *logmsg;
char bits[10];
CHECK_OBJ_NOTNULL(vt, VBP_TARGET_MAGIC);
/* Calculate exponential average */
if (vt->happy & 1) {
if (vt->rate < AVG_RATE)
vt->rate += 1.0;
vt->avg += (vt->last - vt->avg) / vt->rate;
}
i = 0;
#define BITMAP(n, c, t, b) bits[i++] = (vt->n & 1) ? c : '-';
#include "cache_backend_poll.h"
#undef BITMAP
bits[i] = '\0';
u = vt->happy;
for (i = j = 0; i < vt->probe.window; i++) {
if (u & 1)
j++;
u >>= 1;
}
vt->good = j;
if (vt->good >= vt->probe.threshold) {
if (vt->backend->healthy)
logmsg = "Still healthy";
else
logmsg = "Back healthy";
vt->backend->healthy = 1;
} else {
if (vt->backend->healthy)
logmsg = "Went sick";
else
logmsg = "Still sick";
vt->backend->healthy = 0;
}
VSL(SLT_Backend_health, 0, "%s %s %s %u %u %u %.6f %.6f %s",
vt->backend->vcl_name, logmsg, bits,
vt->good, vt->probe.threshold, vt->probe.window,
vt->last, vt->avg, vt->resp_buf);
if (!vt->stop)
TIM_sleep(vt->probe.interval);
}
/*--------------------------------------------------------------------
* One thread per backend to be poked.
*/
static void *
vbp_wrk_poll_backend(void *priv)
{
struct vbp_target *vt;
unsigned u;
THR_SetName("backend poll");
CAST_OBJ_NOTNULL(vt, priv, VBP_TARGET_MAGIC);
......@@ -273,59 +340,29 @@ vbp_wrk_poll_backend(void *priv)
if (vt->probe.threshold == 0)
vt->probe.threshold = 3;
printf("Probe(\"%s\", %g, %g)\n",
vt->req,
vt->probe.timeout,
vt->probe.interval);
if (vt->probe.threshold == ~0)
vt->probe.initial = vt->probe.threshold - 1;
/*lint -e{525} indent */
while (!vt->stop) {
#define BITMAP(n, c, t, b) vt->n <<= 1;
#include "cache_backend_poll.h"
#undef BITMAP
vt->last = 0;
vt->resp_buf[0] = '\0';
vbp_poke(vt);
if (vt->probe.initial > vt->probe.threshold)
vt->probe.initial = vt->probe.threshold;
/* Calculate exponential average */
if (vt->happy & 1) {
if (vt->rate < AVG_RATE)
vt->rate += 1.0;
vt->avg += (vt->last - vt->avg) / vt->rate;
}
printf("Initial %u\n", vt->probe.initial);
i = 0;
#define BITMAP(n, c, t, b) bits[i++] = (vt->n & 1) ? c : '-';
#include "cache_backend_poll.h"
#undef BITMAP
bits[i] = '\0';
printf("Probe(\"%s\", %g, %g)\n",
vt->req, vt->probe.timeout, vt->probe.interval);
u = vt->happy;
for (i = j = 0; i < vt->probe.window; i++) {
if (u & 1)
j++;
u >>= 1;
}
vt->good = j;
if (vt->good >= vt->probe.threshold) {
if (vt->backend->healthy)
logmsg = "Still healthy";
else
logmsg = "Back healthy";
vt->backend->healthy = 1;
} else {
if (vt->backend->healthy)
logmsg = "Went sick";
else
logmsg = "Still sick";
vt->backend->healthy = 0;
}
VSL(SLT_Backend_health, 0, "%s %s %s %u %u %u %.6f %.6f %s",
vt->backend->vcl_name, logmsg, bits,
vt->good, vt->probe.threshold, vt->probe.window,
vt->last, vt->avg, vt->resp_buf);
if (0) {
for (u = 0; u < vt->probe.initial; u++) {
vbp_start_poke(vt);
vt->happy |= 1;
vbp_has_poked(vt);
}
}
while (!vt->stop) {
vbp_start_poke(vt);
vbp_poke(vt);
vbp_has_poked(vt);
if (!vt->stop)
TIM_sleep(vt->probe.interval);
}
......
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