提交 a7465e6c authored 作者: Chris Rienzo's avatar Chris Rienzo

FS-9052 [mod_hiredis] add connection pooling, improve dropped connection…

FS-9052 [mod_hiredis] add connection pooling, improve dropped connection resiliency, and allow 0.10.0 of hiredis for CentOS 6.
上级 93d45b3b
...@@ -1406,7 +1406,7 @@ PKG_CHECK_MODULES([SMPP34], [libsmpp34 >= 1.10],[ ...@@ -1406,7 +1406,7 @@ PKG_CHECK_MODULES([SMPP34], [libsmpp34 >= 1.10],[
AM_CONDITIONAL([HAVE_SMPP34],[true])],[ AM_CONDITIONAL([HAVE_SMPP34],[true])],[
AC_MSG_RESULT([no]); AM_CONDITIONAL([HAVE_SMPP34],[false])]) AC_MSG_RESULT([no]); AM_CONDITIONAL([HAVE_SMPP34],[false])])
PKG_CHECK_MODULES([HIREDIS], [hiredis >= 0.11.0],[ PKG_CHECK_MODULES([HIREDIS], [hiredis >= 0.10.0],[
AM_CONDITIONAL([HAVE_HIREDIS],[true])],[ AM_CONDITIONAL([HAVE_HIREDIS],[true])],[
AC_MSG_RESULT([no]); AM_CONDITIONAL([HAVE_HIREDIS],[false])]) AC_MSG_RESULT([no]); AM_CONDITIONAL([HAVE_HIREDIS],[false])])
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
* Contributor(s): * Contributor(s):
* *
* William King <william.king@quentustech.com> * William King <william.king@quentustech.com>
* Christopher Rienzo <chris.rienzo@citrix.com>
* *
* mod_hiredis.c -- redis client built using the C client library hiredis * mod_hiredis.c -- redis client built using the C client library hiredis
* *
...@@ -67,7 +68,7 @@ switch_status_t mod_hiredis_do_config() ...@@ -67,7 +68,7 @@ switch_status_t mod_hiredis_do_config()
if ( (connections = switch_xml_child(profile, "connections")) != NULL) { if ( (connections = switch_xml_child(profile, "connections")) != NULL) {
for (connection = switch_xml_child(connections, "connection"); connection; connection = connection->next) { for (connection = switch_xml_child(connections, "connection"); connection; connection = connection->next) {
char *host = NULL, *password = NULL; char *host = NULL, *password = NULL;
uint32_t port = 0, timeout_ms = 0; uint32_t port = 0, timeout_ms = 0, max_connections = 0;
for (param = switch_xml_child(connection, "param"); param; param = param->next) { for (param = switch_xml_child(connection, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name"); char *var = (char *) switch_xml_attr_soft(param, "name");
...@@ -75,15 +76,17 @@ switch_status_t mod_hiredis_do_config() ...@@ -75,15 +76,17 @@ switch_status_t mod_hiredis_do_config()
host = (char *) switch_xml_attr_soft(param, "value"); host = (char *) switch_xml_attr_soft(param, "value");
} else if ( !strncmp(var, "port", 4) ) { } else if ( !strncmp(var, "port", 4) ) {
port = atoi(switch_xml_attr_soft(param, "value")); port = atoi(switch_xml_attr_soft(param, "value"));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "hiredis: adding conn[%u == %s]\n", port, switch_xml_attr_soft(param, "value")); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "hiredis: adding conn[%u == %s]\n", port, switch_xml_attr_soft(param, "value"));
} else if ( !strncmp(var, "timeout_ms", 10) ) { } else if ( !strncmp(var, "timeout_ms", 10) ) {
timeout_ms = atoi(switch_xml_attr_soft(param, "value")); timeout_ms = atoi(switch_xml_attr_soft(param, "value"));
} else if ( !strncmp(var, "password", 8) ) { } else if ( !strncmp(var, "password", 8) ) {
password = (char *) switch_xml_attr_soft(param, "value"); password = (char *) switch_xml_attr_soft(param, "value");
} else if ( !strncmp(var, "max-connections", 15) ) {
max_connections = atoi(switch_xml_attr_soft(param, "value"));
} }
} }
if ( hiredis_profile_connection_add(new_profile, host, password, port, timeout_ms) == SWITCH_STATUS_SUCCESS) { if ( hiredis_profile_connection_add(new_profile, host, password, port, timeout_ms, max_connections) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created profile[%s]\n", name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created profile[%s]\n", name);
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to create profile[%s]\n", name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to create profile[%s]\n", name);
......
...@@ -103,7 +103,7 @@ SWITCH_STANDARD_API(raw_api) ...@@ -103,7 +103,7 @@ SWITCH_STANDARD_API(raw_api)
} }
if ( hiredis_profile_execute_sync(profile, data, &response) != SWITCH_STATUS_SUCCESS) { if ( hiredis_profile_execute_sync(profile, data, &response) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "hiredis: profile[%s] error executing [%s] reason:[%s]\n", input, data, response); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "hiredis: profile[%s] error executing [%s] reason:[%s]\n", input, data, response ? response : "");
switch_goto_status(SWITCH_STATUS_GENERR, done); switch_goto_status(SWITCH_STATUS_GENERR, done);
} }
......
...@@ -13,12 +13,19 @@ typedef struct mod_hiredis_global_s { ...@@ -13,12 +13,19 @@ typedef struct mod_hiredis_global_s {
extern mod_hiredis_global_t mod_hiredis_globals; extern mod_hiredis_global_t mod_hiredis_globals;
typedef struct mod_hiredis_context_s {
struct hiredis_connection_s *connection;
redisContext *context;
} hiredis_context_t;
typedef struct hiredis_connection_s { typedef struct hiredis_connection_s {
char *host; char *host;
char *password; char *password;
uint32_t port; uint32_t port;
redisContext *context; switch_interval_time_t timeout_us;
struct timeval timeout; struct timeval timeout;
switch_memory_pool_t *pool;
switch_queue_t *context_pool;
struct hiredis_connection_s *next; struct hiredis_connection_s *next;
} hiredis_connection_t; } hiredis_connection_t;
...@@ -28,7 +35,6 @@ typedef struct hiredis_profile_s { ...@@ -28,7 +35,6 @@ typedef struct hiredis_profile_s {
char *name; char *name;
int debug; int debug;
hiredis_connection_t *conn;
hiredis_connection_t *conn_head; hiredis_connection_t *conn_head;
} hiredis_profile_t; } hiredis_profile_t;
...@@ -44,7 +50,7 @@ typedef struct hiredis_limit_pvt_s { ...@@ -44,7 +50,7 @@ typedef struct hiredis_limit_pvt_s {
switch_status_t mod_hiredis_do_config(); switch_status_t mod_hiredis_do_config();
switch_status_t hiredis_profile_create(hiredis_profile_t **new_profile, char *name, uint8_t port); switch_status_t hiredis_profile_create(hiredis_profile_t **new_profile, char *name, uint8_t port);
switch_status_t hiredis_profile_destroy(hiredis_profile_t **old_profile); switch_status_t hiredis_profile_destroy(hiredis_profile_t **old_profile);
switch_status_t hiredis_profile_connection_add(hiredis_profile_t *profile, char *host, char *password, uint32_t port, uint32_t timeout_ms); switch_status_t hiredis_profile_connection_add(hiredis_profile_t *profile, char *host, char *password, uint32_t port, uint32_t timeout_ms, uint32_t max_connections);
switch_status_t hiredis_profile_execute_sync(hiredis_profile_t *profile, const char *data, char **response); switch_status_t hiredis_profile_execute_sync(hiredis_profile_t *profile, const char *data, char **response);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论