[erlang-questions] help about process,why very slow.

瞄瞄 <>
Sun Feb 17 15:16:32 CET 2008


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


-- 
关注:erlang,python,java,php
--------------------------------
工作室博客http://blog.80s.net.cn




More information about the erlang-questions mailing list