res_pjsip: disable multi domain to improve realtime performace
authorAlexei Gradinari <alex2grad@gmail.com>
Fri, 15 Apr 2016 16:59:42 +0000 (12:59 -0400)
committerRichard Mudgett <rmudgett@digium.com>
Wed, 27 Apr 2016 15:58:43 +0000 (10:58 -0500)
This patch added new global pjsip option 'disable_multi_domain'.
Disabling Multi Domain can improve Realtime performance by reducing
number of database requests.

ASTERISK-25930 #close

Change-Id: I2e7160f3aae68475d52742107949a799aa2c7dc7

CHANGES
configs/samples/pjsip.conf.sample
contrib/ast-db-manage/config/versions/8d478ab86e29_pjsip_add_disable_multi_domain.py [new file with mode: 0644]
include/asterisk/res_pjsip.h
res/res_pjsip.c
res/res_pjsip/config_global.c
res/res_pjsip_endpoint_identifier_anonymous.c
res/res_pjsip_endpoint_identifier_user.c

diff --git a/CHANGES b/CHANGES
index e7f0656..4844f85 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -279,6 +279,12 @@ res_parking:
    for these variables.  The indefinite inheritance is also recommended
    for the PARKINGEXTEN variable.
 
+res_pjsip
+------------------
+ * Added new global option (disable_multi_domain) to pjsip.
+   Disabling Multi Domain can improve realtime performace by reducing
+   number of database requsts.
+
 chan_pjsip
 ------------------
  * Added 'pjsip show channelstats' CLI command.
index 94d1792..6a08edc 100644 (file)
                         ; (default: "0")
 ;contact_expiration_check_interval=30
                         ; The interval (in seconds) to check for expired contacts.
+;disable_multi_domain=no
+                       ; Disable Multi Domain support.
+                       ; If disabled it can improve realtime performace by reducing
+                       ; number of database requsts
+                       ; (default: "no")
 ;endpoint_identifier_order=ip,username,anonymous
             ; The order by which endpoint identifiers are given priority.
             ; Identifier names are derived from res_pjsip_endpoint_identifier_*
diff --git a/contrib/ast-db-manage/config/versions/8d478ab86e29_pjsip_add_disable_multi_domain.py b/contrib/ast-db-manage/config/versions/8d478ab86e29_pjsip_add_disable_multi_domain.py
new file mode 100644 (file)
index 0000000..a782685
--- /dev/null
@@ -0,0 +1,31 @@
+"""pjsip_add_disable_multi_domain
+
+Revision ID: 8d478ab86e29
+Revises: 1c688d9a003c
+Create Date: 2016-04-15 11:41:26.988997
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '8d478ab86e29'
+down_revision = '1c688d9a003c'
+
+from alembic import op
+import sqlalchemy as sa
+from sqlalchemy.dialects.postgresql import ENUM
+
+YESNO_NAME = 'yesno_values'
+YESNO_VALUES = ['yes', 'no']
+
+def upgrade():
+    ############################# Enums ##############################
+
+    # yesno_values have already been created, so use postgres enum object
+    # type to get around "already created" issue - works okay with mysql
+    yesno_values = ENUM(*YESNO_VALUES, name=YESNO_NAME, create_type=False)
+
+    op.add_column('ps_globals', sa.Column('disable_multi_domain', yesno_values))
+
+
+def downgrade():
+    op.drop_column('ps_globals', 'disable_multi_domain')
index 1bfae66..d06fce9 100644 (file)
@@ -2212,6 +2212,13 @@ unsigned int ast_sip_get_keep_alive_interval(void);
  */
 unsigned int ast_sip_get_contact_expiration_check_interval(void);
 
+/*!
+ * \brief Retrieve the system setting 'disable multi domain'.
+ * \since 13.9.0
+ *
+ * \retval non zero if disable multi domain.
+ */
+unsigned int ast_sip_get_disable_multi_domain(void);
 
 /*!
  * \brief Retrieve the system max initial qualify time.
index d12951c..428e58d 100644 (file)
                                <configOption name="contact_expiration_check_interval" default="30">
                                        <synopsis>The interval (in seconds) to check for expired contacts.</synopsis>
                                </configOption>
+                               <configOption name="disable_multi_domain" default="no">
+                                       <synopsis>Disable Multi Domain support</synopsis>
+                                       <description><para>
+                                               If disabled it can improve realtime performace by reducing number of database requsts.
+                                       </para></description>
+                               </configOption>
                                <configOption name="max_initial_qualify_time" default="0">
                                        <synopsis>The maximum amount of time from startup that qualifies should be attempted on all contacts.
                                        If greater than the qualify_frequency for an aor, qualify_frequency will be used instead.</synopsis>
index 8348a1e..ccfec54 100644 (file)
@@ -37,6 +37,7 @@
 #define DEFAULT_FROM_USER "asterisk"
 #define DEFAULT_REGCONTEXT ""
 #define DEFAULT_CONTACT_EXPIRATION_CHECK_INTERVAL 30
+#define DEFAULT_DISABLE_MULTI_DOMAIN 0
 #define DEFAULT_VOICEMAIL_EXTENSION ""
 
 static char default_useragent[256];
@@ -64,6 +65,8 @@ struct global_config {
        unsigned int max_initial_qualify_time;
        /* The interval at which to check for expired contacts */
        unsigned int contact_expiration_check_interval;
+       /*! Nonzero to disable multi domain support */
+       unsigned int disable_multi_domain;
 };
 
 static void global_destructor(void *obj)
@@ -222,6 +225,21 @@ unsigned int ast_sip_get_contact_expiration_check_interval(void)
        return interval;
 }
 
+unsigned int ast_sip_get_disable_multi_domain(void)
+{
+       unsigned int disable_multi_domain;
+       struct global_config *cfg;
+
+       cfg = get_global_cfg();
+       if (!cfg) {
+               return DEFAULT_DISABLE_MULTI_DOMAIN;
+       }
+
+       disable_multi_domain = cfg->disable_multi_domain;
+       ao2_ref(cfg, -1);
+       return disable_multi_domain;
+}
+
 unsigned int ast_sip_get_max_initial_qualify_time(void)
 {
        unsigned int time;
@@ -373,6 +391,8 @@ int ast_sip_initialize_sorcery_global(void)
        ast_sorcery_object_field_register(sorcery, "global", "contact_expiration_check_interval",
                __stringify(DEFAULT_CONTACT_EXPIRATION_CHECK_INTERVAL),
                OPT_UINT_T, 0, FLDSET(struct global_config, contact_expiration_check_interval));
+       ast_sorcery_object_field_register(sorcery, "global", "disable_multi_domain", "no",
+               OPT_BOOL_T, 1, FLDSET(struct global_config, disable_multi_domain));
 
        if (ast_sorcery_instance_observer_add(sorcery, &observer_callbacks_global)) {
                return -1;
index d9d7e03..a529466 100644 (file)
@@ -69,28 +69,30 @@ static struct ast_sip_endpoint *anonymous_identify(pjsip_rx_data *rdata)
                return NULL;
        }
 
-       /* Attempt to find the endpoint given the name and domain provided */
-       snprintf(id, sizeof(id), "anonymous@%s", domain_name);
-       if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {
-               goto done;
-       }
-
-       /* See if an alias exists for the domain provided */
-       if ((alias = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "domain_alias", domain_name))) {
-               snprintf(id, sizeof(id), "anonymous@%s", alias->domain);
+       if (!ast_sip_get_disable_multi_domain()) {
+               /* Attempt to find the endpoint given the name and domain provided */
+               snprintf(id, sizeof(id), "anonymous@%s", domain_name);
                if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {
                        goto done;
                }
-       }
 
-       /* See if the transport this came in on has a provided domain */
-       if ((transport_states = ast_sip_get_transport_states())
-               && (transport_state = ao2_callback(transport_states, 0, find_transport_state_in_use, rdata))
-               && (transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", transport_state->id))
-               && !ast_strlen_zero(transport->domain)) {
-               snprintf(id, sizeof(id), "anonymous@%s", transport->domain);
-               if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {
-                       goto done;
+               /* See if an alias exists for the domain provided */
+               if ((alias = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "domain_alias", domain_name))) {
+                       snprintf(id, sizeof(id), "anonymous@%s", alias->domain);
+                       if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {
+                               goto done;
+                       }
+               }
+
+               /* See if the transport this came in on has a provided domain */
+               if ((transport_states = ast_sip_get_transport_states())
+                       && (transport_state = ao2_callback(transport_states, 0, find_transport_state_in_use, rdata))
+                       && (transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", transport_state->id))
+                       && !ast_strlen_zero(transport->domain)) {
+                       snprintf(id, sizeof(id), "anonymous@%s", transport->domain);
+                       if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {
+                               goto done;
+                       }
                }
        }
 
index 9a2bc89..12af2ed 100644 (file)
@@ -69,28 +69,30 @@ static struct ast_sip_endpoint *username_identify(pjsip_rx_data *rdata)
                return NULL;
        }
 
-       /* Attempt to find the endpoint given the name and domain provided */
-       snprintf(id, sizeof(id), "%s@%s", endpoint_name, domain_name);
-       if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {
-               goto done;
-       }
-
-       /* See if an alias exists for the domain provided */
-       if ((alias = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "domain_alias", domain_name))) {
-               snprintf(id, sizeof(id), "%s@%s", endpoint_name, alias->domain);
+       if (!ast_sip_get_disable_multi_domain()) {
+               /* Attempt to find the endpoint given the name and domain provided */
+               snprintf(id, sizeof(id), "%s@%s", endpoint_name, domain_name);
                if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {
                        goto done;
                }
-       }
 
-       /* See if the transport this came in on has a provided domain */
-       if ((transport_states = ast_sip_get_transport_states())
-               && (transport_state = ao2_callback(transport_states, 0, find_transport_state_in_use, rdata))
-               && (transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", transport_state->id))
-               && !ast_strlen_zero(transport->domain)) {
-               snprintf(id, sizeof(id), "anonymous@%s", transport->domain);
-               if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {
-                       goto done;
+               /* See if an alias exists for the domain provided */
+               if ((alias = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "domain_alias", domain_name))) {
+                       snprintf(id, sizeof(id), "%s@%s", endpoint_name, alias->domain);
+                       if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {
+                               goto done;
+                       }
+               }
+
+               /* See if the transport this came in on has a provided domain */
+               if ((transport_states = ast_sip_get_transport_states())
+                       && (transport_state = ao2_callback(transport_states, 0, find_transport_state_in_use, rdata))
+                       && (transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", transport_state->id))
+                       && !ast_strlen_zero(transport->domain)) {
+                       snprintf(id, sizeof(id), "anonymous@%s", transport->domain);
+                       if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {
+                               goto done;
+                       }
                }
        }