Turning off nagle's algorithm for http.Client

959 views
Skip to first unread message

hay

unread,
Oct 8, 2016, 9:46:08 AM10/8/16
to golang-nuts
Hi,

I'm using http.Client to make restful calls, turning off nagle's algorithm will help as messages are very short and response time needs to be fast. Is there a way to check or/and set to turn off 'NoDelay'/Nagle's algorithm for http.Client ( https://golang.org/pkg/net/http/#Client ) ?

Regards and thanks in advance,


Janne Snabb

unread,
Oct 8, 2016, 4:10:27 PM10/8/16
to golan...@googlegroups.com
In the http.Client that you use, specify your own Transport where you
specify your own DialContext function which Dials first and then calls
SetNoDelay on the connection before returning.

Janne Snabb
sn...@epipe.com
> --
> You received this message because you are subscribed to the Google
> Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to golang-nuts...@googlegroups.com
> <mailto:golang-nuts...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

Sokolov Yura

unread,
Oct 9, 2016, 3:02:00 AM10/9/16
to golang-nuts
Looks lije SetNoDelay is already called on dial.

Look into source.

hay

unread,
Oct 9, 2016, 11:50:40 PM10/9/16
to golang-nuts
@Janne, thanks got it working.

@Sokolov, I don't see it set in dial code. I'm using 1.6.* version.

Sokolov Yura

unread,
Oct 10, 2016, 2:16:27 AM10/10/16
to golang-nuts
Read carefully, and you will not need to do redundant work and write redundant code.

It is really here: https://github.com/golang/go/blob/release-branch.go1.6/src/net/tcpsock_posix.go

If you don't see it... Then you reading skill is weak.

hay

unread,
Oct 10, 2016, 11:53:32 AM10/10/16
to golang-nuts
I stand corrected, it is there in "newTCPConn" function.
Reply all
Reply to author
Forward
0 new messages