[erlang-questions] Experience with much memory
Jack Tang
himars@REDACTED
Sat Sep 28 16:45:58 CEST 2019
It is complex question. You should locate who hold the memory first :)
Below codes might help you to locate the process / ets
```
applications_memory() ->
try application:which_applications() of
Apps ->
lists:map(
fun({AppName, _, _}) ->
Mem = application_memory(AppName),
{AppName, Mem}
end, Apps)
catch
_:Exception ->
error_logger:error_msg("[~p] get application memory failed ~p",
[?MODULE, Exception]),
undefined
end.
application_memory(App) ->
case application_controller:get_master(App) of
Master when is_pid(Master) ->
{Root, Name} = application_master:get_child(Master),
{Memory, Children} = memory_info(Root),
{Name, Memory div 1000000, Children};
_ ->
undefined
end.
memory_info(Sup) ->
Infos = supervisor:which_children(Sup),
{M, E, ES} =
lists:foldl(
fun({Name, PId, Type, _}, {Total, Memories, MemorySets}) ->
case Type of
worker ->
{memory, Memory} = process_info(PId, memory),
NTotal = Total + Memory,
case Name of
undefined ->
NMemorySets =
case gb_sets:size(MemorySets) of
Size when Size > 10 ->
{_, NSets} =
gb_sets:take_smallest(MemorySets),
NSets;
_ ->
MemorySets
end,
NNMemorySets = gb_sets:insert(
{undefined, Memory, PId},
NMemorySets),
{NTotal, Memories, NNMemorySets};
Name ->
{NTotal, [{Name, Memory, PId}|Memories],
MemorySets}
end;
supervisor ->
{Memory, Each} = memory_info(PId),
NTotal = Total + Memory,
{NTotal, [{Name, {Memory, Each}, PId}|Memories],
MemorySets}
end
end, {0, [], gb_sets:new()}, Infos),
NE =
case E of
[] ->
gb_sets:to_list(ES);
_ ->
E
end,
NNE = lists:map(
fun({N, Mem, PId}) ->
case Mem of
Mem when is_integer(Mem) ->
{N, Mem div 1000000, undefined, PId};
{T, RestEach} ->
{N, T div 1000000, PId, RestEach}
end
end, NE),
NNNE = lists:reverse(lists:keysort(3, NNE)),
{M, NNNE}.
ets_memory() ->
All = ets:all(),
AllMems = lists:map(
fun(Ets) ->
Mem = ets:info(Ets, memory),
{Ets, Mem}
end, All),
Mems =
lists:sort(
fun({_, M1}, {_, M2}) ->
M1 > M2
end, AllMems),
Sum = lists:sum(lists:map(fun({_, Mem}) -> Mem end, AllMems)),
{Sum, Mems}.
```
Also I recommend
https://github.com/ferd/recon/blob/master/src/recon_alloc.erl .
On Sat, Sep 28, 2019 at 10:03 PM <buday.gergely@REDACTED> wrote:
> Hi there,
>
> are there experience reports on using Erlang/Elixir on systems with 200 GB
> of memory and more?
>
> If you have a first-hand account on that, please share it with me.
>
> My friends are doing that and said that only C++ was capable of handling
> that.
>
> - Gergely
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
--
Jack Tang
http://www.linkedin.com/in/jacktang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190928/23b13b2d/attachment.htm>
More information about the erlang-questions
mailing list