r679 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Sat Aug 5 19:04:25 CEST 2006
Author: phk
Date: 2006-08-05 19:04:25 +0200 (Sat, 05 Aug 2006)
New Revision: 679
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_cli.c
trunk/varnish-cache/bin/varnishd/cache_pool.c
Log:
Add some undocumented code to look for something that worries me.
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2006-08-05 16:41:11 UTC (rev 678)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2006-08-05 17:04:25 UTC (rev 679)
@@ -30,6 +30,7 @@
struct sess;
struct object;
struct objhead;
+struct workreq;
/*--------------------------------------------------------------------*/
@@ -94,6 +95,7 @@
unsigned nbr;
pthread_cond_t cv;
TAILQ_ENTRY(worker) list;
+ struct workreq *wrq;
int *wfd;
unsigned werr; /* valid after WRK_Flush() */
@@ -407,6 +409,7 @@
cli_func_t cli_func_config_load;
cli_func_t cli_func_config_discard;
cli_func_t cli_func_config_use;
+cli_func_t cli_func_dump_pool;
#endif
/* rfc2616.c */
Modified: trunk/varnish-cache/bin/varnishd/cache_cli.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_cli.c 2006-08-05 16:41:11 UTC (rev 678)
+++ trunk/varnish-cache/bin/varnishd/cache_cli.c 2006-08-05 17:04:25 UTC (rev 679)
@@ -44,6 +44,11 @@
{ CLI_CONFIG_LIST, cli_func_config_list },
{ CLI_CONFIG_DISCARD, cli_func_config_discard },
{ CLI_CONFIG_USE, cli_func_config_use },
+
+ /* Undocumented */
+ { "dump.pool", "dump.pool",
+ "\tDump the worker thread pool state\n",
+ 0, 0, cli_func_dump_pool },
{ NULL }
};
Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c 2006-08-05 16:41:11 UTC (rev 678)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2006-08-05 17:04:25 UTC (rev 679)
@@ -14,6 +14,7 @@
#include "heritage.h"
#include "shmlog.h"
#include "vcl.h"
+#include "cli_priv.h"
#include "cache.h"
static pthread_mutex_t wrk_mtx;
@@ -21,7 +22,8 @@
/* Number of work requests queued in excess of worker threads available */
static unsigned wrk_overflow;
-static TAILQ_HEAD(, worker) wrk_head = TAILQ_HEAD_INITIALIZER(wrk_head);
+static TAILQ_HEAD(, worker) wrk_idle = TAILQ_HEAD_INITIALIZER(wrk_idle);
+static TAILQ_HEAD(, worker) wrk_busy = TAILQ_HEAD_INITIALIZER(wrk_busy);
static TAILQ_HEAD(, workreq) wrk_reqhead = TAILQ_HEAD_INITIALIZER(wrk_reqhead);
/*--------------------------------------------------------------------
@@ -107,7 +109,9 @@
VSL_stats->n_wrk_queue--;
AZ(pthread_mutex_unlock(&wrk_mtx));
CHECK_OBJ_NOTNULL(wrq->sess, SESS_MAGIC);
+ assert(wrq->sess->wrk == NULL);
wrq->sess->wrk = w;
+ w->wrq = wrq;
if (wrq->sess->srcaddr == NULL) {
w->acct.sess++;
SES_RefSrcAddr(wrq->sess);
@@ -121,6 +125,8 @@
CHECK_OBJ(w->nobj, OBJECT_MAGIC);
if (w->nobjhead != NULL)
CHECK_OBJ(w->nobjhead, OBJHEAD_MAGIC);
+ wrq->sess->wrk = NULL;
+ w->wrq = NULL;
AZ(pthread_mutex_lock(&wrk_mtx));
VSL_stats->n_wrk_busy--;
}
@@ -143,6 +149,7 @@
VSL_stats->n_wrk_create++;
VSL(SLT_WorkThread, 0, "%u born dynamic", w->nbr);
}
+ TAILQ_INSERT_HEAD(&wrk_busy, w, list);
while (1) {
CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
@@ -153,7 +160,8 @@
continue;
}
- TAILQ_INSERT_HEAD(&wrk_head, w, list);
+ TAILQ_REMOVE(&wrk_busy, w, list);
+ TAILQ_INSERT_HEAD(&wrk_idle, w, list);
/* If we are a reserved thread we don't die */
if (priv != NULL) {
@@ -164,7 +172,7 @@
ts.tv_sec += heritage.wthread_timeout;
if (pthread_cond_timedwait(&w->cv, &wrk_mtx, &ts)) {
VSL_stats->n_wrk--;
- TAILQ_REMOVE(&wrk_head, w, list);
+ TAILQ_REMOVE(&wrk_idle, w, list);
AZ(pthread_mutex_unlock(&wrk_mtx));
VSL(SLT_WorkThread, 0, "%u suicide", w->nbr);
AZ(pthread_cond_destroy(&w->cv));
@@ -172,7 +180,7 @@
}
}
- /* we are already removed from wrk_head */
+ /* we are already removed from wrk_idle */
wrk_do_one(w);
}
}
@@ -194,10 +202,11 @@
VSL_stats->n_wrk_queue++;
/* If there are idle threads, we tickle the first one into action */
- w = TAILQ_FIRST(&wrk_head);
+ w = TAILQ_FIRST(&wrk_idle);
if (w != NULL) {
AZ(pthread_cond_signal(&w->cv));
- TAILQ_REMOVE(&wrk_head, w, list);
+ TAILQ_REMOVE(&wrk_idle, w, list);
+ TAILQ_INSERT_TAIL(&wrk_busy, w, list);
AZ(pthread_mutex_unlock(&wrk_mtx));
return;
}
@@ -248,3 +257,39 @@
AZ(pthread_detach(tp));
}
}
+
+
+/*--------------------------------------------------------------------*/
+
+void
+cli_func_dump_pool(struct cli *cli, char **av, void *priv)
+{
+ unsigned u;
+ struct sess *s;
+ time_t t;
+
+ (void)av;
+ (void)priv;
+ struct worker *w;
+ AZ(pthread_mutex_lock(&wrk_mtx));
+ t = time(NULL);
+ TAILQ_FOREACH(w, &wrk_busy, list) {
+ cli_out(cli, "\n");
+ cli_out(cli, "W %p nbr %d ", w, w->nbr);
+ if (w->wrq == NULL)
+ continue;
+ s = w->wrq->sess;
+ if (s == NULL)
+ continue;
+ cli_out(cli, "sess %p fd %d xid %u step %d handling %d age %d",
+ s, s->fd, s->xid, s->step, s->handling,
+ t - s->t_req.tv_sec);
+ }
+ cli_out(cli, "\n");
+
+ u = 0;
+ TAILQ_FOREACH(w, &wrk_idle, list)
+ u++;
+ cli_out(cli, "%u idle workers\n", u);
+ AZ(pthread_mutex_unlock(&wrk_mtx));
+}
More information about the varnish-commit
mailing list