<div dir="ltr">I'm confused; how exactly is the receive/if changed? Looks the same to me. Am i missing something?<br><br><div class="gmail_quote">On Mon, Sep 22, 2008 at 10:08 AM, Paul Oliver <span dir="ltr"><<a href="mailto:puzza007@gmail.com">puzza007@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi all,<br>
<br>
I've written a test client that starts a number of sockets and<br>
repeatedly sends and receives a static sting from an echo server.<br>
I've noticed some strange behavior with an if statement and was<br>
wondering if someone can tell me why? The following code seems to<br>
leak memory and processes until my box is hosed:<br>
<br>
loop(Sock, Log) -><br>
Before = if Log -> now();<br>
true -> 0<br>
end,<br>
ok = gen_tcp:send(Sock,<br>
<<"01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789">>),<br>
receive<br>
{tcp, Sock, _Data} -><br>
if Log -><br>
[{total, Total}, {processes, Processes} , _, _, _, _, {binary,<br>
Binary}, _, _] = erlang:memory(),<br>
error_logger:info_msg("tot_mem: ~p, binary: ~p, procs: ~p, time: ~p",<br>
[Total, Binary, Processes, timer:now_diff(now(),Before)/1000]);<br>
true -> true<br>
end;<br>
Error -><br>
% Anything other than a data message, print error<br>
error_logger:error_msg(Error)<br>
end,<br>
receive<br>
after ?MESSAGE_INTERVAL -><br>
true<br>
end,<br>
loop(Sock, Log).<br>
<br>
Example logs:<br>
<br>
=INFO REPORT==== 22-Sep-2008::14:53:31 ===<br>
tot_mem: 587049608, binary: 334781944, procs: 171962344, time: 9.685<br>
<br>
[snip - box now running out of swap]<br>
<br>
=INFO REPORT==== 22-Sep-2008::15:00:23 ===<br>
tot_mem: 1261717856, binary: 874756136, procs: 307929080, time: 23137.121<br>
<br>
<br>
However, changing the receive/if to:<br>
<br>
receive<br>
{tcp, Sock, _Data} -><br>
[{total, Total}, {processes, Processes} , _, _, _, _, {binary,<br>
Binary}, _, _] = erlang:memory(),<br>
if Log -><br>
error_logger:info_msg("tot_mem: ~p, binary: ~p, procs: ~p, time: ~p",<br>
[Total, Binary, Processes, timer:now_diff(now(),Before)/1000]);<br>
true -> true<br>
end;<br>
<br>
allows the program to run without leaking anything.<br>
<br>
Any help greatly appreciated.<br>
<br>
Cheers,<br>
Paul.<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
<br>
</blockquote></div><br></div>