From d41bb9ea93aa22c4ede701cec08e88a4139eea0a Mon Sep 17 00:00:00 2001 From: SisMaker <1713699517@qq.com> Date: Sun, 21 Mar 2021 22:23:52 +0800 Subject: [PATCH] =?UTF-8?q?ft:=20=E4=BB=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/eRum.hrl | 3 +++ src/eRum_app.erl | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/eRum.hrl b/include/eRum.hrl index 50526f6..c7cd727 100644 --- a/include/eRum.hrl +++ b/include/eRum.hrl @@ -1,3 +1,6 @@ +%% 三元表达式 +-define(IIF(Cond, Ret1, Ret2), (case Cond of true -> Ret1; _ -> Ret2 end)). + %% 应用名字 -define(RumAppName, eRum). diff --git a/src/eRum_app.erl b/src/eRum_app.erl index 9e1503a..2ff1077 100644 --- a/src/eRum_app.erl +++ b/src/eRum_app.erl @@ -28,7 +28,7 @@ start(_StartType, _StartArgs) -> boot() -> %% Handle the default sink. - tryStartAsyncer(?RumDefSink, rumUtil:get_env(?RumAppName, asyncThreshold, undefined), rumUtil:get_env(?RumAppName, asyncThresholdWindow, undefined)), + tryStartAsyncMgr(?RumDefSink, rumUtil:get_env(?RumAppName, asyncThreshold, undefined), rumUtil:get_env(?RumAppName, asyncThresholdWindow, undefined)), _ = maybe_install_sink_killer(?RumDefSink, application:get_env(lager, killer_hwm, undefined), application:get_env(lager, killer_reinstall_after, undefined)), @@ -68,17 +68,20 @@ stop(Handlers) -> end, Handlers), rumConfig:cleanup(). -tryStartAsyncer(_Sink, undefined, _Window) -> - ok; -tryStartAsyncer(_Sink, Threshold, _Window) when not is_integer(Threshold) orelse Threshold < 0 -> +tryStartAsyncMgr(undefined, _Window, _SinkS) -> + ignore; +tryStartAsyncMgr(Threshold, Window, Sink) -> + case + startThrottle(Sink, Threshold, Window) +tryStartAsyncMgr(_Sink, Threshold, _Window) when not is_integer(Threshold) orelse Threshold < 0 -> error_logger:error_msg("Invalid value for 'asyncThreshold': ~p~n", [Threshold]), throw({error, bad_config}); -tryStartAsyncer(Sink, Threshold, undefined) -> +tryStartAsyncMgr(Sink, Threshold, undefined) -> startThrottle(Sink, Threshold, erlang:trunc(Threshold * 0.2)); -tryStartAsyncer(_Sink, Threshold, Window) when not is_integer(Window) orelse Window > Threshold orelse Window < 0 -> +tryStartAsyncMgr(_Sink, Threshold, Window) when not is_integer(Window) orelse Window > Threshold orelse Window < 0 -> error_logger:error_msg("Invalid value for 'asyncThresholdWindow': ~p~n", [Window]), throw({error, bad_config}); -tryStartAsyncer(Sink, Threshold, Window) -> +tryStartAsyncMgr(Sink, Threshold, Window) -> startThrottle(Sink, Threshold, Window). startThrottle(Sink, Threshold, Window) -> @@ -214,7 +217,7 @@ configure_sink(Sink, SinkDef) -> rumConfig:initSink(Sink), ChildId = rumUtil:make_internal_sink_name(Sink), _ = supervisor:start_child(eRum_sup, {ChildId, {gen_event, start_link, [{local, Sink}]}, permanent, 5000, worker, dynamic}), - tryStartAsyncer(Sink, proplists:get_value(asyncThreshold, SinkDef), proplists:get_value(asyncThresholdWindow, SinkDef)), + tryStartAsyncMgr(Sink, proplists:get_value(asyncThreshold, SinkDef), proplists:get_value(asyncThresholdWindow, SinkDef)), _ = maybe_install_sink_killer(Sink, proplists:get_value(killer_hwm, SinkDef), proplists:get_value(killer_reinstall_after, SinkDef)), start_handlers(Sink, proplists:get_value(handlers, SinkDef, [])),