help!<br><br><div class="gmail_quote">On Feb 16, 2008 11:32 AM, 瞄瞄 <<a href="mailto:icejmx@gmail.com">icejmx@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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><div class="gmail_quote"><div class="Ih2E3d">On Sat, Feb 16, 2008 at 11:26 AM, 瞄瞄 <<a href="mailto:icejmx@gmail.com" target="_blank">icejmx@gmail.com</a>> wrote:<br>
</div><div><div></div><div class="Wj3C7c"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
Hello everyone! I recent study erlang familiar with the code to 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, Aclient<br>
send message to group C , message will be transmitted to B by 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 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 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 are<br>
all the message at the end, and not from the message into the A, 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 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}, {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() -> 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 ~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>
</blockquote></div></div></div><font color="#888888"><br><br clear="all"><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>
</font></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>