Commit 82f2a37d authored by Nils Goroll's avatar Nils Goroll

make the worker thread size configurable and choose a sensible small default

parent 8dd93ba4
......@@ -492,6 +492,11 @@ Parameter CLI Option Description
-------------------- ---------- ----------------------------------------------------------------------------------------- -------
``nworkers`` Number of worker threads used to send messages to the message broker(s). 1
-------------------- ---------- ----------------------------------------------------------------------------------------- -------
``worker.stack`` Stack size for worker threads started by trackrdrd. 131072
Note: mq modules may start additional threads to which this limit does not apply
Observed actual stack sizes are <64k, so the default leaves plenty of room. (128 KB)
Increase only if segmentation faults on stack addresses are observed
-------------------- ---------- ----------------------------------------------------------------------------------------- -------
``max.records`` The maximum number of buffered records waiting to be sent to message brokers. 1024
-------------------- ---------- ----------------------------------------------------------------------------------------- -------
``max.reclen`` The maximum length of a data record in characters. Should be at least as large the 1024
......
......@@ -140,6 +140,7 @@ CONF_Add(const char *lval, const char *rval)
confUnsigned("maxkeylen", maxkeylen);
confUnsigned("qlen.goal", qlen_goal);
confUnsigned("nworkers", nworkers);
confUnsigned("worker.stack", worker_stack);
confUnsigned("restarts", restarts);
confUnsigned("restart.pause", restart_pause);
confUnsigned("thread.restarts", thread_restarts);
......@@ -239,6 +240,7 @@ CONF_Init(void)
config.mq_module[0] = '\0';
config.mq_config_file[0] = '\0';
config.nworkers = 1;
config.worker_stack = 128 * 1024;
config.restarts = 1;
config.restart_pause = 1;
config.thread_restarts = 1;
......
......@@ -99,4 +99,6 @@ test_worker_LDADD = \
../data.$(OBJEXT) \
../assert.$(OBJEXT) \
../vtim.$(OBJEXT) \
../config.$(OBJEXT) \
../config_common.$(OBJEXT) \
-L${VARNISH_PKG_LIB}/varnish -lvarnish
......@@ -109,11 +109,9 @@ static char
printf("... testing worker initialization\n");
config.max_records = DEF_MAX_RECORDS;
config.max_reclen = DEF_MAX_RECLEN;
config.maxkeylen = DEF_MAXKEYLEN;
CONF_Init();
config.nworkers = NWORKERS;
config.chunk_size = DEF_CHUNK_SIZE;
strcpy(config.mq_config_file, MQ_CONFIG);
error = mqf.global_init(config.nworkers, config.mq_config_file);
......
......@@ -219,6 +219,7 @@ struct config {
#define DEF_QLEN_GOAL 512
unsigned nworkers;
size_t worker_stack;
unsigned restarts;
unsigned restart_pause;
unsigned thread_restarts;
......
......@@ -405,22 +405,37 @@ WRK_Init(void)
return 0;
}
void
wrk_pthread_attr_init(pthread_attr_t *attr)
{
AZ(pthread_attr_init(attr));
AZ(pthread_attr_setstacksize(attr, config.worker_stack));
}
void
WRK_Start(void)
{
pthread_attr_t attr;
wrk_pthread_attr_init(&attr);
run = 1;
for (int i = 0; i < config.nworkers; i++) {
CHECK_OBJ_NOTNULL(thread_data[i].wrk_data, WORKER_DATA_MAGIC);
AZ(pthread_create(&thread_data[i].worker, NULL, wrk_main,
AZ(pthread_create(&thread_data[i].worker, &attr, wrk_main,
thread_data[i].wrk_data));
}
AZ(pthread_attr_destroy(&attr));
}
int
WRK_Restart(void)
{
int err = 0;
worker_data_t *wrk;
pthread_attr_t attr;
wrk_pthread_attr_init(&attr);
for (int i = 0; i < config.nworkers; i++) {
CHECK_OBJ_NOTNULL(thread_data[i].wrk_data, WORKER_DATA_MAGIC);
wrk = thread_data[i].wrk_data;
......@@ -442,18 +457,20 @@ WRK_Restart(void)
wrk->restarts++;
MON_StatsUpdate(STATS_RESTART, 0, 0);
wrk->state = WRK_NOTSTARTED;
if (pthread_create(&thread_data[i].worker, NULL, wrk_main, wrk)
if (pthread_create(&thread_data[i].worker, &attr, wrk_main, wrk)
!= 0) {
/* EAGAIN means we've hit a system limit trying to restart
threads, so it's time to give up. Any other errno is a
programming error.
*/
assert(errno == EAGAIN);
return errno;
err = errno;
break;
}
}
}
return 0;
AZ(pthread_attr_destroy(&attr));
return err;
}
void
......
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