hi!<br>I checked the server found in erlang shell activated when launched smp,
my server is single core, smp cancelled after the running of the entire
service soon, but still high cpu occupiers, the test data will be
1000000 continuing seconds cpu 99% usage, may I ask you what optimization
approach? Cpu occupiers will be reduced?<br><br>thanks All!<br><br><div class="gmail_quote">2008/2/17 myname iserl <<a href="mailto:mynameiserl@itsbeen.sent.com">mynameiserl@itsbeen.sent.com</a>>:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br><br>Sorry, for offlist.<br>I don't use erlang yet and I don't really know erlang at all,<br>but I read the list often.<br><br>For monitoring why your server is using 99% you might try:<br><a href="http://www.erlang.org/documentation/doc-5.2/lib/observer-0.9/doc/html/etop_ug.html" target="_blank">http://www.erlang.org/documentation/doc-5.2/lib/observer-0.9/doc/html/etop_ug.html</a><br>
<a href="http://www.erlang.org/doc/efficiency_guide/profiling.html" target="_blank">http://www.erlang.org/doc/efficiency_guide/profiling.html</a><br><br><a href="http://www.erlang.org/doc/man/eprof.html" target="_blank">http://www.erlang.org/doc/man/eprof.html</a><br>
<a href="http://www.erlang.org/doc/man/fprof.html" target="_blank">http://www.erlang.org/doc/man/fprof.html</a><br><a href="http://www.erlang.org/doc/apps/tools/cprof_chapter.html" target="_blank">http://www.erlang.org/doc/apps/tools/cprof_chapter.html</a><br>
<br>Good luck<br><div class="Ih2E3d"><br>瞄瞄 wrote:<br>> thanks!<br>> I was revised to {active,once} and server cpu still occupy 99%, but my<br></div>> code in the local tests, use  <a href="http://127.0.0.1" target="_blank">127.0.0.1</a> <<a href="http://127.0.0.1/" target="_blank">http://127.0.0.1/</a>>,100 million<br>
> run by 40 seconds, and even in the server <a href="http://127.0.0.1" target="_blank">127.0.0.1</a> <<a href="http://127.0.0.1/" target="_blank">http://127.0.0.1/</a>><br><div class="Ih2E3d">> of the cpu will be 99%.<br>
><br>> Is there any way to find out whether there is a server cpu 99%?<br>><br>> very thanks!<br>><br></div>> 2008/2/16 Sean Hinde <<a href="mailto:sean.hinde@gmail.com">sean.hinde@gmail.com</a> <mailto:<a href="mailto:sean.hinde@gmail.com">sean.hinde@gmail.com</a>>>:<br>
<div class="Ih2E3d">><br>>     The problem here is almost certainly your use of {active, true}. The<br>>     inbound mailbox will rapidly fill with a very large number of messages<br>>     (1 million in your case), and this can cause the emulator to slow down<br>
>     during garbage collection.<br>><br>>     You need to introduce some flow control. The {active,once} socket<br>>     option is normally used for this.<br>><br>>     Sean<br>><br>>     On 16 Feb 2008, at 12:18, 瞄瞄 wrote:<br>
><br>>      > help!<br>>      ><br>>      > On Feb 16, 2008 11:32 AM, 瞄瞄 <<a href="mailto:icejmx@gmail.com">icejmx@gmail.com</a><br></div><div class="Ih2E3d">>     <mailto:<a href="mailto:icejmx@gmail.com">icejmx@gmail.com</a>>> wrote:<br>
>      > server code url<br>>      > <a href="http://icej.80s.net.cn/emssserver.erl" target="_blank">http://icej.80s.net.cn/emssserver.erl</a><br>>      ><br>>      > On Sat, Feb 16, 2008 at 11:26 AM, 瞄瞄 <<a href="mailto:icejmx@gmail.com">icejmx@gmail.com</a><br>
</div><div><div></div><div class="Wj3C7c">>     <mailto:<a href="mailto:icejmx@gmail.com">icejmx@gmail.com</a>>> wrote:<br>>      ><br>>      > Hello everyone! I recent study erlang familiar with the code to<br>
>     make a<br>>      > message transmitted server, have a problem!<br>>      ><br>>      > I development of the information transmitted server function:<br>>      > Aclient Bclient are connected to Server, and joined a group C,<br>
>     Aclient<br>>      > send message to group C , message will be transmitted to B by<br>>     group C.<br>>      > SOCKET use the binary (active true), (2) packet.<br>>      ><br>>      > News Server design:<br>
>      > Have a process responsible for monitoring all client even when the<br>>      > client connect server, another process (group_manager process)<br>>      > maintenance division List of members of the client group, each group<br>
>      > (group process) to have an process within the group responsible for<br>>      > the<br>>      > client to transmit message.<br>>      ><br>>      ><br>>      > Performance testing problems encountered by:<br>
>      > A test of million sent to the SERVER message used on the finished<br>>      > eight<br>>      > seconds, and automatic logoff, and the content of the message are the<br>>      > same, so, the test Lan network.<br>
>      > SERVER through tcpdump monitor and indeed also in the eight seconds<br>>      > are<br>>      > all the message at the end, and not from the message into the A,<br>>      > however<br>>      > SERVER transmitted to the messages with for a very long time, over 10<br>
>      > minutes, finally, I end of the process.<br>>      ><br>>      > In server,use top,the cpu is 99% by beam.smp.<br>>      > PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND<br>>      > 31586 root 17 0 70564 18m 1868 S 99.9 0.9 15:46.12 beam.smp<br>
>      ><br>>      > Is it a problem I designed a very slow ? Or as a result of the<br>>     process<br>>      > of communication? What measures can be taken tuning?<br>>      ><br>>      > Thank you help!<br>
>      ><br>>      > the server code<br>>      > # -module(emssserver).<br>>      > # -export([init/0]).<br>>      > # -define(TCP_OPTIONS,[binary,{packet, 2}, {active, true},<br>>     {reuseaddr,<br>
>      > true}]).<br>>      > # -define(PORT,7000).<br>>      > # -define(Debug,"YES").<br>>      > #<br>>      > # -ifdef(Debug).<br>>      > # -define(DEBUG(Fmt, Args), io:format(Fmt, Args)).<br>
>      > # -else.<br>>      > # -define(DEBUG(Fmt, Args), no_debug).<br>>      > # -endif.<br>>      > # -record(group,{name,gpid}).<br>>      > # -record(client, {name,pid,socket}).<br>>      > #<br>
>      > # init()-><br>>      > # {ok, Listen} = gen_tcp:listen(?PORT, ?TCP_OPTIONS),<br>>      > # register(accept_connection, spawn(fun() -><br>>     accept_connection(Listen)<br>>      > end)),<br>
>      > # register(group_manage, spawn(fun() -> group_manage([]) end)).<br>>      > #<br>>      > # accept_connection(Listen) ->%% listen new client connection<br>>      > # {ok, Socket} = gen_tcp:accept(Listen),<br>
>      > # Pid = spawn(fun() -> client_recv(Socket,"","") end),<br>>      > # gen_tcp:controlling_process(Socket,Pid),<br>>      > # accept_connection(Listen).<br>>      > #<br>
>      > # client_recv(Socket,ClientName,GroupPid)->%%client process recv<br>>      > # receive<br>>      > # {tcp, Socket, Bin} -><br>>      > # ?DEBUG("Server recv Data\r\n",""),<br>
>      > # case binary_to_term(Bin) of<br>>      > # {join,JoinName,ClientNameTmp}->%%client join<br>>      > # ?DEBUG("client_recv Join:~s ~s\r\n",[JoinName,ClientNameTmp]),<br>>      > # G=#group{name=JoinName},<br>
>      > # group_manage ! {join,G,self()},%%get group pid<br>>      > # receive<br>>      > # {grouppid,GPid}->%%recv group pid<br>>      > # ?DEBUG("Client_recv grouppid ~w ~s\r\n",[GPid,ClientNameTmp]),<br>
>      > # GPid!{join,Socket,ClientNameTmp,self()} %% send "join" msg to group<br>>      > # end,<br>>      > # client_recv(Socket,ClientNameTmp,GPid);<br>>      > # {send,GroupName,Msg}->%%send msg to group<br>
>      > # ?DEBUG("client_recv Send:~s ~s\r\n",[GroupName,Msg]),<br>>      > # GroupPid!{send,ClientName,Msg},<br>>      > # client_recv(Socket,ClientName,GroupPid)<br>>      > # end;<br>
>      > # {tcp_closed, Socket} -><br>>      > # ?DEBUG("client_recv close\r\n",[])<br>>      > # end.<br>>      > #<br>>      > # group_manage(Group)->%%manage group member<br>
>      > # ?DEBUG("group_manage start\r\n",[]),<br>>      > # receive<br>>      > # {join,JoinGroup,ClientPid}-><br>>      > # ?DEBUG("group_manage Join:~s\r\n",[JoinGroup#group.name]),<br>
>      > # case lists:keysearch(JoinGroup#group.name, #group.name, Group) of<br>>      > # false -><br>>      > # Pid=spawn(fun() -> group([]) end),<br>>      > # ?DEBUG("group_manage group pid~w\r\n",[Pid]),<br>
>      > # ClientPid!{grouppid,Pid},%%return client_recv group pid<br>>      > # JoinGroupp = #group{name=JoinGroup#group.name,gpid=Pid},<br>>      > # Gs = [JoinGroupp|Group],<br>>      > # ?DEBUG("group_manage group:~w\r\n",[Gs]),<br>
>      > # group_manage(Gs);<br>>      > # {value,SingleGroup} -><br>>      > # ?DEBUG("group_manage group is set<br>>     ~s\r\n",[SingleGroup#group.name]),<br>>      > # ClientPid!{grouppid,SingleGroup#group.gpid},<br>
>      > # group_manage(Group)<br>>      > # end<br>>      > #<br>>      > # end.<br>>      > #<br>>      > # group(Client)->%%send msg to all<br>>      > # ?DEBUG("group \r\n",[]),<br>
>      > # receive<br>>      > # {join,Socket,ClientName,CPid} -><br>>      > # ?DEBUG("group ClientName ~s\r\n",[ClientName]),<br>>      > # ?DEBUG("group Client set ~w\r\n",[Client]),<br>
>      > # case lists:keysearch(ClientName,#client.name,Client) of<br>>      > # false-><br>>      > # ?DEBUG("group new client\r\n",[]),<br>>      > # ClientNew = #client{name=ClientName,pid=CPid,socket=Socket},<br>
>      > # ClientTmp = [ClientNew|Client],<br>>      > # group(ClientTmp);<br>>      > # {value,SingleClient}-><br>>      > # ?DEBUG("group client is set ~s\r\n",[SingleClient#client.name]),<br>
>      > # group(Client)<br>>      > # end;<br>>      > # {send,ClientName,Msg}-><br>>      > # ?DEBUG("group recv client send ~s\r\n",[Msg]),<br>>      > # lists:foreach(fun(T)->send(ClientName,T,Msg) end,Client),<br>
>      > # group(Client)<br>>      > # end,<br>>      > # ok.<br>>      > #<br>>      > # send(FClientName,TClientName,Msg)-><br>>      > # if<br>>      > # FClientName /= TClientName#client.name -><br>
>      > # ?DEBUG("send f:~s t:~s<br>>      > ~s\r\n",[FClientName,TClientName#client.name,Msg]),<br>>      > # M = {FClientName,Msg},<br>>      > # gen_tcp:send(TClientName#client.socket,term_to_binary(M));<br>
>      > # true-><br>>      > # ?DEBUG("send from eq to\r\n",[])<br>>      > # end.<br>>      ><br>>      > the client code is "gen_tcp:send",iterative<br>>      ><br>
>      > the code install three linux server.<br>>      ><br>>      ><br>>      ><br>>      ><br>>      > --<br>>      > 关注:erlang,python,php,java<br>>      > ---------------------------------------------<br>
>      > 工作室博客<br>>      > <a href="http://blog.80s.net.cn" target="_blank">http://blog.80s.net.cn</a><br>>      ><br>>      ><br>>      ><br>>      > --<br>>      > 关注:erlang,python,php,java<br>
>      > ---------------------------------------------<br>>      > 工作室博客<br>>      > <a href="http://blog.80s.net.cn" target="_blank">http://blog.80s.net.cn</a><br>>      > _______________________________________________<br>
>      > erlang-questions mailing list<br></div></div>>      > <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a> <mailto:<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>><br>
<div class="Ih2E3d">>      > <a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>><br>><br>><br>><br>> --<br>
> 关注:erlang,python,php,java<br>> ---------------------------------------------<br>> 工作室博客<br>> <a href="http://blog.80s.net.cn" target="_blank">http://blog.80s.net.cn</a><br>><br>><br></div>> ------------------------------------------------------------------------<br>
<div><div></div><div class="Wj3C7c">><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></div></div></blockquote></div><br><br clear="all"><br>-- <br>关注:erlang,python,php,java<br>
---------------------------------------------<br>工作室博客<br><a href="http://blog.80s.net.cn">http://blog.80s.net.cn</a><br>