r4402 - branches/2.0/varnish-cache/bin/varnishd

tfheen at projects.linpro.no tfheen at projects.linpro.no
Wed Dec 16 10:55:38 CET 2009


Author: tfheen
Date: 2009-12-16 10:55:37 +0100 (Wed, 16 Dec 2009)
New Revision: 4402

Modified:
   branches/2.0/varnish-cache/bin/varnishd/cache_pool.c
   branches/2.0/varnish-cache/bin/varnishd/heritage.h
   branches/2.0/varnish-cache/bin/varnishd/mgt_pool.c
Log:
Merge r4352: 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



Modified: branches/2.0/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_pool.c	2009-12-16 09:53:25 UTC (rev 4401)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_pool.c	2009-12-16 09:55:37 UTC (rev 4402)
@@ -551,7 +551,7 @@
  */
 
 static void
-wrk_breed_flock(struct wq *qp)
+wrk_breed_flock(struct wq *qp, const pthread_attr_t *tp_attr)
 {
 	pthread_t tp;
 
@@ -564,7 +564,7 @@
 	    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++;
@@ -595,17 +595,27 @@
 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
@@ -613,7 +623,6 @@
 			Lck_Lock(&herder_mtx);
 			Lck_CondWait(&herder_cond, &herder_mtx);
 			Lck_Unlock(&herder_mtx);
-			wrk_breed_flock(wq[u]);
 		}
 	}
 }

Modified: branches/2.0/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/heritage.h	2009-12-16 09:53:25 UTC (rev 4401)
+++ branches/2.0/varnish-cache/bin/varnishd/heritage.h	2009-12-16 09:55:37 UTC (rev 4402)
@@ -94,6 +94,7 @@
 	unsigned		wthread_add_delay;
 	unsigned		wthread_fail_delay;
 	unsigned		wthread_purge_delay;
+	unsigned		wthread_stacksize;
 
 	unsigned		overflow_max;
 

Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_pool.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/mgt_pool.c	2009-12-16 09:53:25 UTC (rev 4401)
+++ branches/2.0/varnish-cache/bin/varnishd/mgt_pool.c	2009-12-16 09:55:37 UTC (rev 4402)
@@ -179,6 +179,13 @@
 		"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 }
 };
 



More information about the varnish-commit mailing list