[erlang-questions] why is gen_tcp:send slow?
Rapsey
rapsey@REDACTED
Thu Jun 19 10:55:22 CEST 2008
I have a streaming server written in Erlang. When it was pushing 200-300
mb/s the CPU was getting completely hammered. I traced the problem to
gen_tcp:send.
So instead of sending every audio/video packet with a single gen_tcp:send
call, I buffer 3 packets and then send them all at once. CPU consumption
dropped dramatically.
On one of the servers I have a simple proxy, the main process that sends
packets between the client and some other server looks like this:
transmit_loop({tcp, Sock, Data}, P) when P#transdat.client == Sock ->
gen_tcp:send(P#transdat.server, Data),
inet:setopts(P#transdat.client, [{active, once}]),
{ok, P};
transmit_loop({tcp, Sock, Data}, P) when P#transdat.server == Sock ->
gen_tcp:send(P#transdat.client, Data),
inet:setopts(P#transdat.server, [{active, once}]),
{ok, P};
transmit_loop({start, ServerPort}, P) ->
{ok, Sock} = gen_tcp:connect("127.0.0.1", ServerPort, [binary, {active,
once}, {packet, 0}]),
{ok, P#transdat{server = Sock}};
transmit_loop({tcp_closed, _}, _) ->
exit(stop).
The proxy is eating more CPU time than the streaming server.
Is this normal behavior? The server is running OSX 10.4
Sergej
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080619/19172f8b/attachment.htm>
More information about the erlang-questions
mailing list