Browse Source

Make redis connection timeout configurable

pull/445/head
Claudiu Boriga 8 years ago
parent
commit
485092383f
5 changed files with 22 additions and 8 deletions
  1. +8
    -0
      README.md
  2. +5
    -3
      daemon/main.c
  3. +6
    -4
      daemon/redis.c
  4. +2
    -1
      daemon/redis.h
  5. +1
    -0
      etc/rtpengine.sample.conf

+ 8
- 0
README.md View File

@ -186,6 +186,7 @@ option and which are reproduced below:
--redis-allowed-errors Number of allowed errors before redis is temporarily disabled
--redis-disable-time Number of seconds redis communication is disabled because of errors
--redis-cmd-timeout Sets a timeout in milliseconds for redis commands
--redis-connect-timeout Sets a timeout in milliseconds for redis connections
-b, --b2b-url=STRING XMLRPC URL of B2B UA
-L, --log-level=INT Mask log priorities above this level
--log-facility=daemon|local0|... Syslog facility to use for logging
@ -462,6 +463,13 @@ The options are described in more detail below.
If redis does not reply within the specified timeout the command will fail. The default value is 0, meaning that the commands
will have no timeout
* --redis-connect-timeout
This parameter sets the timeout value, in milliseconds, when connecting to a redis server. If the connection cannot be made
within the specified timeout the connection will fail. Note that in case of failure, when reconnecting to redis, a PING command
is issued before attempting to connect so the `--redis-cmd-timeout` value will also be added to the total waiting time.
This is useful if using `--redis-allowed-errors', when attempting to estimate the total lost time in case of redis failures.
The default value for the connection timeout is 1000ms.
* -b, --b2b-url
Enables and sets the URI for an XMLRPC callback to be made when a call is torn down due to packet


+ 5
- 3
daemon/main.c View File

@ -74,6 +74,7 @@ static int no_redis_required;
static int redis_allowed_errors = -1;
static int redis_disable_time = 10;
static int redis_cmd_timeout = 0;
static int redis_connect_timeout = 1000;
static char *redis_auth;
static char *redis_write_auth;
static char *b2b_url;
@ -284,6 +285,7 @@ static void options(int *argc, char ***argv) {
{ "redis-allowed-errors", 0, 0, G_OPTION_ARG_INT, &redis_allowed_errors, "Number of allowed errors before redis is temporarily disabled", "INT" },
{ "redis-disable-time", 0, 0, G_OPTION_ARG_INT, &redis_disable_time, "Number of seconds redis communication is disabled because of errors", "INT" },
{ "redis-cmd-timeout", 0, 0, G_OPTION_ARG_INT, &redis_cmd_timeout, "Sets a timeout in milliseconds for redis commands", "INT" },
{ "redis-connect-timeout", 0, 0, G_OPTION_ARG_INT, &redis_connect_timeout, "Sets a timeout in milliseconds for redis connections", "INT" },
{ "b2b-url", 'b', 0, G_OPTION_ARG_STRING, &b2b_url, "XMLRPC URL of B2B UA" , "STRING" },
{ "log-facility-cdr",0, 0, G_OPTION_ARG_STRING, &log_facility_cdr_s, "Syslog facility to use for logging CDRs", "daemon|local0|...|local7"},
{ "log-facility-rtcp",0, 0, G_OPTION_ARG_STRING, &log_facility_rtcp_s, "Syslog facility to use for logging RTCP", "daemon|local0|...|local7"},
@ -584,7 +586,7 @@ no_kernel:
if (!is_addr_unspecified(&redis_write_ep.address)) {
mc.redis_write = redis_new(&redis_write_ep, redis_write_db,
redis_write_auth, ANY_REDIS_ROLE, no_redis_required,
redis_allowed_errors, redis_disable_time, redis_cmd_timeout);
redis_allowed_errors, redis_disable_time, redis_cmd_timeout, redis_connect_timeout);
if (!mc.redis_write)
die("Cannot start up without running Redis %s write database! See also NO_REDIS_REQUIRED parameter.",
endpoint_print_buf(&redis_write_ep));
@ -594,11 +596,11 @@ no_kernel:
mc.redis = redis_new(&redis_ep, redis_db, redis_auth,
mc.redis_write ? ANY_REDIS_ROLE : MASTER_REDIS_ROLE,
no_redis_required, redis_allowed_errors, redis_disable_time,
redis_cmd_timeout);
redis_cmd_timeout, redis_connect_timeout);
mc.redis_notify = redis_new(&redis_ep, redis_db, redis_auth,
mc.redis_write ? ANY_REDIS_ROLE : MASTER_REDIS_ROLE,
no_redis_required, redis_allowed_errors, redis_disable_time,
redis_cmd_timeout);
redis_cmd_timeout, redis_connect_timeout);
if (!mc.redis || !mc.redis_notify)
die("Cannot start up without running Redis %s database! See also NO_REDIS_REQUIRED parameter.",
endpoint_print_buf(&redis_ep));


+ 6
- 4
daemon/redis.c View File

@ -174,8 +174,8 @@ static int redis_connect(struct redis *r, int wait) {
redisFree(r->ctx);
r->ctx = NULL;
tv.tv_sec = 1;
tv.tv_usec = 0;
tv.tv_sec = (int) r->connect_timeout / 1000;
tv.tv_usec = (int) (r->connect_timeout % 1000) * 1000;
r->ctx = redisConnectWithTimeout(r->host, r->endpoint.port, tv);
if (!r->ctx)
@ -639,7 +639,7 @@ void redis_notify_loop(void *d) {
struct redis *redis_new(const endpoint_t *ep, int db, const char *auth,
enum redis_role role, int no_redis_required, int redis_allowed_errors,
int redis_disable_time, int redis_cmd_timeout) {
int redis_disable_time, int redis_cmd_timeout,int redis_connect_timeout) {
struct redis *r;
r = g_slice_alloc0(sizeof(*r));
@ -655,6 +655,7 @@ struct redis *redis_new(const endpoint_t *ep, int db, const char *auth,
r->restore_tick = 0;
r->consecutive_errors = 0;
r->cmd_timeout = redis_cmd_timeout;
r->connect_timeout = redis_connect_timeout;
mutex_init(&r->lock);
if (redis_connect(r, 10)) {
@ -1696,7 +1697,8 @@ int redis_restore(struct callmaster *m, struct redis *r) {
g_queue_push_tail(&ctx.r_q,
redis_new(&r->endpoint, r->db, r->auth, r->role,
r->no_redis_required, r->allowed_errors,
r->disable_time,r->cmd_timeout));
r->disable_time,r->cmd_timeout,
r->connect_timeout));
gtp = g_thread_pool_new(restore_thread, &ctx, m->conf.redis_num_threads, TRUE, NULL);
for (i = 0; i < calls->elements; i++) {


+ 2
- 1
daemon/redis.h View File

@ -66,6 +66,7 @@ struct redis {
int disable_time;
time_t restore_tick;
int cmd_timeout;
int connect_timeout;
};
struct redis_hash {
@ -97,7 +98,7 @@ INLINE gboolean g_hash_table_insert_check(GHashTable *h, gpointer k, gpointer v)
void redis_notify_loop(void *d);
struct redis *redis_new(const endpoint_t *, int, const char *, enum redis_role, int, int, int, int);
struct redis *redis_new(const endpoint_t *, int, const char *, enum redis_role, int, int, int, int, int);
int redis_restore(struct callmaster *, struct redis *);
void redis_update(struct call *, struct redis *);
void redis_update_onekey(struct call *c, struct redis *r);


+ 1
- 0
etc/rtpengine.sample.conf View File

@ -44,6 +44,7 @@ port-max = 50000
# redis-allowed-errors = -1
# redis-disable-time = 10
# redis-cmd-timeout = 0
# redis-connect-timeout = 1000
# b2b-url = http://127.0.0.1:8090/
# xmlrpc-format = 0


Loading…
Cancel
Save