Remove used memory watermark check (#135)

Even being optional it had considerable negative effect on latency
perceived by client. I guess we need something more elaborated.
This commit is contained in:
Andrew Mayorov 2020-05-13 18:43:34 +03:00 committed by GitHub
parent b6ec9887fb
commit 7a31f024f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,8 +23,7 @@
%% Types
-type handler_limits() :: #{
max_heap_size => integer(), %% process words, see erlang:process_flag(max_heap_size, MaxHeapSize) for details.
total_mem_threshold => integer() %% bytes, see erlang:memory() for details.
max_heap_size => integer() %% process words, see erlang:process_flag(max_heap_size, MaxHeapSize) for details.
}.
-export_type([handler_limits/0]).
@ -261,19 +260,10 @@ init(Req, Opts = #{ev_handler := EvHandler, handler_limits := Limits}) ->
ok = set_handler_limits(Limits),
Url = unicode:characters_to_binary(cowboy_req:uri(Req)),
WoodyState = create_dummy_state(EvHandler),
case have_resources_to_continue(Limits) of
true ->
Opts1 = update_woody_state(Opts#{url => Url}, WoodyState, Req),
case check_request(Req, Opts1) of
{ok, Req1, State} -> handle(Req1, State);
{stop, Req1, State} -> {ok, Req1, State}
end;
false ->
Details = <<"erlang vm exceeded total memory threshold">>,
_ = woody_event_handler:handle_event(?EV_SERVER_RECEIVE, WoodyState,
#{url => Url, status => error, reason => Details}),
Req2 = handle_error({system, {internal, resource_unavailable, Details}}, Req, WoodyState),
{ok, Req2, undefined}
Opts1 = update_woody_state(Opts#{url => Url}, WoodyState, Req),
case check_request(Req, Opts1) of
{ok, Req1, State} -> handle(Req1, State);
{stop, Req1, State} -> {ok, Req1, State}
end.
-spec set_handler_limits(handler_limits()) ->
@ -291,16 +281,6 @@ set_handler_limits(Limits) ->
ok
end.
-spec have_resources_to_continue(handler_limits()) ->
boolean().
have_resources_to_continue(Limits) ->
case maps:get(total_mem_threshold, Limits, undefined) of
undefined ->
true;
MaxTotalMem when is_integer(MaxTotalMem) ->
erlang:memory(total) < MaxTotalMem
end.
-spec handle(cowboy_req:req(), state()) ->
{ok, cowboy_req:req(), _}.
handle(Req, State = #{