feat(olp): bump lc to 0.1.1
This commit is contained in:
parent
8d8969672b
commit
b0c27c74fd
|
@ -9,7 +9,7 @@
|
||||||
%% This rebar.config is necessary because the app may be used as a
|
%% This rebar.config is necessary because the app may be used as a
|
||||||
%% `git_subdir` dependency in other projects.
|
%% `git_subdir` dependency in other projects.
|
||||||
{deps,
|
{deps,
|
||||||
[ {lc, {git, "https://github.com/qzhuyan/lc.git", {tag, "0.1.0"}}}
|
[ {lc, {git, "https://github.com/qzhuyan/lc.git", {tag, "0.1.1"}}}
|
||||||
, {gproc, {git, "https://github.com/uwiger/gproc", {tag, "0.8.0"}}}
|
, {gproc, {git, "https://github.com/uwiger/gproc", {tag, "0.8.0"}}}
|
||||||
, {typerefl, {git, "https://github.com/k32/typerefl", {tag, "0.8.5"}}}
|
, {typerefl, {git, "https://github.com/k32/typerefl", {tag, "0.8.5"}}}
|
||||||
, {jiffy, {git, "https://github.com/emqx/jiffy", {tag, "1.0.5"}}}
|
, {jiffy, {git, "https://github.com/emqx/jiffy", {tag, "1.0.5"}}}
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-module(emqx_olp).
|
-module(emqx_olp).
|
||||||
|
|
||||||
|
-include_lib("lc/include/lc.hrl").
|
||||||
|
|
||||||
-export([ is_overloaded/0
|
-export([ is_overloaded/0
|
||||||
, backoff/1
|
, backoff/1
|
||||||
, backoff_gc/1
|
, backoff_gc/1
|
||||||
|
@ -100,9 +102,16 @@ off() ->
|
||||||
load_ctl:stop_runq_flagman(5000).
|
load_ctl:stop_runq_flagman(5000).
|
||||||
|
|
||||||
%% @doc turn on backgroud runq check.
|
%% @doc turn on backgroud runq check.
|
||||||
-spec on() -> {ok, pid()} | {error, running | restarting}.
|
-spec on() -> {ok, pid()} | {error, running | restarting | disabled}.
|
||||||
on() ->
|
on() ->
|
||||||
load_ctl:restart_runq_flagman().
|
case load_ctl:restart_runq_flagman() of
|
||||||
|
{error, disabled} ->
|
||||||
|
OldCfg = load_ctl:get_config(),
|
||||||
|
ok = load_ctl:put_config(OldCfg#{ ?RUNQ_MON_F0 => true }),
|
||||||
|
load_ctl:restart_runq_flagman();
|
||||||
|
Other ->
|
||||||
|
Other
|
||||||
|
end.
|
||||||
|
|
||||||
%%% Internals
|
%%% Internals
|
||||||
-spec do_check(Zone::atom(), cfg_key(), cnt_name()) -> boolean().
|
-spec do_check(Zone::atom(), cfg_key(), cnt_name()) -> boolean().
|
||||||
|
|
|
@ -35,11 +35,20 @@ end_per_suite(_Config) ->
|
||||||
|
|
||||||
init_per_testcase(_, Config) ->
|
init_per_testcase(_, Config) ->
|
||||||
emqx_olp:on(),
|
emqx_olp:on(),
|
||||||
ok = load_ctl:put_config(#{ ?RUNQ_MON_T1 => 200
|
case wait_for(fun() -> lc_sup:whereis_runq_flagman() end, 10) of
|
||||||
, ?RUNQ_MON_T2 => 50
|
true -> ok;
|
||||||
, ?RUNQ_MON_C1 => 3
|
false ->
|
||||||
}),
|
ct:fail("runq_flagman is not up")
|
||||||
Config.
|
end,
|
||||||
|
ok = load_ctl:put_config(#{ ?RUNQ_MON_F0 => true
|
||||||
|
, ?RUNQ_MON_F1 => 5
|
||||||
|
, ?RUNQ_MON_F2 => 1
|
||||||
|
, ?RUNQ_MON_T1 => 200
|
||||||
|
, ?RUNQ_MON_T2 => 50
|
||||||
|
, ?RUNQ_MON_C1 => 2
|
||||||
|
, ?RUNQ_MON_F5 => -1
|
||||||
|
}),
|
||||||
|
Config.
|
||||||
|
|
||||||
%% Test that olp could be enabled/disabled globally
|
%% Test that olp could be enabled/disabled globally
|
||||||
t_off_on(_Config) ->
|
t_off_on(_Config) ->
|
||||||
|
@ -47,15 +56,16 @@ t_off_on(_Config) ->
|
||||||
ok = emqx_olp:off(),
|
ok = emqx_olp:off(),
|
||||||
?assert(not is_process_alive(Old)),
|
?assert(not is_process_alive(Old)),
|
||||||
{ok, Pid} = emqx_olp:on(),
|
{ok, Pid} = emqx_olp:on(),
|
||||||
|
timer:sleep(1000),
|
||||||
?assert(is_process_alive(Pid)).
|
?assert(is_process_alive(Pid)).
|
||||||
|
|
||||||
%% Test that overload detection works
|
%% Test that overload detection works
|
||||||
t_is_overloaded(_Config) ->
|
t_is_overloaded(_Config) ->
|
||||||
P = burst_runq(),
|
P = burst_runq(),
|
||||||
timer:sleep(2000),
|
timer:sleep(3000),
|
||||||
?assert(emqx_olp:is_overloaded()),
|
?assert(emqx_olp:is_overloaded()),
|
||||||
exit(P, kill),
|
exit(P, kill),
|
||||||
timer:sleep(2000),
|
timer:sleep(3000),
|
||||||
?assert(not emqx_olp:is_overloaded()).
|
?assert(not emqx_olp:is_overloaded()).
|
||||||
|
|
||||||
%% Test that new conn is rejected when olp is enabled
|
%% Test that new conn is rejected when olp is enabled
|
||||||
|
@ -95,3 +105,14 @@ worker_parent(N, {M, F, A}) ->
|
||||||
busy_loop() ->
|
busy_loop() ->
|
||||||
erlang:yield(),
|
erlang:yield(),
|
||||||
busy_loop().
|
busy_loop().
|
||||||
|
|
||||||
|
wait_for(_Fun, 0) ->
|
||||||
|
false;
|
||||||
|
wait_for(Fun, Retry) ->
|
||||||
|
case is_pid(Fun()) of
|
||||||
|
true ->
|
||||||
|
true;
|
||||||
|
false ->
|
||||||
|
timer:sleep(10),
|
||||||
|
wait_for(Fun, Retry - 1)
|
||||||
|
end.
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
{post_hooks,[]}.
|
{post_hooks,[]}.
|
||||||
|
|
||||||
{deps,
|
{deps,
|
||||||
[ {lc, {git, "https://github.com/qzhuyan/lc.git", {tag, "0.1.0"}}}
|
[ {lc, {git, "https://github.com/qzhuyan/lc.git", {tag, "0.1.1"}}}
|
||||||
, {gpb, "4.11.2"} %% gpb only used to build, but not for release, pin it here to avoid fetching a wrong version due to rebar plugins scattered in all the deps
|
, {gpb, "4.11.2"} %% gpb only used to build, but not for release, pin it here to avoid fetching a wrong version due to rebar plugins scattered in all the deps
|
||||||
, {typerefl, {git, "https://github.com/k32/typerefl", {tag, "0.8.5"}}}
|
, {typerefl, {git, "https://github.com/k32/typerefl", {tag, "0.8.5"}}}
|
||||||
, {ehttpc, {git, "https://github.com/emqx/ehttpc", {tag, "0.1.9"}}}
|
, {ehttpc, {git, "https://github.com/emqx/ehttpc", {tag, "0.1.9"}}}
|
||||||
|
|
Loading…
Reference in New Issue