[erlang-questions] question about binary memory

叶少波 shaobo.ye@REDACTED
Mon Sep 19 16:57:19 CEST 2016


Hi,


My question is about the binary memory usage.
I implemented a server which accepts Tcp connection. All the Tcp connections use binary options.


Before I set up 10000 Tcp connections to my server, the memory usage is as below:
(node1@REDACTED)1> erlang:memory().
[{total,100311433},
 {processes,24898112},
 {processes_used,24895144},
 {system,75413321},
 {atom,1517705},
 {atom_used,1506108},
 {binary,3115928},
 {code,48956174},
 {ets,3556416},
 {maximum,102757346}]



after I set up 10000 Tcp connections, every connection is hold by one gen_server; the memory usage is as below:
(node1@REDACTED)5>erlang:memory().          
[{total,2616776425},
 {processes,92150752},
 {processes_used,92138976},
 {system,2524625673},
 {atom,1517705},
 {atom_used,1506108},
 {binary,2437117184},
 {code,48956174},
 {ets,13264464},
 {maximum,2848153566}]



And I check the binary hold by all the processes on the node with the command below:
List = [begin {binary, L} = erlang:process_info(P, binary), {P, (lists:foldl(fun({_, I, _}, Acc) -> Acc + I end, 0, L))} end || P <- processes() -- [self()]], lists:foldl(fun({_, A}, Acc) -> A + Acc end, 0, List). 
the result is 23113860.  It is much less than the value 2437117184 reported by erlang:memory().


My question is :
why does the VM allocate so much memory for binary?
Does the Tcp ports allocate their send/recv buffer on binary heap?
Is there any way I can see what are in the binary heap?


Thanks,
BRs/Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160919/5c85097d/attachment.htm>


More information about the erlang-questions mailing list