Commit 7c57822e authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add a parameter to set the workerthread stacksize.

On 32 bit systems, it may be necessary to tweak this down to get high
numbers of worker threads squeezed into the address-space.

I have no idea how much stack-space a worker thread normally uses, so
no guidance is given, and we default to the system default.

Fixes #572


git-svn-id: http://www.varnish-cache.org/svn/trunk@4352 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent e7540c13
......@@ -432,7 +432,7 @@ wrk_herdtimer_thread(void *priv)
*/
static void
wrk_breed_flock(struct wq *qp)
wrk_breed_flock(struct wq *qp, const pthread_attr_t *tp_attr)
{
pthread_t tp;
......@@ -445,7 +445,7 @@ wrk_breed_flock(struct wq *qp)
qp->nqueue > qp->lqueue)) { /* not getting better since last */
if (qp->nthr >= nthr_max) {
VSL_stats->n_wrk_max++;
} else if (pthread_create(&tp, NULL, wrk_thread, qp)) {
} else if (pthread_create(&tp, tp_attr, wrk_thread, qp)) {
VSL(SLT_Debug, 0, "Create worker thread failed %d %s",
errno, strerror(errno));
VSL_stats->n_wrk_failed++;
......@@ -476,17 +476,27 @@ static void *
wrk_herder_thread(void *priv)
{
unsigned u, w;
pthread_attr_t tp_attr;
/* Set the stacksize for worker threads */
AZ(pthread_attr_init(&tp_attr));
THR_SetName("wrk_herder");
(void)priv;
while (1) {
for (u = 0 ; u < nwq; u++) {
if (params->wthread_stacksize != UINT_MAX)
AZ(pthread_attr_setstacksize(&tp_attr,
params->wthread_stacksize));
wrk_breed_flock(wq[u], &tp_attr);
/*
* Make sure all pools have their minimum complement
*/
for (w = 0 ; w < nwq; w++)
while (wq[w]->nthr < params->wthread_min)
wrk_breed_flock(wq[w]);
wrk_breed_flock(wq[w], &tp_attr);
/*
* We cannot avoid getting a mutex, so we have a
* bogo mutex just for POSIX_STUPIDITY
......@@ -494,7 +504,6 @@ wrk_herder_thread(void *priv)
Lck_Lock(&herder_mtx);
Lck_CondWait(&herder_cond, &herder_mtx);
Lck_Unlock(&herder_mtx);
wrk_breed_flock(wq[u]);
}
}
NEEDLESS_RETURN(NULL);
......
......@@ -93,6 +93,7 @@ struct params {
unsigned wthread_fail_delay;
unsigned wthread_purge_delay;
unsigned wthread_stats_rate;
unsigned wthread_stacksize;
unsigned overflow_max;
......
......@@ -190,6 +190,13 @@ const struct parspec WRK_parspec[] = {
"number of worker threads. ",
EXPERIMENTAL,
"3", "requests per request" },
{ "thread_pool_stack",
tweak_uint, &master.wthread_stacksize, 64*1024, UINT_MAX,
"Worker thread stack size. In particular on 32bit systems "
"you may need to tweak this down to fit many threads into "
"the limited address space.\n",
EXPERIMENTAL,
"-1", "bytes" },
{ NULL, NULL, NULL }
};
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