Skip to content

Commit 31dc28a

Browse files
InterLinked1jcolp
authored andcommitted
res_pjsip_outbound_registration: Make max random delay configurable.
Currently, PJSIP will randomly wait up to 10 seconds for each outbound registration's initial attempt. The reason for this is to avoid having all outbound registrations attempt to register simultaneously. This can create limitations with the test suite where we need to be able to receive inbound calls potentially within 10 seconds of starting up. For instance, we might register to another server and then try to receive a call through the registration, but if the registration hasn't happened yet, this will fail, and hence this inconsistent behavior can cause tests to fail. Ultimately, this requires a smaller random value because there may be no good reason to wait for up to 10 seconds in these circumstances. To address this, a new config option is introduced which makes this maximum delay configurable. This allows, for instance, this to be set to a very small value in test systems to ensure that registrations happen immediately without an unnecessary delay, and can be used more generally to control how "tight" the initial outbound registrations are. ASTERISK-29965 #close Change-Id: Iab989a8e94323e645f3a21cbb6082287c7b2f3fd
1 parent 5f0581c commit 31dc28a

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

configs/samples/pjsip.conf.sample

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,11 @@
13501350
; (default: "")
13511351
;outbound_proxy= ; Proxy through which to send registrations, a full SIP URI
13521352
; must be provided (default: "")
1353+
;max_random_initial_delay=10 ; Maximum random delay for initial registrations (default: 10)
1354+
; Generally it is a good idea to space out registrations
1355+
; to not overload the system. If you have a small number
1356+
; of registrations and need them to register more quickly,
1357+
; you can reduce this to a lower value.
13531358
;retry_interval=60 ; Interval in seconds between retries if outbound
13541359
; registration is unsuccessful (default: "60")
13551360
;forbidden_retry_interval=0 ; Interval used when receiving a 403 Forbidden
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""max_random_initial_delay
2+
3+
Revision ID: 18e0805d367f
4+
Revises: 0bee61aa9425
5+
Create Date: 2022-05-18 17:07:02.626045
6+
7+
"""
8+
9+
# revision identifiers, used by Alembic.
10+
revision = '18e0805d367f'
11+
down_revision = '0bee61aa9425'
12+
13+
from alembic import op
14+
import sqlalchemy as sa
15+
16+
17+
def upgrade():
18+
op.add_column('ps_registrations', sa.Column('max_random_initial_delay', sa.Integer))
19+
20+
def downgrade():
21+
op.drop_column('ps_registrations', 'max_random_initial_delay')

res/res_pjsip_outbound_registration.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@
109109
<configOption name="outbound_proxy" default="">
110110
<synopsis>Full SIP URI of the outbound proxy used to send registrations</synopsis>
111111
</configOption>
112+
<configOption name="max_random_initial_delay" default="10">
113+
<synopsis>Maximum interval in seconds for which an initial registration may be randomly delayed</synopsis>
114+
<description>
115+
<para>By default, registrations are randomly delayed by a small amount to prevent
116+
too many registrations from being made simultaneously.</para>
117+
<para>Depending on your system usage, it may be desirable to set this to a smaller
118+
or larger value to have fine grained control over the size of this random delay.</para>
119+
</description>
120+
</configOption>
112121
<configOption name="retry_interval" default="60">
113122
<synopsis>Interval in seconds between retries if outbound registration is unsuccessful</synopsis>
114123
</configOption>
@@ -319,6 +328,8 @@ struct sip_outbound_registration {
319328
);
320329
/*! \brief Requested expiration time */
321330
unsigned int expiration;
331+
/*! \brief Maximum random initial delay interval for initial registrations */
332+
unsigned int max_random_initial_delay;
322333
/*! \brief Interval at which retries should occur for temporal responses */
323334
unsigned int retry_interval;
324335
/*! \brief Interval at which retries should occur for permanent responses */
@@ -1711,6 +1722,7 @@ static int sip_outbound_registration_perform(void *data)
17111722
struct sip_outbound_registration_state *state = data;
17121723
struct sip_outbound_registration *registration = ao2_bump(state->registration);
17131724
size_t i;
1725+
int max_delay;
17141726

17151727
/* Just in case the client state is being reused for this registration, free the auth information */
17161728
ast_sip_auth_vector_destroy(&state->client_state->outbound_auths);
@@ -1731,10 +1743,12 @@ static int sip_outbound_registration_perform(void *data)
17311743
state->client_state->support_path = registration->support_path;
17321744
state->client_state->support_outbound = registration->support_outbound;
17331745
state->client_state->auth_rejection_permanent = registration->auth_rejection_permanent;
1746+
max_delay = registration->max_random_initial_delay;
17341747

17351748
pjsip_regc_update_expires(state->client_state->client, registration->expiration);
17361749

1737-
schedule_registration(state->client_state, (ast_random() % 10) + 1);
1750+
/* n mod 0 is undefined, so don't let that happen */
1751+
schedule_registration(state->client_state, (max_delay ? ast_random() % max_delay : 0) + 1);
17381752

17391753
ao2_ref(registration, -1);
17401754
ao2_ref(state, -1);
@@ -2546,6 +2560,7 @@ static int load_module(void)
25462560
ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "transport", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct sip_outbound_registration, transport));
25472561
ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "outbound_proxy", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct sip_outbound_registration, outbound_proxy));
25482562
ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "expiration", "3600", OPT_UINT_T, 0, FLDSET(struct sip_outbound_registration, expiration));
2563+
ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "max_random_initial_delay", "10", OPT_UINT_T, 0, FLDSET(struct sip_outbound_registration, max_random_initial_delay));
25492564
ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "retry_interval", "60", OPT_UINT_T, 0, FLDSET(struct sip_outbound_registration, retry_interval));
25502565
ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "forbidden_retry_interval", "0", OPT_UINT_T, 0, FLDSET(struct sip_outbound_registration, forbidden_retry_interval));
25512566
ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "fatal_retry_interval", "0", OPT_UINT_T, 0, FLDSET(struct sip_outbound_registration, fatal_retry_interval));

0 commit comments

Comments
 (0)