From b66091b090aa5f70210076804719f56e106a68a1 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 23 Oct 2014 11:05:25 -0400 Subject: [PATCH] make number of threads configurable --- daemon/main.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/daemon/main.c b/daemon/main.c index 86802a2ad..56d85f0eb 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -101,6 +101,7 @@ static u_int16_t redis_port; static int redis_db = -1; static char *b2b_url; static enum xmlrpc_format xmlrpc_fmt = XF_SEMS; +static int num_threads; static void sighandler(gpointer x) { @@ -332,6 +333,7 @@ static void options(int *argc, char ***argv) { { "log-facility",0, 0, G_OPTION_ARG_STRING, &log_facility_s, "Syslog facility to use for logging", "daemon|local0|...|local7"}, { "log-stderr", 'E', 0, G_OPTION_ARG_NONE, &_log_stderr, "Log on stderr instead of syslog", NULL }, { "xmlrpc-format",'x', 0, G_OPTION_ARG_INT, &xmlrpc_fmt, "XMLRPC timeout request format to use. 0: SEMS DI, 1: call-id only", "INT" }, + { "num-threads", 0, 0, G_OPTION_ARG_INT, &num_threads, "Number of worker threads to create", "INT" }, { NULL, } }; @@ -617,7 +619,7 @@ static void poller_loop(void *d) { int main(int argc, char **argv) { struct main_context ctx; - int idx=0, numCPU=0; + int idx=0; options(&argc, &argv); init_everything(); @@ -628,9 +630,15 @@ int main(int argc, char **argv) { thread_create_detach(sighandler, NULL); thread_create_detach(timer_loop, ctx.p); - numCPU = sysconf( _SC_NPROCESSORS_ONLN ); + if (num_threads < 1) { +#ifdef _SC_NPROCESSORS_ONLN + num_threads = sysconf( _SC_NPROCESSORS_ONLN ); +#endif + if (num_threads < 1) + num_threads = 4; + } - for (;idx