[erlang-questions] How about the net IO ability of erlang

igwan igwan@REDACTED
Wed Sep 10 13:26:28 CEST 2008


leon zhao wrote :
> I worte a tcp proxy to forward data from peer to peer, but i find the 
> CPU usage of beam is high in test
> The client make 1000 connections per second and get 16K data from 
> server, and the server send 8K to client per second, because we want 
> to decrease the traffic.
> And the compute's CPU is Intel(R) Xeon(TM) CPU 3.20GHz, so the proxy's 
> usage is on avenage 26%
> Is my codes have some problem or erlang need some optimization.
> Anyone can tell me
>  
> here is my codes
>  
> [...]
> tcp_start(CSock, SSock, Cfg) ->
>     inet:setopts(CSock, [{active, true}, {packet,raw}, binary]),
>     tcp_data_loop(CSock, SSock, Cfg).
> [...]
Hi,

Just a few hints from a non-expert. You're using the {active, true} mode 
for your client socket. Try other modes like {active, once} (which was 
optimized in R12B-4) or {active, false}. Or a combination of the two : 
set {active, once} and when receiving the message, use gen_tcp:recv/2 to 
get the rest of available data, then set the socket to {active, once} 
again, ...
This should make a big difference in CPU usage vs. {active, true}.

--
igwan



More information about the erlang-questions mailing list