Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion apps/arweave/include/ar_config.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@
-define(DEFAULT_COWBOY_TCP_SEND_TIMEOUT, 15_000).
-define(DEFAULT_COWBOY_TCP_LISTENER_SHUTDOWN, 5000).

%% The default OOM monitor report period in milliseconds.
-define(DEFAULT_OOM_MONITOR_REPORT_PERIOD_MS, 5000).
-define(DEFAULT_OOM_MONITOR_FILENAME, "/tmp/arweave_oom_monitor.log").
-define(DEFAULT_OOM_MONITOR_TOP_PROCS, 20).

%% @doc Startup options with default values.
-record(config, {
init = false,
Expand Down Expand Up @@ -313,7 +318,12 @@
'http_api.tcp.nodelay' = ?DEFAULT_COWBOY_TCP_NODELAY,
'http_api.tcp.num_acceptors' = ?DEFAULT_COWBOY_TCP_NUM_ACCEPTORS,
'http_api.tcp.send_timeout_close' = ?DEFAULT_COWBOY_TCP_SEND_TIMEOUT_CLOSE,
'http_api.tcp.send_timeout' = ?DEFAULT_COWBOY_TCP_SEND_TIMEOUT
'http_api.tcp.send_timeout' = ?DEFAULT_COWBOY_TCP_SEND_TIMEOUT,

% OOM Monitor Configuration
oom_monitor_report_period = ?DEFAULT_OOM_MONITOR_REPORT_PERIOD_MS,
oom_monitor_filename = ?DEFAULT_OOM_MONITOR_FILENAME,
oom_monitor_top_procs = ?DEFAULT_OOM_MONITOR_TOP_PROCS
}).

-endif.
29 changes: 29 additions & 0 deletions apps/arweave/src/ar.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,35 @@ parse_cli_args(["http_api.tcp.send_timeout", Timeout|Rest], C) ->
parse_cli_args(Rest, C)
end;

parse_cli_args(["oom_monitor_report_period", Period|Rest], C) ->
try list_to_integer(Period) of
P when P >= 0 ->
parse_cli_args(Rest, C#config{ oom_monitor_report_period = P });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need a P * 1000?

_ ->
io:format("Invalid oom_monitor_report_period ~p.", [Period]),
parse_cli_args(Rest, C)
catch
_:_ ->
io:format("Invalid oom_monitor_report_period ~p.", [Period]),
parse_cli_args(Rest, C)
end;

parse_cli_args(["oom_monitor_filename", Filename|Rest], C) ->
parse_cli_args(Rest, C#config{ oom_monitor_filename = Filename });

parse_cli_args(["oom_monitor_top_procs", TopProcs|Rest], C) ->
try list_to_integer(TopProcs) of
T when T >= 0 ->
parse_cli_args(Rest, C#config{ oom_monitor_top_procs = T });
_ ->
io:format("Invalid oom_monitor_top_procs ~p.", [TopProcs]),
parse_cli_args(Rest, C)
catch
_:_ ->
io:format("Invalid oom_monitor_top_procs ~p.", [TopProcs]),
parse_cli_args(Rest, C)
end;

%% Undocumented/unsupported options
parse_cli_args(["chunk_storage_file_size", Num | Rest], C) ->
parse_cli_args(Rest, C#config{ chunk_storage_file_size = list_to_integer(Num) });
Expand Down
25 changes: 23 additions & 2 deletions apps/arweave/src/ar_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

-export([validate_config/1, set_dependent_flags/1, use_remote_vdf_server/0,
pull_from_remote_vdf_server/0, compute_own_vdf/0, is_vdf_server/0,
is_public_vdf_server/0, parse/1, parse_storage_module/1, log_config/1]).
is_public_vdf_server/0, is_oom_monitor_enabled/0, parse/1, parse_storage_module/1,
log_config/1]).

-include("../include/ar.hrl").
-include("../include/ar_consensus.hrl").
Expand Down Expand Up @@ -65,6 +66,10 @@ is_public_vdf_server() ->
{ok, Config} = application:get_env(arweave, config),
lists:member(public_vdf_server, Config#config.enable).

is_oom_monitor_enabled() ->
{ok, Config} = application:get_env(arweave, config),
lists:member(oom_monitor, Config#config.enable).

parse(Config) when is_binary(Config) ->
case ar_serialize:json_decode(Config) of
{ok, JsonValue} -> parse_options(JsonValue);
Expand Down Expand Up @@ -916,6 +921,23 @@ parse_options([{<<"http_api.tcp.send_timeout">>, Timeout}|Rest], Config) ->
{error, {bad_value, 'http_api.tcp.send_timeout'}, Timeout}
end;

parse_options([{<<"oom_monitor_report_period">>, Period} | Rest], Config)
when is_integer(Period), Period > 0 ->
parse_options(Rest, Config#config{ oom_monitor_report_period = Period * 1000 });
parse_options([{<<"oom_monitor_report_period">>, Period} | _], _) ->
{error, {bad_type, oom_monitor_report_period, number}, Period};

parse_options([{<<"oom_monitor_filename">>, Filename} | Rest], Config) when is_binary(Filename) ->
parse_options(Rest, Config#config{ oom_monitor_filename = binary_to_list(Filename) });
parse_options([{<<"oom_monitor_filename">>, Filename} | _], _) ->
{error, {bad_type, oom_monitor_filename, string}, Filename};

parse_options([{<<"oom_monitor_top_procs">>, TopProcs} | Rest], Config)
when is_integer(TopProcs), TopProcs > 0 ->
parse_options(Rest, Config#config{ oom_monitor_top_procs = TopProcs });
parse_options([{<<"oom_monitor_top_procs">>, TopProcs} | _], _) ->
{error, {bad_type, oom_monitor_top_procs, number}, TopProcs};

parse_options([Opt | _], _) ->
{error, unknown, Opt};
parse_options([], Config) ->
Expand Down Expand Up @@ -1268,4 +1290,3 @@ set_verify_flags(Config) ->
max_propagation_peers = 0,
max_block_propagation_peers = 0
}.

Loading
Loading