r4184 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Mon Aug 17 13:26:20 CEST 2009
Author: phk
Date: 2009-08-17 13:26:19 +0200 (Mon, 17 Aug 2009)
New Revision: 4184
Modified:
trunk/varnish-cache/bin/varnishd/cache_acceptor.c
trunk/varnish-cache/bin/varnishd/cache_backend_poll.c
Log:
An explanatory comment.
Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2009-08-17 10:53:17 UTC (rev 4183)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2009-08-17 11:26:19 UTC (rev 4184)
@@ -69,6 +69,13 @@
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,
};
Modified: trunk/varnish-cache/bin/varnishd/cache_backend_poll.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend_poll.c 2009-08-17 10:53:17 UTC (rev 4183)
+++ trunk/varnish-cache/bin/varnishd/cache_backend_poll.c 2009-08-17 11:26:19 UTC (rev 4184)
@@ -242,18 +242,85 @@
}
/*--------------------------------------------------------------------
- * 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)
{
- 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)
+{
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 @@
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 (0) {
+ for (u = 0; u < vt->probe.initial; u++) {
+ vbp_start_poke(vt);
+ vt->happy |= 1;
+ vbp_has_poked(vt);
+ }
+}
- 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);
-
+ while (!vt->stop) {
+ vbp_start_poke(vt);
+ vbp_poke(vt);
+ vbp_has_poked(vt);
if (!vt->stop)
TIM_sleep(vt->probe.interval);
}
More information about the varnish-commit
mailing list