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

瞄瞄 icejmx@REDACTED
Wed Feb 20 03:02:42 CET 2008


parnell 写道:
> Was the c version faster as well?  In other words what was the
> difference in the time it took each version to process 1000000?
>
> On Feb 17, 8:16 am, 瞄瞄 <ice...@REDACTED> wrote:
>   
>> 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 <mynameis...@REDACTED>:
>>>> 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...
>>>>         
>>>> 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 <sean.hi...@REDACTED
>>>>>           
>>>> <mailto:sean.hi...@REDACTED>>:
>>>>         
>>>>> 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, 瞄瞄 <ice...@REDACTED
>>>>>>             
>>>>> <mailto:ice...@REDACTED>> wrote:
>>>>>           
>>>>>> server code url
>>>>>> http://icej.80s.net.cn/emssserver.erl
>>>>>>             
>>>>>> On Sat, Feb 16, 2008 at 11:26 AM, 瞄瞄 <ice...@REDACTED
>>>>>>             
>>>>> <mailto:ice...@REDACTED>> 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
>>>>>> erlang-questi...@REDACTED <mailto:erlang-questi...@REDACTED>
>>>>>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>>>>>             
>>>>> --
>>>>> 关注:erlang,python,php,java
>>>>> ---------------------------------------------
>>>>> 工作室博客
>>>>> http://blog.80s.net.cn
>>>>>           
>>>> ------------------------------------------------------------------------
>>>>         
>>>>> _______________________________________________
>>>>> erlang-questions mailing list
>>>>> erlang-questi...@REDACTED
>>>>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>>>>           
>>>> --
>>>> 关注:erlang,python,php,java
>>>> ---------------------------------------------
>>>> 工作室博客
>>>> http://blog.80s.net.cn
>>>> _______________________________________________
>>>> erlang-questions mailing list
>>>> erlang-questi...@REDACTED
>>>> 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...
>>
>> read more >>
>>     
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions

I tested the performance of erlang better, in the same group on the
machines and spread contrast,later.
But the server, I wrote a simple function with the spread, testing some
error.Test data are as follows:

erlang:

num send time recv time send/s recv/s
1 8.667778 23.121259 115,369.82 43,250.23
2 8.260629 20.104712 121,056.15 49,739.58
3 8.108403 21.915384 123,328.84 45,630.04
4 8.140427 21.756103 122,843.67 45,964.11
5 8.191785 20.626905 122,073.51 48,480.37
6 7.418387 21.703533 134,800.19 46,075.44
7 8.167769 21.822701 122,432.45 45,823.84
8 8.449056 21.717407 118,356.41 46,046.01
9 8.210315 21.939503 121,798.00 45,579.88
10 8.416223 21.857715 118,818.14 45,750.43
average 8.2030772 21.6565222 122,087.718 46,233.993

spread:

num send time recv time send/s recv/s
1 33.96289 42.26861 29,443.90 23,658.22
2 35.60048 39.92257 28,089.51 25,048.49
3 36.90358 40.85970 27,097.64 24,473.99
4 36.44208 45.73787 27,440.80 21,863.72
5 37.18958 43.11423 26,889.26 23,194.20
6 37.68567 43.12220 26,535.29 23,189.91
7 36.12817 46.69936 27,679.24 21,413.57
8 36.38800 43.80660 27,481.58 22,827.61
9 36.19551 48.22904 27,627.74 20,734.40
10 35.96400 46.55988 27,805.58 21,477.72
average 36.24600 44.03201 27,589.25 22,710.75



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




More information about the erlang-questions mailing list