[Asterisk-code-review] res pjsip: Cache global config options. (asterisk[13])

Joshua Colp asteriskteam at digium.com
Sat Aug 27 05:03:14 CDT 2016


Joshua Colp has submitted this change and it was merged.

Change subject: res_pjsip: Cache global config options.
......................................................................


res_pjsip: Cache global config options.

We may check a global config option hundreds of times a second or more.
Asking sorcery for the global configuration from the config files backend
involves several allocations and container traversals.  Using realtime
without a memory cache is a lot worse because you have to lookup in the
realtime database each time to reconstitute the sorcery object.  With a
memory cache for realtime, there is about the same amount of overhead as
for config files.  Either way, it is still fairly expensive to access the
sorcery object that much.

* Cache the global config options so we can access them faster.  You must
now always perform a res_pjsip reload to change the global options.

Change-Id: Ice16c7a4cbca4614da344aaea21a072b86263ef7
---
M CHANGES
M res/res_pjsip/config_global.c
2 files changed, 20 insertions(+), 12 deletions(-)

Approvals:
  Mark Michelson: Looks good to me, approved
  George Joseph: Looks good to me, but someone else must approve
  Joshua Colp: Verified



diff --git a/CHANGES b/CHANGES
index 1dfd445..27643f2 100644
--- a/CHANGES
+++ b/CHANGES
@@ -43,6 +43,12 @@
    when set will override the default user set on Contact headers in outgoing
    requests.
 
+ * If you are using a sorcery realtime backend to store global res_pjsip
+   options (ps_globals table) then you now have to do a res_pjsip reload for
+   changes to these options to take effect.  If you are using pjsip.conf to
+   configure these options then you already had to do a reload after making
+   changes.
+
 ------------------------------------------------------------------------------
 --- Functionality changes from Asterisk 13.10.0 to Asterisk 13.11.0 ----------
 ------------------------------------------------------------------------------
diff --git a/res/res_pjsip/config_global.c b/res/res_pjsip/config_global.c
index 975c5ee..1d0c11c 100644
--- a/res/res_pjsip/config_global.c
+++ b/res/res_pjsip/config_global.c
@@ -48,6 +48,15 @@
 #define DEFAULT_MWI_TPS_QUEUE_LOW -1
 #define DEFAULT_MWI_DISABLE_INITIAL_UNSOLICITED 0
 
+/*!
+ * \brief Cached global config object
+ *
+ * \details
+ * Cached so we don't have to keep asking sorcery for the config.
+ * We could ask for it hundreds of times a second if not more.
+ */
+static AO2_GLOBAL_OBJ_STATIC(global_cfg);
+
 static char default_useragent[256];
 
 struct global_config {
@@ -135,23 +144,14 @@
 	ast_sip_add_global_request_header("Max-Forwards", max_forwards, 1);
 	ast_sip_add_global_request_header("User-Agent", cfg->useragent, 1);
 	ast_sip_add_global_response_header("Server", cfg->useragent, 1);
+
+	ao2_t_global_obj_replace_unref(global_cfg, cfg, "Applying global settings");
 	return 0;
 }
 
 static struct global_config *get_global_cfg(void)
 {
-	struct global_config *cfg;
-	struct ao2_container *globals;
-
-	globals = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "global",
-		AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
-	if (!globals) {
-		return NULL;
-	}
-
-	cfg = ao2_find(globals, NULL, 0);
-	ao2_ref(globals, -1);
-	return cfg;
+	return ao2_global_obj_ref(global_cfg);
 }
 
 char *ast_sip_global_default_outbound_endpoint(void)
@@ -462,6 +462,8 @@
 
 	ast_sorcery_instance_observer_remove(sorcery, &observer_callbacks_global);
 
+	ao2_t_global_obj_release(global_cfg, "Module is unloading");
+
 	return 0;
 }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ice16c7a4cbca4614da344aaea21a072b86263ef7
Gerrit-PatchSet: 2
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-code-review mailing list