Mailing List Archive

r2656 - trunk/varnish-cache/bin/varnishd
Author: phk
Date: 2008-06-09 10:35:38 +0200 (Mon, 09 Jun 2008)
New Revision: 2656

Modified:
trunk/varnish-cache/bin/varnishd/cache_pool.c
Log:
Style & Polish.


Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c 2008-06-09 08:12:31 UTC (rev 2655)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2008-06-09 08:35:38 UTC (rev 2656)
@@ -28,7 +28,18 @@
*
* $Id$
*
- * XXX: automatic thread-pool size adaptation.
+ * We maintain a number of worker thread pools, to spread lock contention.
+ *
+ * Pools can be added on the fly, as a means to mitigate lock contention,
+ * but can only be removed again by a restart. (XXX: we could fix that)
+ *
+ * Two threads herd the pools, one eliminates idle threads and aggregates
+ * statistics for all the pools, the other thread creates new threads
+ * on demand, subject to various numerical constraints.
+ *
+ * The algorithm for when to create threads needs to be reactive enough
+ * to handle startup spikes, but sufficiently attenuated to not cause
+ * thread pileups. This remains subject for improvement.
*/

#include "config.h"
@@ -188,24 +199,6 @@

/*--------------------------------------------------------------------*/

-static void
-wrk_do_cnt_sess(struct worker *w, void *priv)
-{
- struct sess *sess;
-
- CAST_OBJ_NOTNULL(sess, priv, SESS_MAGIC);
- sess->wrk = w;
- CHECK_OBJ_ORNULL(w->nobj, OBJECT_MAGIC);
- CHECK_OBJ_ORNULL(w->nobjhead, OBJHEAD_MAGIC);
- w->used = NAN;
- CNT_Session(sess);
- assert(!isnan(w->used));
- CHECK_OBJ_ORNULL(w->nobj, OBJECT_MAGIC);
- CHECK_OBJ_ORNULL(w->nobjhead, OBJHEAD_MAGIC);
-}
-
-/*--------------------------------------------------------------------*/
-
static void *
wrk_thread(void *priv)
{
@@ -269,7 +262,11 @@
return (NULL);
}

-/*--------------------------------------------------------------------*/
+/*--------------------------------------------------------------------
+ * Queue a workrequest if possible.
+ *
+ * Return zero if the request was queued, negative if it wasn't.
+ */

int
WRK_Queue(struct workreq *wrq)
@@ -302,8 +299,7 @@
return (0);
}

- /* If we have too much in the overflow already, refuse */
-
+ /* If we have too much in the overflow already, refuse. */
if (qp->nqueue > ovfl_max) {
qp->ndrop++;
UNLOCK(&qp->mtx);
@@ -320,6 +316,24 @@

/*--------------------------------------------------------------------*/

+static void
+wrk_do_cnt_sess(struct worker *w, void *priv)
+{
+ struct sess *sess;
+
+ CAST_OBJ_NOTNULL(sess, priv, SESS_MAGIC);
+ sess->wrk = w;
+ CHECK_OBJ_ORNULL(w->nobj, OBJECT_MAGIC);
+ CHECK_OBJ_ORNULL(w->nobjhead, OBJHEAD_MAGIC);
+ w->used = NAN;
+ CNT_Session(sess);
+ assert(!isnan(w->used));
+ CHECK_OBJ_ORNULL(w->nobj, OBJECT_MAGIC);
+ CHECK_OBJ_ORNULL(w->nobjhead, OBJHEAD_MAGIC);
+}
+
+/*--------------------------------------------------------------------*/
+
void
WRK_QueueSession(struct sess *sp)
{
@@ -346,7 +360,9 @@
SES_Delete(sp);
}

-/*--------------------------------------------------------------------*/
+/*--------------------------------------------------------------------
+ * Add (more) thread pools
+ */

static void
wrk_addpools(const unsigned pools)
@@ -466,7 +482,7 @@
}

/*--------------------------------------------------------------------
- * Create more threads, if necessay & possible
+ * Create another thread, if necessary & possible
*/

static void
@@ -540,6 +556,7 @@
AZ(pthread_mutex_init(&herder_mtx, NULL));

AZ(pthread_create(&tp, NULL, wrk_herdtimer_thread, NULL));
+ AZ(pthread_detach(tp));
AZ(pthread_create(&tp, NULL, wrk_herder_thread, NULL));
AZ(pthread_detach(tp));
}