Erlang node memory consumption grows to 18GB in few seconds

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Erlang node memory consumption grows to 18GB in few seconds

Chaitanya Chalasani-4
Hi,

I see the memory consumption of an erlang node grows exponentially and quickly when I was sending binary data of about 700 MB from shell to a simple erlang listener process and the shell process is stuck.

-module(strange).
-export([start/0, listener/0, send/1, stop/0]).

start() ->
  register(?MODULE, spawn(?MODULE, listener, [])).

listener() ->
  receive
    {send, Data} ->
      io:format("Received Data ~p ~n", [Data]),
      listener();
    stop ->
      io:format("Stopping listener ~n")
  end.

send(Data) ->
  ?MODULE ! {send, Data}.

stop() ->
  ?MODULE ! stop.

$ uname -a
Darwin Chaitanyas-MacBook-Pro.local 17.5.0 Darwin Kernel Version 17.5.0: Mon Mar  5 22:24:32 PST 2018; root:xnu-4570.51.1~1/RELEASE_X86_64 x86_64

$ erl
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Eshell V9.3  (abort with ^G)
1> c(strange).
{ok,strange}
2> {ok, Data} = file:read_file("centos.iso").
{ok,<<51,237,144,144,144,144,144,144,144,144,144,144,144,
      144,144,144,144,144,144,144,144,144,144,144,144,
      144,144,...>>}
3> strange:start().
true
4> strange:send(Data).

BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
       (v)ersion (k)ill (D)b-tables (d)istribution

The observer says -
<0.53.0> group:server/3 93980000 17957208520 1 erlang:integer_to_list/1

The Mac activity monitor shows Erlang consuming 18GB of RAM.

Kindly, help me understand what is happening.

/Chaitanya

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Erlang node memory consumption grows to 18GB in few seconds

Chaitanya Chalasani-4
I suppose it is the io:format which is causing the issue. Removed the io:format and it works well now. 

On 14-Apr-2018, at 15:25, Chaitanya Chalasani <[hidden email]> wrote:

Hi,

I see the memory consumption of an erlang node grows exponentially and quickly when I was sending binary data of about 700 MB from shell to a simple erlang listener process and the shell process is stuck.

-module(strange).
-export([start/0, listener/0, send/1, stop/0]).

start() ->
  register(?MODULE, spawn(?MODULE, listener, [])).

listener() ->
  receive
    {send, Data} ->
      io:format("Received Data ~p ~n", [Data]),
      listener();
    stop ->
      io:format("Stopping listener ~n")
  end.

send(Data) ->
  ?MODULE ! {send, Data}.

stop() ->
  ?MODULE ! stop.

$ uname -a
Darwin Chaitanyas-MacBook-Pro.local 17.5.0 Darwin Kernel Version 17.5.0: Mon Mar  5 22:24:32 PST 2018; root:xnu-4570.51.1~1/RELEASE_X86_64 x86_64

$ erl
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Eshell V9.3  (abort with ^G)
1> c(strange).
{ok,strange}
2> {ok, Data} = file:read_file("centos.iso").
{ok,<<51,237,144,144,144,144,144,144,144,144,144,144,144,
      144,144,144,144,144,144,144,144,144,144,144,144,
      144,144,...>>}
3> strange:start().
true
4> strange:send(Data).

BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
       (v)ersion (k)ill (D)b-tables (d)istribution

The observer says -
<0.53.0> group:server/3 93980000 17957208520 1 erlang:integer_to_list/1

The Mac activity monitor shows Erlang consuming 18GB of RAM.

Kindly, help me understand what is happening.

/Chaitanya


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Erlang node memory consumption grows to 18GB in few seconds

Dmitry Kolesnikov-2
In reply to this post by Chaitanya Chalasani-4
Hello,

`io:format(…)` is your problem in this example.

Best Regards, 
Dmitry


On 14 Apr 2018, at 12.55, Chaitanya Chalasani <[hidden email]> wrote:

Hi,

I see the memory consumption of an erlang node grows exponentially and quickly when I was sending binary data of about 700 MB from shell to a simple erlang listener process and the shell process is stuck.

-module(strange).
-export([start/0, listener/0, send/1, stop/0]).

start() ->
  register(?MODULE, spawn(?MODULE, listener, [])).

listener() ->
  receive
    {send, Data} ->
      io:format("Received Data ~p ~n", [Data]),
      listener();
    stop ->
      io:format("Stopping listener ~n")
  end.

send(Data) ->
  ?MODULE ! {send, Data}.

stop() ->
  ?MODULE ! stop.

$ uname -a
Darwin Chaitanyas-MacBook-Pro.local 17.5.0 Darwin Kernel Version 17.5.0: Mon Mar  5 22:24:32 PST 2018; root:xnu-4570.51.1~1/RELEASE_X86_64 x86_64

$ erl
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Eshell V9.3  (abort with ^G)
1> c(strange).
{ok,strange}
2> {ok, Data} = file:read_file("centos.iso").
{ok,<<51,237,144,144,144,144,144,144,144,144,144,144,144,
      144,144,144,144,144,144,144,144,144,144,144,144,
      144,144,...>>}
3> strange:start().
true
4> strange:send(Data).

BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
       (v)ersion (k)ill (D)b-tables (d)istribution

The observer says -
<0.53.0> group:server/3 93980000 17957208520 1 erlang:integer_to_list/1

The Mac activity monitor shows Erlang consuming 18GB of RAM.

Kindly, help me understand what is happening.

/Chaitanya
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Erlang node memory consumption grows to 18GB in few seconds

Danil Zagoskin-2
In reply to this post by Chaitanya Chalasani-4
Never use io:format("~p") on large data.
Simple solution is to limit depth: io:format("~P~n", [Data, 30])

On Sat, Apr 14, 2018 at 12:55 PM, Chaitanya Chalasani <[hidden email]> wrote:

> Hi,
>
> I see the memory consumption of an erlang node grows exponentially and
> quickly when I was sending binary data of about 700 MB from shell to a
> simple erlang listener process and the shell process is stuck.
>
> -module(strange).
> -export([start/0, listener/0, send/1, stop/0]).
>
> start() ->
>   register(?MODULE, spawn(?MODULE, listener, [])).
>
> listener() ->
>   receive
>     {send, Data} ->
>       io:format("Received Data ~p ~n", [Data]),
>       listener();
>     stop ->
>       io:format("Stopping listener ~n")
>   end.
>
> send(Data) ->
>   ?MODULE ! {send, Data}.
>
> stop() ->
>   ?MODULE ! stop.
>
> $ uname -a
> Darwin Chaitanyas-MacBook-Pro.local 17.5.0 Darwin Kernel Version 17.5.0: Mon
> Mar  5 22:24:32 PST 2018; root:xnu-4570.51.1~1/RELEASE_X86_64 x86_64
>
> $ erl
> Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:8:8] [ds:8:8:10]
> [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
>
> Eshell V9.3  (abort with ^G)
> 1> c(strange).
> {ok,strange}
> 2> {ok, Data} = file:read_file("centos.iso").
> {ok,<<51,237,144,144,144,144,144,144,144,144,144,144,144,
>       144,144,144,144,144,144,144,144,144,144,144,144,
>       144,144,...>>}
> 3> strange:start().
> true
> 4> strange:send(Data).
>
> BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
>        (v)ersion (k)ill (D)b-tables (d)istribution
>
> The observer says -
> <0.53.0> group:server/3 93980000 17957208520 1 erlang:integer_to_list/1
>
> The Mac activity monitor shows Erlang consuming 18GB of RAM.
>
> Kindly, help me understand what is happening.
>
> /Chaitanya
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>



--
Danil Zagoskin | [hidden email]
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Erlang node memory consumption grows to 18GB in few seconds

Chaitanya Chalasani-4
Thank you for that suggestion, Danil.

However, removing the io:format alone didn’t solve the problem. I had to change the send function too.

From:

send(Data) ->
 ?MODULE ! {send, Data}.

To:

send(Data) ->
  ?MODULE ! {send, Data},
  ok.

Does the shell also use io:format to show the function return value?

> On 15-Apr-2018, at 18:40, Danil Zagoskin <[hidden email]> wrote:
>
> Never use io:format("~p") on large data.
> Simple solution is to limit depth: io:format("~P~n", [Data, 30])
>
> On Sat, Apr 14, 2018 at 12:55 PM, Chaitanya Chalasani <[hidden email]> wrote:
>> Hi,
>>
>> I see the memory consumption of an erlang node grows exponentially and
>> quickly when I was sending binary data of about 700 MB from shell to a
>> simple erlang listener process and the shell process is stuck.
>>
>> -module(strange).
>> -export([start/0, listener/0, send/1, stop/0]).
>>
>> start() ->
>>  register(?MODULE, spawn(?MODULE, listener, [])).
>>
>> listener() ->
>>  receive
>>    {send, Data} ->
>>      io:format("Received Data ~p ~n", [Data]),
>>      listener();
>>    stop ->
>>      io:format("Stopping listener ~n")
>>  end.
>>
>> send(Data) ->
>>  ?MODULE ! {send, Data}.
>>
>> stop() ->
>>  ?MODULE ! stop.
>>
>> $ uname -a
>> Darwin Chaitanyas-MacBook-Pro.local 17.5.0 Darwin Kernel Version 17.5.0: Mon
>> Mar  5 22:24:32 PST 2018; root:xnu-4570.51.1~1/RELEASE_X86_64 x86_64
>>
>> $ erl
>> Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:8:8] [ds:8:8:10]
>> [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
>>
>> Eshell V9.3  (abort with ^G)
>> 1> c(strange).
>> {ok,strange}
>> 2> {ok, Data} = file:read_file("centos.iso").
>> {ok,<<51,237,144,144,144,144,144,144,144,144,144,144,144,
>>      144,144,144,144,144,144,144,144,144,144,144,144,
>>      144,144,...>>}
>> 3> strange:start().
>> true
>> 4> strange:send(Data).
>>
>> BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
>>       (v)ersion (k)ill (D)b-tables (d)istribution
>>
>> The observer says -
>> <0.53.0> group:server/3 93980000 17957208520 1 erlang:integer_to_list/1
>>
>> The Mac activity monitor shows Erlang consuming 18GB of RAM.
>>
>> Kindly, help me understand what is happening.
>>
>> /Chaitanya
>>
>> _______________________________________________
>> erlang-questions mailing list
>> [hidden email]
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>
>
>
> --
> Danil Zagoskin | [hidden email]

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Erlang node memory consumption grows to 18GB in few seconds

Raimo Niskanen-2
On Sun, Apr 15, 2018 at 06:47:19PM +0530, Chaitanya Chalasani wrote:

> Thank you for that suggestion, Danil.
>
> However, removing the io:format alone didn’t solve the problem. I had to change the send function too.
>
> From:
>
> send(Data) ->
>  ?MODULE ! {send, Data}.
>
> To:
>
> send(Data) ->
>   ?MODULE ! {send, Data},
>   ok.
>
> Does the shell also use io:format to show the function return value?

The return value from all shell commands are saved in the shell history.
/ Raimo



>
> > On 15-Apr-2018, at 18:40, Danil Zagoskin <[hidden email]> wrote:
> >
> > Never use io:format("~p") on large data.
> > Simple solution is to limit depth: io:format("~P~n", [Data, 30])
> >
> > On Sat, Apr 14, 2018 at 12:55 PM, Chaitanya Chalasani <[hidden email]> wrote:
> >> Hi,
> >>
> >> I see the memory consumption of an erlang node grows exponentially and
> >> quickly when I was sending binary data of about 700 MB from shell to a
> >> simple erlang listener process and the shell process is stuck.
> >>
> >> -module(strange).
> >> -export([start/0, listener/0, send/1, stop/0]).
> >>
> >> start() ->
> >>  register(?MODULE, spawn(?MODULE, listener, [])).
> >>
> >> listener() ->
> >>  receive
> >>    {send, Data} ->
> >>      io:format("Received Data ~p ~n", [Data]),
> >>      listener();
> >>    stop ->
> >>      io:format("Stopping listener ~n")
> >>  end.
> >>
> >> send(Data) ->
> >>  ?MODULE ! {send, Data}.
> >>
> >> stop() ->
> >>  ?MODULE ! stop.
> >>
> >> $ uname -a
> >> Darwin Chaitanyas-MacBook-Pro.local 17.5.0 Darwin Kernel Version 17.5.0: Mon
> >> Mar  5 22:24:32 PST 2018; root:xnu-4570.51.1~1/RELEASE_X86_64 x86_64
> >>
> >> $ erl
> >> Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:8:8] [ds:8:8:10]
> >> [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
> >>
> >> Eshell V9.3  (abort with ^G)
> >> 1> c(strange).
> >> {ok,strange}
> >> 2> {ok, Data} = file:read_file("centos.iso").
> >> {ok,<<51,237,144,144,144,144,144,144,144,144,144,144,144,
> >>      144,144,144,144,144,144,144,144,144,144,144,144,
> >>      144,144,...>>}
> >> 3> strange:start().
> >> true
> >> 4> strange:send(Data).
> >>
> >> BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
> >>       (v)ersion (k)ill (D)b-tables (d)istribution
> >>
> >> The observer says -
> >> <0.53.0> group:server/3 93980000 17957208520 1 erlang:integer_to_list/1
> >>
> >> The Mac activity monitor shows Erlang consuming 18GB of RAM.
> >>
> >> Kindly, help me understand what is happening.
> >>
> >> /Chaitanya
> >>
> >> _______________________________________________
> >> erlang-questions mailing list
> >> [hidden email]
> >> http://erlang.org/mailman/listinfo/erlang-questions
> >>
> >
> >
> >
> > --
> > Danil Zagoskin | [hidden email]
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions

--

/ Raimo Niskanen, Erlang/OTP, Ericsson AB
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions