Skip to content

Commit

Permalink
make the session init more asynchronous
Browse files Browse the repository at this point in the history
The session init phase can take significant time. This would cause
a backlog in the session supervisor when many sessions where started
at once. This becomes visible as a significant grows of the mailbox
of the supervisor process.

Also increase the outstanding requests limit for the rate limit
test. The inproved startup time also means the traffic in that
test will be much more bursty and will run into that limit.
  • Loading branch information
RoadRunnr committed May 31, 2021
1 parent 4a62e35 commit 49dd3e7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/ergw_aaa_session.erl
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ event(Session, Event, EvOpts, SessionOpts) when is_map(SessionOpts) ->
%%===================================================================

start_link(Owner, SessionData) ->
Opts = [{hibernate_after, 500},
{spawn_opt,[{fullsweep_after, 0}]}],
gen_statem:start_link(?MODULE, [Owner, SessionData], Opts).
proc_lib:start_link(?MODULE, init, [[Owner, SessionData]], infinity, [{fullsweep_after, 0}]).

invoke_compat_async(Session, SessionOpts, Procedure) ->
case invoke(Session, SessionOpts, Procedure, #{async => true}) of
Expand Down Expand Up @@ -170,6 +168,7 @@ callback_mode() -> handle_event_function.

init([Owner, SessionOpts]) ->
process_flag(trap_exit, true),
proc_lib:init_ack({ok, self()}),

AppId = maps:get('AAA-Application-Id', SessionOpts, default),
SessionId = ergw_aaa_session_seq:inc(AppId),
Expand All @@ -190,16 +189,16 @@ init([Owner, SessionOpts]) ->
ergw_aaa_session_reg:register(SessionId),
ergw_aaa_session_reg:register(DiamSessionId),

Data = #data{
Data0 = #data{
owner = Owner,
owner_monitor = MonRef,
application = AppId,
handlers = #{},
session = DefaultSessionOpts
},
State = #state{},
{Reply, DataOut, _Events} = exec(init, SessionOpts, #{}, Data),
{Reply, State, DataOut}.
{ok, Data, _Events} = exec(init, SessionOpts, #{}, Data0),
gen_statem:enter_loop(?MODULE, [{hibernate_after, 500}], State, Data).

handle_event({call, From}, get, _State, Data) ->
{keep_state_and_data, [{reply, From, Data#data.session}]};
Expand Down
2 changes: 1 addition & 1 deletion test/diameter_Gy_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

-define(CONFIG,
#{rate_limits =>
#{default => #{outstanding_requests => 1, rate => 10}},
#{default => #{outstanding_requests => 10, rate => 10}},
functions => ?DIAMETER_FUNCTION,
handlers =>
#{ergw_aaa_static => ?STATIC_CONFIG,
Expand Down

0 comments on commit 49dd3e7

Please sign in to comment.