[erlang-questions] why is gen_tcp:send slow?

Javier París Fernández javierparis@REDACTED
Thu Jun 19 21:35:40 CEST 2008


El 19/06/2008, a las 20:06, Rapsey escribió:

> It loops from another module, that way I can update the code at any  
> time without disrupting anything.
> The packets are generally a few hundred bytes big, except keyframes  
> which tend to be in the kB range. I haven't tried looking with  
> wireshark.  Still it seems a bit odd that a large CPU consumption  
> would be the symptom. The traffic is strictly one way. Either  
> someone is sending the stream or receiving it.
> The transmit could of course be written with a passive receive, but  
> the code would be significantly uglier. I'm sure someone here knows  
> if setting {active, once} every packet is CPU intensive or not.
> It seems the workings of gen_tcp is quite platform dependent. If I  
> run the code in windows, sending more than 128 bytes per gen_tcp  
> call significantly decreases network output.
> Oh and I forgot to mention I use R12B-3.

Hi,

Without being an expert.

200-300 mb/s  in small (hundreds of bytes) packets means a *lot* of  
system calls if you are doing a gen_tcp:send for each one. If you  
buffer 3 packets, you are reducing that by a factor of 3 :). I'd try  
to do an small test doing the same thing in C and compare the results.  
I think it will also eat a lot of CPU.

About the proxy CPU... I'm a bit lost about it, but speculating wildly  
it is possible that the time spent doing the system calls that gen_tcp  
is doing is added to the proxy CPU process.

Regards.


More information about the erlang-questions mailing list