static unsigned nwq;
static unsigned ovfl_max;
static unsigned nthr_max;
-static unsigned nthr_min;
static pthread_cond_t herder_cond;
static MTX herder_mtx;
{
struct worker *w;
- if (qp->nthr <= nthr_min)
+ if (qp->nthr <= params->wthread_min)
return;
LOCK(&qp->mtx);
wrk_addpools(u);
/* Scale parameters */
- u = params->wthread_min / nwq;
- if (u < 1)
- u = 1;
- nthr_min = u;
u = params->wthread_max / nwq;
- if (u < nthr_min)
- u = nthr_min;
+ if (u < params->wthread_min)
+ u = params->wthread_min;
nthr_max = u;
ovfl_max = (nthr_max * params->overflow_max) / 100;
* If we need more threads, and have space, create
* one more thread.
*/
- if (qp->nthr < nthr_min || /* Not enough threads yet */
+ if (qp->nthr < params->wthread_min || /* Not enough threads yet */
(qp->nqueue > params->wthread_add_threshold && /* more needed */
qp->nqueue > qp->lqueue)) { /* not getting better since last */
if (qp->nthr >= nthr_max) {
/*
* Make sure all pools have their minimum complement
*/
- for (w = 0 ; w < nwq; w++) {
- if (wq[w]->nthr < nthr_min)
+ for (w = 0 ; w < nwq; w++)
+ while (wq[w]->nthr < params->wthread_min)
wrk_breed_flock(wq[w]);
- }
/*
* We cannot avoid getting a mutex, so we have a
* bogo mutex just for POSIX_STUPIDITY
tweak_thread_pool_min(struct cli *cli, const struct parspec *par, const char *arg)
{
- (void)par;
tweak_generic_uint(cli, &master.wthread_min, arg,
- 0, master.wthread_max);
+ par->umin, master.wthread_max);
}
/*--------------------------------------------------------------------*/
"in the way of getting work done.\n",
EXPERIMENTAL | DELAYED_EFFECT,
"500", "threads" },
- { "thread_pool_min", tweak_thread_pool_min, NULL, 1, 0,
- "The minimum number of threads in all worker pools combined.\n"
+ { "thread_pool_min", tweak_thread_pool_min, NULL, 2, 0,
+ "The minimum number of threads in each worker pool.\n"
"\n"
"Increasing this may help ramp up faster from low load "
"situations where threads have expired.\n"
"\n"
- "Minimum is 1 thread.",
+ "Minimum is 2 threads.",
EXPERIMENTAL | DELAYED_EFFECT,
- "1", "threads" },
+ "5", "threads" },
{ "thread_pool_timeout", tweak_timeout, &master.wthread_timeout, 1, 0,
"Thread idle threshold.\n"
"\n"