From 49dd3e7c82ec1ce0f7e9a3d223542d20ea570753 Mon Sep 17 00:00:00 2001 From: Andreas Schultz Date: Tue, 25 May 2021 12:11:25 +0200 Subject: [PATCH] make the session init more asynchronous 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. --- src/ergw_aaa_session.erl | 11 +++++------ test/diameter_Gy_SUITE.erl | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/ergw_aaa_session.erl b/src/ergw_aaa_session.erl index d3b7931..8990ea5 100644 --- a/src/ergw_aaa_session.erl +++ b/src/ergw_aaa_session.erl @@ -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 @@ -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), @@ -190,7 +189,7 @@ 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, @@ -198,8 +197,8 @@ init([Owner, SessionOpts]) -> 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}]}; diff --git a/test/diameter_Gy_SUITE.erl b/test/diameter_Gy_SUITE.erl index fd372e4..7d4ede4 100644 --- a/test/diameter_Gy_SUITE.erl +++ b/test/diameter_Gy_SUITE.erl @@ -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,