[erlang-questions] How to dig why get_tcp/port allocate so much binary memory?

Danil Zagoskin z@REDACTED
Thu Sep 22 15:06:05 CEST 2016


Hi!

Please check your recbuf and sndbuf port options.
After you establish a conection, log buffer sizes somehow, e.g.
io:format("Socket buffers: ~w~n", [inet:getopts(S, [recbuf, sndbuf])]).

Large socket buffers are nice thing to have (for high throughput), but they
can eat all your memory really fast.
If they are not set explicitly by your application, you can
check inet_default_connect_options kernel app environment variable or your
operating system defaults (rmem_default).


On Thu, Sep 22, 2016 at 12:41 PM, 叶少波 <shaobo.ye@REDACTED> wrote:

> Hi experts,
>
> I wrote a server that accepts TCP connections. The listen socket starts
> with the options below:
>   -define(TCP_OPTS, [
>     binary,
>     {backlog, 256},
>     {packet, 0},
>     {active, false},
>     {reuseaddr, true},
>     {nodelay, false},
>     {delay_send, true},
>     {keepalive, true},
>     {send_timeout, 60000},
>     {exit_on_close, true}
> ]).
> On the server node every new connection will spawn a new gen_server to
> handle it.
>
> And  then I spawn 5000 gen_servers on another erlang node(I call it Client
> node), every gen_server will connect to the server via TCP.
>
> It is a really simple case.
>
> After setup 5000 connections I found the binary memory on server node was
> used up to 17G;
> and the binary memory on the Client node was 42M.  It is a huge difference.
>
> Then I rebooted  the erlang node with "+Mim true"  and "+Mis true"; after
> re-setup 5000 connections again, I used
> instrument:memory_status(types) to check the memory status, I found the
> dry_binary allocated 17G memory:
> [{drv_binary,[{sizes,1844114912,1844116842,1844116842},
>               {blocks,5227,5724,5724}]},
>  {code,[{sizes,39944997,39955374,39955374},
>         {blocks,1321,1321,1321}]},
>  {heap,[{sizes,28000216,78942872,78942872},
>         {blocks,5263,5267,5267}]},
>  {old_heap,[{sizes,21132056,72481264,72481264},
>             {blocks,2940,4736,4736}]},
>  {binary,[{sizes,17908918,21738516,21738516},
>           {blocks,25087,35039,35039}]},
>  {proc_tab,[{sizes,12582975,12582975,12582975},
>             {blocks,1,1,1}]},
>  {export_entry,[{sizes,7108992,7108992,7108992},
>                 {blocks,40392,40392,40392}]},
>  {db_term,[{sizes,6930120,6930200,6930200},
>            {blocks,13149,13150,13150}]},
>  {port_tab,[{sizes,6291519,6291519,6291519},{blocks,1,1,1}]},
>  {proc,[{sizes,4211200,4212800,4212800},
>         {blocks,5264,5266,5266}]},
>  {port,[{sizes,3392108,3393432,3393432},
>         {blocks,5101,5103,5103}]},
> .......
>
> My question is : How can I decrease the drv_binary memory? What parameter
> caused the server used so much memory?
>
> Thanks,
> BRs/Michael
>
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>


-- 
Danil Zagoskin | z@REDACTED
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160922/149059ad/attachment.htm>


More information about the erlang-questions mailing list