Add config REDIS_NUM_THREADS param

Configurable redis restore threads.
pull/221/head
smititelu 10 years ago
parent 74ad505c6f
commit 65de7932ad

@ -430,6 +430,8 @@ struct callmaster_config {
enum xmlrpc_format fmt; enum xmlrpc_format fmt;
endpoint_t graphite_ep; endpoint_t graphite_ep;
int graphite_interval; int graphite_interval;
int redis_num_threads;
}; };
struct callmaster { struct callmaster {

@ -71,6 +71,7 @@ static int port_max = 40000;
static int max_sessions = -1; static int max_sessions = -1;
static int redis_db = -1; static int redis_db = -1;
static int redis_write_db = -1; static int redis_write_db = -1;
static int redis_num_threads;
static int no_redis_required; static int no_redis_required;
static char *redis_auth; static char *redis_auth;
static char *redis_write_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" }, { "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", '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-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 }, { "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" }, { "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" }, { "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.fmt = xmlrpc_fmt;
mc.graphite_ep = graphite_ep; mc.graphite_ep = graphite_ep;
mc.graphite_interval = graphite_interval; 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; ct = NULL;
if (tcp_listen_ep.port) { if (tcp_listen_ep.port) {

@ -1086,7 +1086,6 @@ struct thread_ctx {
GQueue r_q; GQueue r_q;
mutex_t r_m; mutex_t r_m;
}; };
#define RESTORE_NUM_THREADS 4
static void restore_thread(void *call_p, void *ctx_p) { static void restore_thread(void *call_p, void *ctx_p) {
struct thread_ctx *ctx = ctx_p; struct thread_ctx *ctx = ctx_p;
@ -1138,9 +1137,9 @@ int redis_restore(struct callmaster *m, struct redis *r) {
ctx.m = m; ctx.m = m;
mutex_init(&ctx.r_m); mutex_init(&ctx.r_m);
g_queue_init(&ctx.r_q); 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)); 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++) { for (i = 0; i < calls->elements; i++) {
call = calls->element[i]; call = calls->element[i];

@ -14,6 +14,9 @@
#include <hiredis/hiredis.h> #include <hiredis/hiredis.h>
#define REDIS_RESTORE_NUM_THREADS 4
enum redis_role { enum redis_role {
MASTER_REDIS_ROLE = 0, MASTER_REDIS_ROLE = 0,
SLAVE_REDIS_ROLE = 1, SLAVE_REDIS_ROLE = 1,

@ -21,6 +21,7 @@ TABLE=0
# REDIS_WRITE=127.0.0.1:6379 # REDIS_WRITE=127.0.0.1:6379
# REDIS_WRITE_DB=1 # REDIS_WRITE_DB=1
# REDIS_WRITE_AUTH_PW=foobar # REDIS_WRITE_AUTH_PW=foobar
# REDIS_NUM_THREADS=8
# NO_REDIS_REQUIRED=yes # NO_REDIS_REQUIRED=yes
# B2B_URL=http://127.0.0.1:8090/ # B2B_URL=http://127.0.0.1:8090/
# LOG_LEVEL=6 # LOG_LEVEL=6

@ -66,6 +66,7 @@ fi
[ -z "$REDIS_AUTH_PW" ] || export RTPENGINE_REDIS_AUTH_PW="$REDIS_AUTH_PW" [ -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" -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_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 "$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 "$B2B_URL" ] || OPTIONS="$OPTIONS --b2b-url=$B2B_URL"
[ -z "$NO_FALLBACK" -o \( "$NO_FALLBACK" != "1" -a "$NO_FALLBACK" != "yes" \) ] || OPTIONS="$OPTIONS --no-fallback" [ -z "$NO_FALLBACK" -o \( "$NO_FALLBACK" != "1" -a "$NO_FALLBACK" != "yes" \) ] || OPTIONS="$OPTIONS --no-fallback"

Loading…
Cancel
Save