tcp_benchmark: prevent "cheating" with splice

tcp_benchmark is trying to measure the performance of using netstack vs Linux
networking. However, Go tries (succeeds) to be smart and figures out it can use
splice() to copy between sockets, increasing throughput. That, however, just
distorts the benchmark: netstack copies those bytes.

In regular use this isn't an issue because netstack isn't hooked up to two
sockets, it's hooked up to one socket and one userspace process (usually the
sentry).

PiperOrigin-RevId: 575257650
This commit is contained in:
Kevin Krakauer
2023-10-20 10:35:58 -07:00
committed by gVisor bot
parent 54ef8c70dd
commit 57606c7aa1
+8 -3
View File
@@ -509,9 +509,14 @@ func main() {
}
log.Printf("incoming connection established.")
// Copy both ways.
go io.Copy(inConn, next)
go io.Copy(next, inConn)
// Copy both ways. We wrap everything in another
// Reader/Writer to prevent optimizations that
// otherwise call splice() to move data between
// sockets. That penalizes netstack, but isn't relevant
// to real use cases where only one end of netstack is
// attached to a socket.
go io.Copy(io.MultiWriter(inConn), io.MultiReader(next))
go io.Copy(io.MultiWriter(next), io.MultiReader(inConn))
// Print stats every second.
go func() {