[Asterisk-code-review] res pjsip: disable multi domain to improve realtime performace (asterisk[certified/13.8])

George Joseph asteriskteam at digium.com
Fri Apr 29 12:52:00 CDT 2016


George Joseph has uploaded a new change for review.

  https://gerrit.asterisk.org/2734

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, 121 insertions(+), 38 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/34/2734/1

diff --git a/CHANGES b/CHANGES
index 29b1b76..e58ff82 100644
--- a/CHANGES
+++ b/CHANGES
@@ -9,6 +9,16 @@
 ==============================================================================
 
 ------------------------------------------------------------------------------
+--- Functionality changes from Asterisk 13.8.0 to Asterisk 13.9.0 ------------
+------------------------------------------------------------------------------
+
+res_pjsip
+------------------
+ * Added new global option (disable_multi_domain) to pjsip.
+   Disabling Multi Domain can improve realtime performace by reducing
+   number of database requsts.
+
+------------------------------------------------------------------------------
 --- Functionality changes from Asterisk 13.7.0 to Asterisk 13.8.0 ------------
 ------------------------------------------------------------------------------
 
diff --git a/configs/samples/pjsip.conf.sample b/configs/samples/pjsip.conf.sample
index ebbd199..f87a671 100644
--- a/configs/samples/pjsip.conf.sample
+++ b/configs/samples/pjsip.conf.sample
@@ -886,6 +886,11 @@
 ;keep_alive_interval=20 ; The interval (in seconds) at which to send keepalive
                         ; messages on all active connection-oriented transports
                         ; (default: "0")
+;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..8c4269c
--- /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: 3bcc0b5bc2c9
+Create Date: 2016-04-15 11:41:26.988997
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '8d478ab86e29'
+down_revision = '3bcc0b5bc2c9'
+
+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 3901cf7..f56eb7b 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -2193,6 +2193,14 @@
 unsigned int ast_sip_get_keep_alive_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.
  *
  * \retval the maximum initial qualify time.
diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index 752491c..37d52df 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -1279,6 +1279,12 @@
 				<configOption name="keep_alive_interval" default="0">
 					<synopsis>The interval (in seconds) to send keepalives to active connection-oriented transports.</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 3d88ffc..ca608dc 100644
--- a/res/res_pjsip/config_global.c
+++ b/res/res_pjsip/config_global.c
@@ -36,6 +36,7 @@
 #define DEFAULT_MAX_INITIAL_QUALIFY_TIME 0
 #define DEFAULT_FROM_USER "asterisk"
 #define DEFAULT_REGCONTEXT ""
+#define DEFAULT_DISABLE_MULTI_DOMAIN 0
 
 static char default_useragent[256];
 
@@ -58,6 +59,8 @@
 	unsigned int keep_alive_interval;
 	/* The maximum time for all contacts to be qualified at startup */
 	unsigned int max_initial_qualify_time;
+	/*! Nonzero to disable multi domain support */
+	unsigned int disable_multi_domain;
 };
 
 static void global_destructor(void *obj)
@@ -184,6 +187,21 @@
 	interval = cfg->keep_alive_interval;
 	ao2_ref(cfg, -1);
 	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)
@@ -330,8 +348,9 @@
 	ast_sorcery_object_field_register(sorcery, "global", "default_from_user", DEFAULT_FROM_USER,
 		OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, default_from_user));
 	ast_sorcery_object_field_register(sorcery, "global", "regcontext", DEFAULT_REGCONTEXT,
-                OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, regcontext));
-
+		OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, regcontext));
+	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 b39c863..b931338 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 aa6d398..10b08af 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/2734
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2e7160f3aae68475d52742107949a799aa2c7dc7
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: certified/13.8
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Alexei Gradinari <alex2grad at gmail.com>



More information about the asterisk-code-review mailing list