[erlang-questions] Re: Unicast 20k messages, $500-$1000 bounty

Witold Baryluk baryluk@REDACTED
Thu Jul 23 22:30:42 CEST 2009


Dnia 2009-07-17, pią o godzinie 12:39 +0200, Ulf Wiger pisze:
> Joel Reymont wrote:
> 
> > Jim,
> > 
> > On Jul 17, 2009, at 11:12 AM, Jim Morris wrote:
> > 
> >> It is Socket programming 101 that writes can block when the TCP
> >> receiver does not read and the flow control causes the TCP buffers to
> >> backup.
> > 
> > This all makes sense. I will redo the code using just 1 middleman 
> > process then.
> 
> You may want to consider the following passage from the inet man page
> on setopts/2:
> 
> {delay_send, Boolean}
> Normally, when an Erlang process sends to a socket, the driver will try 
> to immediately send the data. If that fails, the driver will use any 
> means available to queue up the message to be sent whenever the 
> operating system says it can handle it. Setting {delay_send, true} will 
> make all messages queue up. This makes the messages actually sent onto 
> the network be larger but fewer. The option actually affects the 
> scheduling of send requests versus Erlang processes instead of changing 
> any real property of the socket. Needless to say it is an implementation 
> specific option. Default is false.
> 
> I'm not sure if setting {delay_send, true} would have any beneficial
> effect on your particular problem, but the text does shed some light
> on the semantics of sending to a socket.
> 
> BR,
> Ulf W

There is also similar way of doing this under Linux. Linux' TCP sockets,
have option called TCP_CORK. This is generally delay_send (but in kernel
space). See man page tcp(7) for details, and other useful socket
options.

This is way I access this option in Erlang.

cork(TcpSocket) ->
 inet:setopts(TcpSocket,[{raw,6,3,<<1:32/native>>}]).
uncork(TcpSocket) ->
 inet:setopts(TcpSocket,[{raw,6,3,<<0:32/native>>}]).

Witek

-- 
Witold Baryluk <baryluk@REDACTED>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: To jest cz??? wiadomo?ci podpisana cyfrowo
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090723/f588f60c/attachment.bin>


More information about the erlang-questions mailing list