diff --git a/daemon/call.h b/daemon/call.h index 937fa60dd..28f5c26e0 100644 --- a/daemon/call.h +++ b/daemon/call.h @@ -430,6 +430,8 @@ struct callmaster_config { enum xmlrpc_format fmt; endpoint_t graphite_ep; int graphite_interval; + + int redis_num_threads; }; struct callmaster { diff --git a/daemon/main.c b/daemon/main.c index 672a9b072..acf8826ab 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -71,6 +71,7 @@ static int port_max = 40000; static int max_sessions = -1; static int redis_db = -1; static int redis_write_db = -1; +static int redis_num_threads; static int no_redis_required; static char *redis_auth; static char *redis_write_auth; @@ -290,6 +291,7 @@ static void options(int *argc, char ***argv) { { "port-max", 'M', 0, G_OPTION_ARG_INT, &port_max, "Highest port to use for RTP", "INT" }, { "redis", 'r', 0, G_OPTION_ARG_STRING, &redisps, "Connect to Redis database", "[PW@]IP:PORT/INT" }, { "redis-write",'w', 0, G_OPTION_ARG_STRING, &redisps_write, "Connect to Redis write database", "[PW@]IP:PORT/INT" }, + { "redis-num-threads", 'w', 0, G_OPTION_ARG_INT, &redis_num_threads, "Number of Redis restore threads", "INT" }, { "no-redis-required", 'q', 0, G_OPTION_ARG_NONE, &no_redis_required, "Start no matter of redis connection state", NULL }, { "b2b-url", 'b', 0, G_OPTION_ARG_STRING, &b2b_url, "XMLRPC URL of B2B UA" , "STRING" }, { "log-level", 'L', 0, G_OPTION_ARG_INT, (void *)&log_level,"Mask log priorities above this level","INT" }, @@ -540,6 +542,15 @@ no_kernel: mc.fmt = xmlrpc_fmt; mc.graphite_ep = graphite_ep; mc.graphite_interval = graphite_interval; + if (redis_num_threads < 1) { +#ifdef _SC_NPROCESSORS_ONLN + redis_num_threads = sysconf( _SC_NPROCESSORS_ONLN ); +#endif + if (redis_num_threads < 1) { + redis_num_threads = REDIS_RESTORE_NUM_THREADS; + } + } + mc.redis_num_threads = redis_num_threads; ct = NULL; if (tcp_listen_ep.port) { diff --git a/daemon/redis.c b/daemon/redis.c index 027b5d71e..cb1b674f4 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -1086,7 +1086,6 @@ struct thread_ctx { GQueue r_q; mutex_t r_m; }; -#define RESTORE_NUM_THREADS 4 static void restore_thread(void *call_p, void *ctx_p) { struct thread_ctx *ctx = ctx_p; @@ -1138,9 +1137,9 @@ int redis_restore(struct callmaster *m, struct redis *r) { ctx.m = m; mutex_init(&ctx.r_m); g_queue_init(&ctx.r_q); - for (i = 0; i < RESTORE_NUM_THREADS; i++) + for (i = 0; i < m->conf.redis_num_threads; i++) g_queue_push_tail(&ctx.r_q, redis_new(&r->endpoint, r->db, r->auth, r->role, r->no_redis_required)); - gtp = g_thread_pool_new(restore_thread, &ctx, RESTORE_NUM_THREADS, TRUE, NULL); + gtp = g_thread_pool_new(restore_thread, &ctx, m->conf.redis_num_threads, TRUE, NULL); for (i = 0; i < calls->elements; i++) { call = calls->element[i]; diff --git a/daemon/redis.h b/daemon/redis.h index 037fab041..ead5281e6 100644 --- a/daemon/redis.h +++ b/daemon/redis.h @@ -14,6 +14,9 @@ #include +#define REDIS_RESTORE_NUM_THREADS 4 + + enum redis_role { MASTER_REDIS_ROLE = 0, SLAVE_REDIS_ROLE = 1, diff --git a/debian/ngcp-rtpengine-daemon.default b/debian/ngcp-rtpengine-daemon.default index ed69e24bb..161088ed8 100644 --- a/debian/ngcp-rtpengine-daemon.default +++ b/debian/ngcp-rtpengine-daemon.default @@ -21,6 +21,7 @@ TABLE=0 # REDIS_WRITE=127.0.0.1:6379 # REDIS_WRITE_DB=1 # REDIS_WRITE_AUTH_PW=foobar +# REDIS_NUM_THREADS=8 # NO_REDIS_REQUIRED=yes # B2B_URL=http://127.0.0.1:8090/ # LOG_LEVEL=6 diff --git a/debian/ngcp-rtpengine-daemon.init b/debian/ngcp-rtpengine-daemon.init index bbba8aa0d..5bf1e891f 100755 --- a/debian/ngcp-rtpengine-daemon.init +++ b/debian/ngcp-rtpengine-daemon.init @@ -66,6 +66,7 @@ fi [ -z "$REDIS_AUTH_PW" ] || export RTPENGINE_REDIS_AUTH_PW="$REDIS_AUTH_PW" [ -z "$REDIS_WRITE" -o -z "$REDIS_WRITE_DB" ] || OPTIONS="$OPTIONS --redis-write=$REDIS_WRITE/$REDIS_WRITE_DB" [ -z "$REDIS_WRITE_AUTH_PW" ] || export RTPENGINE_REDIS_WRITE_AUTH_PW="$REDIS_WRITE_AUTH_PW" +[ -z "$REDIS_NUM_THREADS" ] || OPTIONS="$OPTIONS --redis-num-threads=$REDIS_NUM_THREADS" [ -z "$NO_REDIS_REQUIRED" -o \( "$NO_REDIS_REQUIRED" != "1" -a "$NO_REDIS_REQUIRED" != "yes" \) ] || OPTIONS="$OPTIONS --no-redis-required" [ -z "$B2B_URL" ] || OPTIONS="$OPTIONS --b2b-url=$B2B_URL" [ -z "$NO_FALLBACK" -o \( "$NO_FALLBACK" != "1" -a "$NO_FALLBACK" != "yes" \) ] || OPTIONS="$OPTIONS --no-fallback"