r5583 - trunk/varnish-cache/bin/varnishd

phk at varnish-cache.org phk at varnish-cache.org
Mon Nov 22 11:04:56 CET 2010


Author: phk
Date: 2010-11-22 11:04:55 +0100 (Mon, 22 Nov 2010)
New Revision: 5583

Modified:
   trunk/varnish-cache/bin/varnishd/cache_expire.c
   trunk/varnish-cache/bin/varnishd/heritage.h
   trunk/varnish-cache/bin/varnishd/mgt_param.c
Log:
The expiry thread caches its "now" timestamp and if there was a lot
of work to do, this timestamp could get behind times, and send the
thread to sleep, despite being behind on work.

Fix this, by updating the timestamp whenever we run out of work.

Add a parameter ("expiry_sleep") to control how long time the thread
will sleep so this can be tuned down on high-load servers.

Inspired by:	sky



Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_expire.c	2010-11-22 09:44:48 UTC (rev 5582)
+++ trunk/varnish-cache/bin/varnishd/cache_expire.c	2010-11-22 10:04:55 UTC (rev 5583)
@@ -226,8 +226,7 @@
 
 /*--------------------------------------------------------------------
  * This thread monitors the root of the binary heap and whenever an
- * object gets close enough, VCL is asked to decide if it should be
- * discarded.
+ * object expires, accounting also for graceability, it is killed.
  */
 
 static void * __match_proto__(void *start_routine(void *))
@@ -243,11 +242,17 @@
 		Lck_Lock(&exp_mtx);
 		oc = binheap_root(exp_heap);
 		CHECK_OBJ_ORNULL(oc, OBJCORE_MAGIC);
+		/*
+		 * We may have expired so many objects that our timestamp
+		 * got out of date, refresh it and check again.
+		 */
+		if (oc != NULL && oc->timer_when > t)
+			t = TIM_real();
 		if (oc == NULL || oc->timer_when > t) { /* XXX: > or >= ? */
 			Lck_Unlock(&exp_mtx);
 			WSL_Flush(sp->wrk, 0);
 			WRK_SumStat(sp->wrk);
-			AZ(sleep(1));
+			TIM_sleep(params->expiry_sleep);
 			t = TIM_real();
 			continue;
 		}

Modified: trunk/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/heritage.h	2010-11-22 09:44:48 UTC (rev 5582)
+++ trunk/varnish-cache/bin/varnishd/heritage.h	2010-11-22 10:04:55 UTC (rev 5583)
@@ -178,6 +178,9 @@
 	/* Acceptable clockskew with backends */
 	unsigned		clock_skew;
 
+	/* Expiry pacer parameters */
+	double			expiry_sleep;
+
 	/* Acceptor pacer parameters */
 	double			acceptor_sleep_max;
 	double			acceptor_sleep_incr;

Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_param.c	2010-11-22 09:44:48 UTC (rev 5582)
+++ trunk/varnish-cache/bin/varnishd/mgt_param.c	2010-11-22 10:04:55 UTC (rev 5583)
@@ -549,6 +549,11 @@
 		"seconds, the session is closed.",
 		0,
 		"5", "seconds" },
+	{ "expiry_sleep", tweak_timeout_double, &master.expiry_sleep, 0, 60,
+		"How long the expiry thread sleeps when there is nothing "
+		"for it to do.  Reduce if your expiry thread gets behind.\n",
+		0,
+		"1", "seconds" },
 	{ "pipe_timeout", tweak_timeout, &master.pipe_timeout, 0, 0,
 		"Idle timeout for PIPE sessions. "
 		"If nothing have been received in either direction for "




More information about the varnish-commit mailing list