[asterisk-commits] kmoore: branch 13 r429128 - in /branches/13: ./ res/res_pjsip/pjsip_options.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Dec 9 08:00:54 CST 2014


Author: kmoore
Date: Tue Dec  9 08:00:50 2014
New Revision: 429128

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=429128
Log:
PJSIP: Stagger outbound qualifies

This change staggers initiation of outbound qualify (OPTIONS) attempts
to reduce instantaneous server load and prevent network congestion.

Review: https://reviewboard.asterisk.org/r/4246/
ASTERISK-24342 #close
Reported by: Richard Mudgett
........

Merged revisions 429127 from http://svn.asterisk.org/svn/asterisk/branches/12

Modified:
    branches/13/   (props changed)
    branches/13/res/res_pjsip/pjsip_options.c

Propchange: branches/13/
------------------------------------------------------------------------------
Binary property 'branch-12-merged' - no diff available.

Modified: branches/13/res/res_pjsip/pjsip_options.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/res/res_pjsip/pjsip_options.c?view=diff&rev=429128&r1=429127&r2=429128
==============================================================================
--- branches/13/res/res_pjsip/pjsip_options.c (original)
+++ branches/13/res/res_pjsip/pjsip_options.c Tue Dec  9 08:00:50 2014
@@ -418,14 +418,14 @@
 	 * up the data object ref between self deletion and an external
 	 * deletion.
 	 */
-	return 1;
+	return data->contact->qualify_frequency * 1000;
 }
 
 /*!
  * \internal
  * \brief Set up a scheduled qualify contact check.
  */
-static void schedule_qualify(struct ast_sip_contact *contact)
+static void schedule_qualify(struct ast_sip_contact *contact, int initial_interval)
 {
 	struct sched_data *data;
 
@@ -437,8 +437,8 @@
 	ast_assert(contact->qualify_frequency != 0);
 
 	ao2_t_ref(data, +1, "Ref for qualify_contact_sched() scheduler entry");
-	data->id = ast_sched_add_variable(sched, contact->qualify_frequency * 1000,
-		qualify_contact_sched, data, 0);
+	data->id = ast_sched_add_variable(sched, initial_interval,
+		qualify_contact_sched, data, 1);
 	if (data->id < 0) {
 		ao2_t_ref(data, -1, "Cleanup failed scheduler add");
 		ast_log(LOG_ERROR, "Unable to schedule qualify for contact %s\n",
@@ -482,7 +482,7 @@
 			ao2_ref(contact, -1);
 		}
 
-		schedule_qualify(contact);
+		schedule_qualify(contact, contact->qualify_frequency * 1000);
 	} else {
 		delete_contact_status(contact);
 	}
@@ -951,11 +951,16 @@
 {
 	struct ast_sip_contact *contact = obj;
 	struct ast_sip_aor *aor = arg;
+	int initial_interval;
 
 	contact->qualify_frequency = aor->qualify_frequency;
 	contact->authenticate_qualify = aor->authenticate_qualify;
 
-	qualify_and_schedule(contact);
+	/* Delay initial qualification by a random fraction of the specified interval */
+	initial_interval = contact->qualify_frequency * 1000;
+	initial_interval = (int)(initial_interval * ast_random_double());
+
+	schedule_qualify(contact, initial_interval);
 
 	return 0;
 }




More information about the asterisk-commits mailing list