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. <br>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.<br>
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:<br><br>transmit_loop({tcp, Sock, Data}, P) when P#transdat.client == Sock -><br>
    gen_tcp:send(P#transdat.server, Data),<br>    inet:setopts(P#transdat.client, [{active, once}]),<br>    {ok, P};<br>transmit_loop({tcp, Sock, Data}, P) when P#transdat.server == Sock -><br>    gen_tcp:send(P#transdat.client, Data),<br>
    inet:setopts(P#transdat.server, [{active, once}]),<br>    {ok, P};<br>transmit_loop({start, ServerPort}, P) -><br>    {ok, Sock} = gen_tcp:connect("<a href="http://127.0.0.1">127.0.0.1</a>", ServerPort, [binary, {active, once}, {packet, 0}]),<br>
    {ok, P#transdat{server = Sock}};<br>transmit_loop({tcp_closed, _}, _) -><br>    exit(stop).<br><br>The proxy is eating more CPU time than the streaming server.<br>Is this normal behavior? The server is running  OSX 10.4<br>
<br><br>Sergej<br>