The writev syscall is supposed to act like a single write. The WriteTo method of net.Buffers will make a single write syscall on writers that have the unexported writeBuffers method. However, for writers that do not have such a method, it will call Write multiple times. This becomes significant if you are wrapping a *net.TCPConn without embedding, for instance, since it has different performance characteristics with respect to Nagle's algorithm. Frustratingly, since the writeBuffers method is unexported, there's no way for the application to know the behavior of Buffers.WriteTo in order to work around the issue.
Repro case: https://play.golang.org/p/rF0JRZs8z8
The
writevsyscall is supposed to act like a single write. TheWriteTomethod ofnet.Bufferswill make a single write syscall on writers that have the unexportedwriteBuffersmethod. However, for writers that do not have such a method, it will callWritemultiple times. This becomes significant if you are wrapping a*net.TCPConnwithout embedding, for instance, since it has different performance characteristics with respect to Nagle's algorithm. Frustratingly, since thewriteBuffersmethod is unexported, there's no way for the application to know the behavior ofBuffers.WriteToin order to work around the issue.Repro case: https://play.golang.org/p/rF0JRZs8z8