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.
  • Loading branch information
RoadRunnr authored and vkatsuba committed Jun 4, 2021
1 parent 4f42862 commit c01c38a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 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
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -602,7 +602,7 @@ rate_limit(_Config) ->
CCRt = CollectFun('CCR-Terminate', SRefs, #{}),

%% make sure to refill the token buckets, so that the following tests don't fail
ct:sleep(1100),
ct:sleep(2500),

?match(#{ok := OkayI, {error,rate_limit} := LimitI}
when OkayI >= 40 andalso
Expand Down

0 comments on commit c01c38a

Please sign in to comment.