mirror of
https://github.com/golang/go
synced 2024-11-17 01:14:53 -07:00
internal/poll: optimize the maximum amount of bytes that can be transferred by one splice(2) call
Fixes #40222 name old time/op new time/op delta Splice/tcp-to-tcp/1024-4 5.16µs ± 1% 5.17µs ± 4% ~ (p=0.481 n=10+10) Splice/tcp-to-tcp/2048-4 5.46µs ± 2% 5.48µs ± 2% ~ (p=0.617 n=10+10) Splice/tcp-to-tcp/4096-4 6.07µs ± 3% 6.09µs ± 5% ~ (p=0.927 n=10+10) Splice/tcp-to-tcp/8192-4 7.07µs ± 5% 7.16µs ± 3% ~ (p=0.324 n=10+10) Splice/tcp-to-tcp/16384-4 8.82µs ±10% 8.83µs ±11% ~ (p=1.000 n=10+10) Splice/tcp-to-tcp/32768-4 12.3µs ±12% 12.7µs ± 4% ~ (p=0.268 n=10+9) Splice/tcp-to-tcp/65536-4 22.1µs ± 3% 22.0µs ± 3% ~ (p=0.912 n=10+10) Splice/tcp-to-tcp/131072-4 40.0µs ± 4% 39.9µs ± 4% ~ (p=1.000 n=9+8) Splice/tcp-to-tcp/262144-4 69.1µs ± 3% 67.9µs ± 2% -1.67% (p=0.010 n=9+10) Splice/tcp-to-tcp/524288-4 128µs ± 3% 124µs ± 2% -2.67% (p=0.001 n=9+10) Splice/tcp-to-tcp/1048576-4 242µs ± 3% 242µs ± 2% ~ (p=0.912 n=10+10) Splice/unix-to-tcp/1024-4 1.97µs ± 3% 1.96µs ± 2% ~ (p=0.342 n=10+10) Splice/unix-to-tcp/2048-4 2.19µs ± 2% 2.21µs ± 2% ~ (p=0.150 n=9+10) Splice/unix-to-tcp/4096-4 2.52µs ± 5% 2.50µs ± 1% ~ (p=0.393 n=10+10) Splice/unix-to-tcp/8192-4 3.27µs ± 4% 3.24µs ± 7% ~ (p=0.968 n=9+10) Splice/unix-to-tcp/16384-4 4.68µs ± 9% 4.79µs ± 8% ~ (p=0.739 n=10+10) Splice/unix-to-tcp/32768-4 7.82µs ±12% 7.76µs ±12% ~ (p=0.912 n=10+10) Splice/unix-to-tcp/65536-4 17.9µs ± 3% 17.3µs ±10% ~ (p=0.661 n=9+10) Splice/unix-to-tcp/131072-4 35.9µs ± 1% 31.3µs ± 4% -12.88% (p=0.000 n=10+9) Splice/unix-to-tcp/262144-4 72.4µs ± 3% 55.4µs ± 2% -23.55% (p=0.000 n=10+10) Splice/unix-to-tcp/524288-4 146µs ± 3% 113µs ± 1% -22.87% (p=0.000 n=9+9) Splice/unix-to-tcp/1048576-4 288µs ± 3% 223µs ± 3% -22.49% (p=0.000 n=10+9) name old speed new speed delta Splice/tcp-to-tcp/1024-4 198MB/s ± 1% 198MB/s ± 4% ~ (p=0.481 n=10+10) Splice/tcp-to-tcp/2048-4 375MB/s ± 2% 374MB/s ± 2% ~ (p=0.631 n=10+10) Splice/tcp-to-tcp/4096-4 674MB/s ± 3% 673MB/s ± 5% ~ (p=0.912 n=10+10) Splice/tcp-to-tcp/8192-4 1.16GB/s ± 6% 1.15GB/s ± 3% ~ (p=0.315 n=10+10) Splice/tcp-to-tcp/16384-4 1.86GB/s ±10% 1.84GB/s ±13% ~ (p=0.720 n=10+9) Splice/tcp-to-tcp/32768-4 2.68GB/s ±13% 2.57GB/s ± 7% ~ (p=0.165 n=10+10) Splice/tcp-to-tcp/65536-4 2.97GB/s ± 3% 2.98GB/s ± 3% ~ (p=0.912 n=10+10) Splice/tcp-to-tcp/131072-4 3.28GB/s ± 4% 3.29GB/s ± 4% ~ (p=1.000 n=9+8) Splice/tcp-to-tcp/262144-4 3.80GB/s ± 3% 3.86GB/s ± 2% +1.70% (p=0.010 n=9+10) Splice/tcp-to-tcp/524288-4 4.10GB/s ± 3% 4.21GB/s ± 2% +2.74% (p=0.001 n=9+10) Splice/tcp-to-tcp/1048576-4 4.34GB/s ± 3% 4.33GB/s ± 2% ~ (p=0.912 n=10+10) Splice/unix-to-tcp/1024-4 519MB/s ± 3% 523MB/s ± 2% ~ (p=0.353 n=10+10) Splice/unix-to-tcp/2048-4 934MB/s ± 2% 926MB/s ± 2% ~ (p=0.156 n=9+10) Splice/unix-to-tcp/4096-4 1.63GB/s ± 5% 1.64GB/s ± 1% ~ (p=0.393 n=10+10) Splice/unix-to-tcp/8192-4 2.51GB/s ± 3% 2.53GB/s ± 7% ~ (p=0.968 n=9+10) Splice/unix-to-tcp/16384-4 3.52GB/s ± 8% 3.43GB/s ± 8% ~ (p=0.739 n=10+10) Splice/unix-to-tcp/32768-4 4.21GB/s ±14% 4.24GB/s ±13% ~ (p=0.912 n=10+10) Splice/unix-to-tcp/65536-4 3.65GB/s ± 5% 3.81GB/s ±11% ~ (p=0.436 n=10+10) Splice/unix-to-tcp/131072-4 3.65GB/s ± 1% 4.19GB/s ± 4% +14.81% (p=0.000 n=10+9) Splice/unix-to-tcp/262144-4 3.62GB/s ± 3% 4.73GB/s ± 2% +30.78% (p=0.000 n=10+10) Splice/unix-to-tcp/524288-4 3.59GB/s ± 3% 4.66GB/s ± 1% +29.64% (p=0.000 n=9+9) Splice/unix-to-tcp/1048576-4 3.65GB/s ± 3% 4.70GB/s ± 3% +29.01% (p=0.000 n=10+9) name old alloc/op new alloc/op delta Splice/tcp-to-tcp/1024-4 0.00B 0.00B ~ (all equal) Splice/tcp-to-tcp/2048-4 0.00B 0.00B ~ (all equal) Splice/tcp-to-tcp/4096-4 0.00B 0.00B ~ (all equal) Splice/tcp-to-tcp/8192-4 0.00B 0.00B ~ (all equal) Splice/tcp-to-tcp/16384-4 0.00B 0.00B ~ (all equal) Splice/tcp-to-tcp/32768-4 0.00B 0.00B ~ (all equal) Splice/tcp-to-tcp/65536-4 0.00B 0.00B ~ (all equal) Splice/tcp-to-tcp/131072-4 0.00B 0.00B ~ (all equal) Splice/tcp-to-tcp/262144-4 0.00B 0.00B ~ (all equal) Splice/tcp-to-tcp/524288-4 0.00B 0.00B ~ (all equal) Splice/tcp-to-tcp/1048576-4 0.00B 0.00B ~ (all equal) Splice/unix-to-tcp/1024-4 0.00B 0.00B ~ (all equal) Splice/unix-to-tcp/2048-4 0.00B 0.00B ~ (all equal) Splice/unix-to-tcp/4096-4 0.00B 0.00B ~ (all equal) Splice/unix-to-tcp/8192-4 0.00B 0.00B ~ (all equal) Splice/unix-to-tcp/16384-4 0.00B 0.00B ~ (all equal) Splice/unix-to-tcp/32768-4 0.00B 0.00B ~ (all equal) Splice/unix-to-tcp/65536-4 0.00B 0.00B ~ (all equal) Splice/unix-to-tcp/131072-4 0.00B 0.00B ~ (all equal) Splice/unix-to-tcp/262144-4 0.00B 0.00B ~ (all equal) Splice/unix-to-tcp/524288-4 0.00B 0.00B ~ (all equal) Splice/unix-to-tcp/1048576-4 0.00B 0.00B ~ (all equal) name old allocs/op new allocs/op delta Splice/tcp-to-tcp/1024-4 0.00 0.00 ~ (all equal) Splice/tcp-to-tcp/2048-4 0.00 0.00 ~ (all equal) Splice/tcp-to-tcp/4096-4 0.00 0.00 ~ (all equal) Splice/tcp-to-tcp/8192-4 0.00 0.00 ~ (all equal) Splice/tcp-to-tcp/16384-4 0.00 0.00 ~ (all equal) Splice/tcp-to-tcp/32768-4 0.00 0.00 ~ (all equal) Splice/tcp-to-tcp/65536-4 0.00 0.00 ~ (all equal) Splice/tcp-to-tcp/131072-4 0.00 0.00 ~ (all equal) Splice/tcp-to-tcp/262144-4 0.00 0.00 ~ (all equal) Splice/tcp-to-tcp/524288-4 0.00 0.00 ~ (all equal) Splice/tcp-to-tcp/1048576-4 0.00 0.00 ~ (all equal) Splice/unix-to-tcp/1024-4 0.00 0.00 ~ (all equal) Splice/unix-to-tcp/2048-4 0.00 0.00 ~ (all equal) Splice/unix-to-tcp/4096-4 0.00 0.00 ~ (all equal) Splice/unix-to-tcp/8192-4 0.00 0.00 ~ (all equal) Splice/unix-to-tcp/16384-4 0.00 0.00 ~ (all equal) Splice/unix-to-tcp/32768-4 0.00 0.00 ~ (all equal) Splice/unix-to-tcp/65536-4 0.00 0.00 ~ (all equal) Splice/unix-to-tcp/131072-4 0.00 0.00 ~ (all equal) Splice/unix-to-tcp/262144-4 0.00 0.00 ~ (all equal) Splice/unix-to-tcp/524288-4 0.00 0.00 ~ (all equal) Splice/unix-to-tcp/1048576-4 0.00 0.00 ~ (all equal) Change-Id: I899c1fdcb3f7b9997faf2b0d2336016a3f1fd3ea Reviewed-on: https://go-review.googlesource.com/c/go/+/425051 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
a52f4952cb
commit
c8bb3cff9e
@ -17,7 +17,9 @@ const (
|
||||
|
||||
// maxSpliceSize is the maximum amount of data Splice asks
|
||||
// the kernel to move in a single call to splice(2).
|
||||
maxSpliceSize = 4 << 20
|
||||
// We use 1MB as Splice writes data through a pipe, and 1MB is the default maximum pipe buffer size,
|
||||
// which is determined by /proc/sys/fs/pipe-max-size.
|
||||
maxSpliceSize = 1 << 20
|
||||
)
|
||||
|
||||
// Splice transfers at most remain bytes of data from src to dst, using the
|
||||
@ -211,6 +213,14 @@ func newPipe() *splicePipe {
|
||||
if err := syscall.Pipe2(fds[:], syscall.O_CLOEXEC|syscall.O_NONBLOCK); err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Splice will loop writing maxSpliceSize bytes from the source to the pipe,
|
||||
// and then write those bytes from the pipe to the destination.
|
||||
// Set the pipe buffer size to maxSpliceSize to optimize that.
|
||||
// Ignore errors here, as a smaller buffer size will work,
|
||||
// although it will require more system calls.
|
||||
fcntl(fds[0], syscall.F_SETPIPE_SZ, maxSpliceSize)
|
||||
|
||||
return &splicePipe{splicePipeFields: splicePipeFields{rfd: fds[0], wfd: fds[1]}}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user