[asterisk-commits] res pjsip: disable multi domain to improve realtime performace (asterisk[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Apr 27 12:45:11 CDT 2016


Joshua Colp has submitted this change and it was merged.

Change subject: res_pjsip: disable multi domain to improve realtime performace
......................................................................


res_pjsip: disable multi domain to improve realtime performace

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
---
M CHANGES
M configs/samples/pjsip.conf.sample
A contrib/ast-db-manage/config/versions/8d478ab86e29_pjsip_add_disable_multi_domain.py
M include/asterisk/res_pjsip.h
M res/res_pjsip.c
M res/res_pjsip/config_global.c
M res/res_pjsip_endpoint_identifier_anonymous.c
M res/res_pjsip_endpoint_identifier_user.c
8 files changed, 115 insertions(+), 36 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, approved; Verified



diff --git a/CHANGES b/CHANGES
index e7f0656..4844f85 100644
--- a/CHANGES
+++ b/CHANGES
@@ -279,6 +279,12 @@
    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.
diff --git a/configs/samples/pjsip.conf.sample b/configs/samples/pjsip.conf.sample
index 94d1792..6a08edc 100644
--- a/configs/samples/pjsip.conf.sample
+++ b/configs/samples/pjsip.conf.sample
@@ -907,6 +907,11 @@
                         ; (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
index 0000000..a782685
--- /dev/null
+++ b/contrib/ast-db-manage/config/versions/8d478ab86e29_pjsip_add_disable_multi_domain.py
@@ -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')
diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h
index 1bfae66..d06fce9 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -2212,6 +2212,13 @@
  */
 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.
diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index d12951c..428e58d 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -1294,6 +1294,12 @@
 				<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>
diff --git a/res/res_pjsip/config_global.c b/res/res_pjsip/config_global.c
index 8348a1e..ccfec54 100644
--- a/res/res_pjsip/config_global.c
+++ b/res/res_pjsip/config_global.c
@@ -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 @@
 	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 @@
 	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 @@
 	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;
diff --git a/res/res_pjsip_endpoint_identifier_anonymous.c b/res/res_pjsip_endpoint_identifier_anonymous.c
index d9d7e03..a529466 100644
--- a/res/res_pjsip_endpoint_identifier_anonymous.c
+++ b/res/res_pjsip_endpoint_identifier_anonymous.c
@@ -69,28 +69,30 @@
 		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;
+			}
 		}
 	}
 
diff --git a/res/res_pjsip_endpoint_identifier_user.c b/res/res_pjsip_endpoint_identifier_user.c
index 9a2bc89..12af2ed 100644
--- a/res/res_pjsip_endpoint_identifier_user.c
+++ b/res/res_pjsip_endpoint_identifier_user.c
@@ -69,28 +69,30 @@
 		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;
+			}
 		}
 	}
 

-- 
To view, visit https://gerrit.asterisk.org/2712
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2e7160f3aae68475d52742107949a799aa2c7dc7
Gerrit-PatchSet: 2
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Alexei Gradinari <alex2grad at gmail.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>



More information about the asterisk-commits mailing list