aboutsummaryrefslogtreecommitdiff
path: root/src/net/splice_test.go
AgeCommit message (Collapse)Author
2024-01-24net: verify if internal/poll.Splice has been called during io.CopyAndy Pan
Change-Id: I29ef35b034cd4ec401ac502bf95dbd8c3ef2a2d4 Reviewed-on: https://go-review.googlesource.com/c/go/+/552535 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2023-11-17net,os: arrange zero-copy of os.File and net.TCPConn to net.UnixConnAndy Pan
Fixes #58808 goos: linux goarch: amd64 pkg: net cpu: DO-Premium-Intel │ old │ new │ │ sec/op │ sec/op vs base │ Splice/tcp-to-unix/1024-4 3.783µ ± 10% 3.201µ ± 7% -15.40% (p=0.001 n=10) Splice/tcp-to-unix/2048-4 3.967µ ± 13% 3.818µ ± 16% ~ (p=0.971 n=10) Splice/tcp-to-unix/4096-4 4.988µ ± 16% 4.590µ ± 11% ~ (p=0.089 n=10) Splice/tcp-to-unix/8192-4 6.981µ ± 13% 5.236µ ± 9% -25.00% (p=0.000 n=10) Splice/tcp-to-unix/16384-4 10.192µ ± 9% 7.350µ ± 7% -27.89% (p=0.000 n=10) Splice/tcp-to-unix/32768-4 19.65µ ± 13% 10.28µ ± 16% -47.69% (p=0.000 n=10) Splice/tcp-to-unix/65536-4 41.89µ ± 18% 15.70µ ± 13% -62.52% (p=0.000 n=10) Splice/tcp-to-unix/131072-4 90.05µ ± 11% 29.55µ ± 10% -67.18% (p=0.000 n=10) Splice/tcp-to-unix/262144-4 170.24µ ± 15% 52.66µ ± 4% -69.06% (p=0.000 n=10) Splice/tcp-to-unix/524288-4 326.4µ ± 13% 109.3µ ± 11% -66.52% (p=0.000 n=10) Splice/tcp-to-unix/1048576-4 651.4µ ± 9% 228.3µ ± 14% -64.95% (p=0.000 n=10) geomean 29.42µ 15.62µ -46.90% │ old │ new │ │ B/s │ B/s vs base │ Splice/tcp-to-unix/1024-4 258.2Mi ± 11% 305.2Mi ± 8% +18.21% (p=0.001 n=10) Splice/tcp-to-unix/2048-4 492.5Mi ± 15% 511.7Mi ± 13% ~ (p=0.971 n=10) Splice/tcp-to-unix/4096-4 783.5Mi ± 14% 851.2Mi ± 12% ~ (p=0.089 n=10) Splice/tcp-to-unix/8192-4 1.093Gi ± 11% 1.458Gi ± 8% +33.36% (p=0.000 n=10) Splice/tcp-to-unix/16384-4 1.497Gi ± 9% 2.076Gi ± 7% +38.67% (p=0.000 n=10) Splice/tcp-to-unix/32768-4 1.553Gi ± 11% 2.969Gi ± 14% +91.17% (p=0.000 n=10) Splice/tcp-to-unix/65536-4 1.458Gi ± 23% 3.888Gi ± 11% +166.69% (p=0.000 n=10) Splice/tcp-to-unix/131072-4 1.356Gi ± 10% 4.131Gi ± 9% +204.72% (p=0.000 n=10) Splice/tcp-to-unix/262144-4 1.434Gi ± 13% 4.637Gi ± 4% +223.32% (p=0.000 n=10) Splice/tcp-to-unix/524288-4 1.497Gi ± 15% 4.468Gi ± 10% +198.47% (p=0.000 n=10) Splice/tcp-to-unix/1048576-4 1.501Gi ± 10% 4.277Gi ± 16% +184.88% (p=0.000 n=10) geomean 1.038Gi 1.954Gi +88.28% │ old │ new │ │ B/op │ B/op vs base │ Splice/tcp-to-unix/1024-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/2048-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/4096-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/8192-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/16384-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/32768-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/65536-4 1.000 ± ? 0.000 ± 0% -100.00% (p=0.001 n=10) Splice/tcp-to-unix/131072-4 2.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10) Splice/tcp-to-unix/262144-4 4.000 ± 25% 0.000 ± 0% -100.00% (p=0.000 n=10) Splice/tcp-to-unix/524288-4 7.500 ± 33% 0.000 ± 0% -100.00% (p=0.000 n=10) Splice/tcp-to-unix/1048576-4 17.00 ± 12% 0.00 ± 0% -100.00% (p=0.000 n=10) geomean ² ? ² ³ ¹ all samples are equal ² summaries must be >0 to compute geomean ³ ratios must be >0 to compute geomean │ old │ new │ │ allocs/op │ allocs/op vs base │ Splice/tcp-to-unix/1024-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/2048-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/4096-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/8192-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/16384-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/32768-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/65536-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/131072-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/262144-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/524288-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/1048576-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ geomean ² +0.00% ² ¹ all samples are equal ² summaries must be >0 to compute geomean Change-Id: I829061b009a0929a8ef1a15c183793c0b9104dde Reviewed-on: https://go-review.googlesource.com/c/go/+/472475 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-02-28net: use /dev/null for TestSplice of big file to fix the test flakes on ↵Andy Pan
linux-riscv64-jsing Fixes #58787 Change-Id: Ia6e9ee0d8dd505f64bfe9ffd23a868b8165f550f Reviewed-on: https://go-review.googlesource.com/c/go/+/471995 Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Andy Pan <panjf2000@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-02-27os: support zero-copy from TCP/Unix socket to fileAndy Pan
Go currently supports the cases of zero-copy: from TCP/Unix socket to TCP socket, from file to TCP socket, from file to file. Now implementing the new support of zero-copy: from TCP/Unix socket to file. goos: linux goarch: amd64 pkg: net cpu: DO-Premium-Intel │ old │ new │ │ sec/op │ sec/op vs base │ SpliceFile/tcp-to-file/1024-4 5.910µ ± 9% 4.116µ ± 13% -30.35% (p=0.000 n=10) SpliceFile/tcp-to-file/2048-4 6.150µ ± 10% 4.077µ ± 13% -33.72% (p=0.002 n=10) SpliceFile/tcp-to-file/4096-4 4.837µ ± 28% 4.447µ ± 23% ~ (p=0.353 n=10) SpliceFile/tcp-to-file/8192-4 9.309µ ± 7% 6.293µ ± 9% -32.40% (p=0.000 n=10) SpliceFile/tcp-to-file/16384-4 19.43µ ± 12% 12.48µ ± 9% -35.76% (p=0.000 n=10) SpliceFile/tcp-to-file/32768-4 42.73µ ± 10% 25.32µ ± 8% -40.76% (p=0.000 n=10) SpliceFile/tcp-to-file/65536-4 70.37µ ± 11% 48.60µ ± 4% -30.93% (p=0.000 n=10) SpliceFile/tcp-to-file/131072-4 141.91µ ± 6% 96.24µ ± 4% -32.18% (p=0.000 n=10) SpliceFile/tcp-to-file/262144-4 329.7µ ± 8% 246.7µ ± 13% -25.19% (p=0.000 n=10) SpliceFile/tcp-to-file/524288-4 653.5µ ± 7% 441.6µ ± 7% -32.43% (p=0.000 n=10) SpliceFile/tcp-to-file/1048576-4 1184.4µ ± 9% 851.8µ ± 14% -28.09% (p=0.000 n=10) SpliceFile/unix-to-file/1024-4 1.734µ ± 10% 1.524µ ± 25% -12.06% (p=0.035 n=10) SpliceFile/unix-to-file/2048-4 2.614µ ± 7% 2.231µ ± 8% -14.65% (p=0.000 n=10) SpliceFile/unix-to-file/4096-4 5.081µ ± 7% 3.947µ ± 11% -22.33% (p=0.000 n=10) SpliceFile/unix-to-file/8192-4 8.560µ ± 5% 8.531µ ± 17% ~ (p=0.796 n=10) SpliceFile/unix-to-file/16384-4 18.09µ ± 12% 12.92µ ± 25% -28.59% (p=0.000 n=10) SpliceFile/unix-to-file/32768-4 35.50µ ± 5% 24.50µ ± 6% -31.00% (p=0.000 n=10) SpliceFile/unix-to-file/65536-4 69.99µ ± 7% 51.22µ ± 23% -26.82% (p=0.000 n=10) SpliceFile/unix-to-file/131072-4 133.7µ ± 17% 119.7µ ± 6% -10.43% (p=0.000 n=10) SpliceFile/unix-to-file/262144-4 246.5µ ± 5% 207.3µ ± 19% -15.90% (p=0.007 n=10) SpliceFile/unix-to-file/524288-4 484.8µ ± 20% 382.9µ ± 10% -21.02% (p=0.000 n=10) SpliceFile/unix-to-file/1048576-4 1188.4µ ± 27% 781.8µ ± 11% -34.21% (p=0.000 n=10) geomean 42.24µ 31.45µ -25.53% │ old │ new │ │ B/s │ B/s vs base │ SpliceFile/tcp-to-file/1024-4 165.4Mi ± 10% 237.3Mi ± 11% +43.47% (p=0.000 n=10) SpliceFile/tcp-to-file/2048-4 317.6Mi ± 12% 479.7Mi ± 14% +51.02% (p=0.002 n=10) SpliceFile/tcp-to-file/4096-4 808.2Mi ± 22% 886.8Mi ± 19% ~ (p=0.353 n=10) SpliceFile/tcp-to-file/8192-4 839.3Mi ± 6% 1241.5Mi ± 8% +47.91% (p=0.000 n=10) SpliceFile/tcp-to-file/16384-4 804.7Mi ± 13% 1252.2Mi ± 10% +55.61% (p=0.000 n=10) SpliceFile/tcp-to-file/32768-4 731.3Mi ± 11% 1234.3Mi ± 7% +68.78% (p=0.000 n=10) SpliceFile/tcp-to-file/65536-4 888.7Mi ± 10% 1286.2Mi ± 4% +44.73% (p=0.000 n=10) SpliceFile/tcp-to-file/131072-4 880.9Mi ± 6% 1299.0Mi ± 4% +47.47% (p=0.000 n=10) SpliceFile/tcp-to-file/262144-4 758.2Mi ± 7% 1014.4Mi ± 15% +33.78% (p=0.000 n=10) SpliceFile/tcp-to-file/524288-4 765.3Mi ± 7% 1132.5Mi ± 7% +47.99% (p=0.000 n=10) SpliceFile/tcp-to-file/1048576-4 845.0Mi ± 8% 1174.0Mi ± 16% +38.94% (p=0.000 n=10) SpliceFile/unix-to-file/1024-4 564.2Mi ± 11% 640.5Mi ± 20% +13.53% (p=0.035 n=10) SpliceFile/unix-to-file/2048-4 747.4Mi ± 7% 875.7Mi ± 8% +17.17% (p=0.000 n=10) SpliceFile/unix-to-file/4096-4 768.8Mi ± 6% 989.8Mi ± 10% +28.74% (p=0.000 n=10) SpliceFile/unix-to-file/8192-4 912.9Mi ± 5% 915.8Mi ± 15% ~ (p=0.796 n=10) SpliceFile/unix-to-file/16384-4 863.6Mi ± 10% 1209.7Mi ± 20% +40.06% (p=0.000 n=10) SpliceFile/unix-to-file/32768-4 880.2Mi ± 6% 1275.7Mi ± 6% +44.93% (p=0.000 n=10) SpliceFile/unix-to-file/65536-4 893.0Mi ± 7% 1220.3Mi ± 19% +36.66% (p=0.000 n=10) SpliceFile/unix-to-file/131072-4 935.1Mi ± 14% 1043.9Mi ± 7% +11.64% (p=0.000 n=10) SpliceFile/unix-to-file/262144-4 1014.2Mi ± 6% 1205.9Mi ± 16% +18.91% (p=0.007 n=10) SpliceFile/unix-to-file/524288-4 1.007Gi ± 17% 1.275Gi ± 9% +26.61% (p=0.000 n=10) SpliceFile/unix-to-file/1048576-4 841.8Mi ± 21% 1279.0Mi ± 10% +51.94% (p=0.000 n=10) geomean 740.1Mi 994.2Mi +34.33% │ old │ new │ │ B/op │ B/op vs base │ SpliceFile/tcp-to-file/1024-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/tcp-to-file/2048-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/tcp-to-file/4096-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/tcp-to-file/8192-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/tcp-to-file/16384-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/tcp-to-file/32768-4 1.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10) SpliceFile/tcp-to-file/65536-4 1.000 ± 100% 0.000 ± 0% -100.00% (p=0.000 n=10) SpliceFile/tcp-to-file/131072-4 3.000 ± 33% 0.000 ± 0% -100.00% (p=0.000 n=10) SpliceFile/tcp-to-file/262144-4 8.500 ± 18% 0.000 ± 0% -100.00% (p=0.000 n=10) SpliceFile/tcp-to-file/524288-4 16.50 ± 21% 0.00 ± 0% -100.00% (p=0.000 n=10) SpliceFile/tcp-to-file/1048576-4 30.50 ± 15% 0.00 ± 0% -100.00% (p=0.000 n=10) SpliceFile/unix-to-file/1024-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/unix-to-file/2048-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/unix-to-file/4096-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/unix-to-file/8192-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/unix-to-file/16384-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/unix-to-file/32768-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/unix-to-file/65536-4 1.000 ± 100% 0.000 ± 0% -100.00% (p=0.000 n=10) SpliceFile/unix-to-file/131072-4 3.000 ± 33% 0.000 ± 0% -100.00% (p=0.000 n=10) SpliceFile/unix-to-file/262144-4 6.000 ± 17% 0.000 ± 0% -100.00% (p=0.000 n=10) SpliceFile/unix-to-file/524288-4 12.00 ± 8% 0.00 ± 0% -100.00% (p=0.000 n=10) SpliceFile/unix-to-file/1048576-4 33.50 ± 10% 0.00 ± 0% -100.00% (p=0.000 n=10) geomean ² ? ² ³ ¹ all samples are equal ² summaries must be >0 to compute geomean ³ ratios must be >0 to compute geomean │ old │ new │ │ allocs/op │ allocs/op vs base │ SpliceFile/tcp-to-file/1024-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/tcp-to-file/2048-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/tcp-to-file/4096-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/tcp-to-file/8192-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/tcp-to-file/16384-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/tcp-to-file/32768-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/tcp-to-file/65536-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/tcp-to-file/131072-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/tcp-to-file/262144-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/tcp-to-file/524288-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/tcp-to-file/1048576-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/unix-to-file/1024-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/unix-to-file/2048-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/unix-to-file/4096-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/unix-to-file/8192-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/unix-to-file/16384-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/unix-to-file/32768-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/unix-to-file/65536-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/unix-to-file/131072-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/unix-to-file/262144-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/unix-to-file/524288-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ SpliceFile/unix-to-file/1048576-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ geomean ² +0.00% ² ¹ all samples are equal ² summaries must be >0 to compute geomean Change-Id: Ie7f7d4d7b6b373d9ee7ce6da8f6a4cd157632486 Reviewed-on: https://go-review.googlesource.com/c/go/+/466015 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Andy Pan <panjf2000@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
2021-12-13net: create unix sockets in unique directoriesBryan C. Mills
This change applies the same transformation as in CL 366774, but to the net package. testUnixAddr was using os.CreateTemp to obtain a unique socket path, but then calling os.Remove on that path immediately. Since the existence of the file is what guarantees its uniqueness, that could occasionally result in testUnixAddr returning the same path for two calls, causing the tests using those paths to fail — especially if they are the same test or are run in parallel. Instead, we now create a unique, short temp directory for each call, and use a path within that directory for the socket address. For #34611 Change-Id: I8e13b606abce2479a0305f7aeecf5d54c449a032 Reviewed-on: https://go-review.googlesource.com/c/go/+/370694 Trust: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-12-13net: pass a testing.TB to newLocal* helpersBryan C. Mills
Passing in an explicit testing.TB gives two benefits: 1. It allows the helper to fail the test itself, instead of returning an error to the caller. A non-nil error invariably fails the calling test, and none of these callers bother to add detail to the error when logging it anyway so returning the error just added noise to the test bodies. 2. It allows the helper to use t.Cleanup to perform any needed cleanup tasks, which will be used in CL 370695 to clean up temp directories used as namespaces for unix socket paths. For #34611 Change-Id: I805e701687c12de2caca955649369294229c10b4 Reviewed-on: https://go-review.googlesource.com/c/go/+/370696 Trust: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-10-28all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor)Russ Cox
When these packages are released as part of Go 1.18, Go 1.16 will no longer be supported, so we can remove the +build tags in these files. Ran go fix -fix=buildtag std cmd and then reverted the bootstrapDirs as defined in src/cmd/dist/buildtool.go, which need to continue to build with Go 1.4 for now. Also reverted src/vendor and src/cmd/vendor, which will need to be updated in their own repos first. Manual changes in runtime/pprof/mprof_test.go to adjust line numbers. For #41184. Change-Id: Ic0f93f7091295b6abc76ed5cd6e6746e1280861e Reviewed-on: https://go-review.googlesource.com/c/go/+/344955 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-02-20all: go fmt std cmd (but revert vendor)Russ Cox
Make all our package sources use Go 1.17 gofmt format (adding //go:build lines). Part of //go:build change (#41184). See https://golang.org/design/draft-gobuild Change-Id: Ia0534360e4957e58cd9a18429c39d0e32a6addb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/294430 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-10-20all: update references to symbols moved from io/ioutil to ioRuss Cox
The old ioutil references are still valid, but update our code to reflect best practices and get used to the new locations. Code compiled with the bootstrap toolchain (cmd/asm, cmd/dist, cmd/compile, debug/elf) must remain Go 1.4-compatible and is excluded. Also excluded vendored code. For #41190. Change-Id: I6d86f2bf7bc37a9d904b6cee3fe0c7af6d94d5b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/263142 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-04-07net: pass TMPDIR to test client processElias Naur
Fixes the TestSplice test on Android where the default TMPDIR (/data/local/tmp) might not be available. Change-Id: I4f104d11254ba855b1bd2dfa0547d69b7bce4878 Reviewed-on: https://go-review.googlesource.com/c/go/+/170947 Run-TryBot: Elias Naur <mail@eliasnaur.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-02-26net: remove unixgram test socketsIan Lance Taylor
Updates https://gcc.gnu.org/PR89406 Change-Id: Iccf2760e42e9caa90720b96e74a805a9c0d48f35 Reviewed-on: https://go-review.googlesource.com/c/163277 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Mikio Hara <mikioh.public.networking@gmail.com> Reviewed-by: Than McIntosh <thanm@google.com>
2018-09-24net: don't use splice for unix{packet,gram} connectionsAndrei Tudor Călin
As pointed out in the aftermath of CL 113997, splice is not supported for SOCK_SEQPACKET or SOCK_DGRAM unix sockets. Don't call poll.Splice in those cases. Change-Id: Ieab18fb0ae706fdeb249e3f54d51a3292e3ead62 Reviewed-on: https://go-review.googlesource.com/136635 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-09-05net: don't block forever in splice test cleanup on failureBrad Fitzpatrick
The ppc64x builders are failing on the new splice test from CL 113997 but the actual failure is being obscured by a test deadlock. Change-Id: I7747f88bcdba9776a3c0d2f5066cfec572706108 Reviewed-on: https://go-review.googlesource.com/133417 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2018-09-05net: skip splice unix-to-tcp tests on androidTobias Klauser
The android builders are failing on the AF_UNIX part of the new splice test from CL 113997. Skip them. Change-Id: Ia0519aae922acb11d2845aa687633935bcd4b1b0 Reviewed-on: https://go-review.googlesource.com/133515 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-09-05net: use splice(2) on Linux when reading from UnixConn, rework splice testsBen Burkert
Rework the splice tests and benchmarks. Move the reading and writing of the spliced connections to child processes so that the I/O is not part of benchmarks or profiles. Enable the use of splice(2) when reading from a unix connection and writing to a TCP connection. The updated benchmarks show a performance gain when using splice(2) to copy large chunks of data that the original benchmark did not capture. name old time/op new time/op delta Splice/tcp-to-tcp/1024-8 5.01µs ± 2% 5.08µs ± 3% ~ (p=0.068 n=8+10) Splice/tcp-to-tcp/2048-8 4.76µs ± 5% 4.65µs ± 3% -2.36% (p=0.015 n=9+8) Splice/tcp-to-tcp/4096-8 4.91µs ± 2% 4.98µs ± 5% ~ (p=0.315 n=9+10) Splice/tcp-to-tcp/8192-8 5.50µs ± 4% 5.44µs ± 3% ~ (p=0.758 n=7+9) Splice/tcp-to-tcp/16384-8 7.65µs ± 7% 6.53µs ± 3% -14.65% (p=0.000 n=10+9) Splice/tcp-to-tcp/32768-8 15.3µs ± 7% 8.5µs ± 5% -44.21% (p=0.000 n=10+10) Splice/tcp-to-tcp/65536-8 30.0µs ± 6% 15.7µs ± 1% -47.58% (p=0.000 n=10+8) Splice/tcp-to-tcp/131072-8 59.2µs ± 2% 27.4µs ± 5% -53.75% (p=0.000 n=9+9) Splice/tcp-to-tcp/262144-8 121µs ± 4% 54µs ±19% -55.56% (p=0.000 n=9+10) Splice/tcp-to-tcp/524288-8 247µs ± 6% 108µs ±12% -56.34% (p=0.000 n=10+10) Splice/tcp-to-tcp/1048576-8 490µs ± 4% 199µs ±12% -59.31% (p=0.000 n=8+10) Splice/unix-to-tcp/1024-8 1.20µs ± 2% 1.35µs ± 7% +12.47% (p=0.000 n=10+10) Splice/unix-to-tcp/2048-8 1.33µs ±12% 1.57µs ± 4% +17.85% (p=0.000 n=9+10) Splice/unix-to-tcp/4096-8 2.24µs ± 4% 1.67µs ± 4% -25.14% (p=0.000 n=9+10) Splice/unix-to-tcp/8192-8 4.59µs ± 8% 2.20µs ±10% -52.01% (p=0.000 n=10+10) Splice/unix-to-tcp/16384-8 8.46µs ±13% 3.48µs ± 6% -58.91% (p=0.000 n=10+10) Splice/unix-to-tcp/32768-8 18.5µs ± 9% 6.1µs ± 9% -66.99% (p=0.000 n=10+10) Splice/unix-to-tcp/65536-8 35.9µs ± 7% 13.5µs ± 6% -62.40% (p=0.000 n=10+9) Splice/unix-to-tcp/131072-8 79.4µs ± 6% 25.7µs ± 4% -67.62% (p=0.000 n=10+9) Splice/unix-to-tcp/262144-8 157µs ± 4% 54µs ± 8% -65.63% (p=0.000 n=10+10) Splice/unix-to-tcp/524288-8 311µs ± 3% 107µs ± 8% -65.74% (p=0.000 n=10+10) Splice/unix-to-tcp/1048576-8 643µs ± 4% 185µs ±32% -71.21% (p=0.000 n=10+10) name old speed new speed delta Splice/tcp-to-tcp/1024-8 204MB/s ± 2% 202MB/s ± 3% ~ (p=0.068 n=8+10) Splice/tcp-to-tcp/2048-8 430MB/s ± 5% 441MB/s ± 3% +2.39% (p=0.014 n=9+8) Splice/tcp-to-tcp/4096-8 833MB/s ± 2% 823MB/s ± 5% ~ (p=0.315 n=9+10) Splice/tcp-to-tcp/8192-8 1.49GB/s ± 4% 1.51GB/s ± 3% ~ (p=0.758 n=7+9) Splice/tcp-to-tcp/16384-8 2.14GB/s ± 7% 2.51GB/s ± 3% +17.03% (p=0.000 n=10+9) Splice/tcp-to-tcp/32768-8 2.15GB/s ± 7% 3.85GB/s ± 5% +79.11% (p=0.000 n=10+10) Splice/tcp-to-tcp/65536-8 2.19GB/s ± 5% 4.17GB/s ± 1% +90.65% (p=0.000 n=10+8) Splice/tcp-to-tcp/131072-8 2.22GB/s ± 2% 4.79GB/s ± 4% +116.26% (p=0.000 n=9+9) Splice/tcp-to-tcp/262144-8 2.17GB/s ± 4% 4.93GB/s ±17% +127.25% (p=0.000 n=9+10) Splice/tcp-to-tcp/524288-8 2.13GB/s ± 6% 4.89GB/s ±13% +130.15% (p=0.000 n=10+10) Splice/tcp-to-tcp/1048576-8 2.09GB/s ±10% 5.29GB/s ±11% +153.36% (p=0.000 n=10+10) Splice/unix-to-tcp/1024-8 850MB/s ± 2% 757MB/s ± 7% -10.94% (p=0.000 n=10+10) Splice/unix-to-tcp/2048-8 1.54GB/s ±11% 1.31GB/s ± 3% -15.32% (p=0.000 n=9+10) Splice/unix-to-tcp/4096-8 1.83GB/s ± 4% 2.45GB/s ± 4% +33.59% (p=0.000 n=9+10) Splice/unix-to-tcp/8192-8 1.79GB/s ± 9% 3.73GB/s ± 9% +108.05% (p=0.000 n=10+10) Splice/unix-to-tcp/16384-8 1.95GB/s ±13% 4.68GB/s ± 3% +139.80% (p=0.000 n=10+9) Splice/unix-to-tcp/32768-8 1.78GB/s ± 9% 5.38GB/s ±10% +202.71% (p=0.000 n=10+10) Splice/unix-to-tcp/65536-8 1.83GB/s ± 8% 4.85GB/s ± 6% +165.70% (p=0.000 n=10+9) Splice/unix-to-tcp/131072-8 1.65GB/s ± 6% 5.10GB/s ± 4% +208.77% (p=0.000 n=10+9) Splice/unix-to-tcp/262144-8 1.67GB/s ± 4% 4.87GB/s ± 7% +191.19% (p=0.000 n=10+10) Splice/unix-to-tcp/524288-8 1.69GB/s ± 3% 4.93GB/s ± 7% +192.38% (p=0.000 n=10+10) Splice/unix-to-tcp/1048576-8 1.63GB/s ± 3% 5.60GB/s ±44% +243.26% (p=0.000 n=10+9) Change-Id: I1eae4c3459c918558c70fc42283db22ff7e0442c Reviewed-on: https://go-review.googlesource.com/113997 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-30net: refactor readerAtEOF splice testAndrei Tudor Călin
Refactor TestSplice/readerAtEOF to handle cases where we disable splice on older kernels better. If splice is disabled, net.splice and poll.Splice do not get to observe EOF on the reader, because poll.Splice returns immediately with EINVAL. The test fails unexpectedly, because the splice operation is reported as not handled. This change refactors the test to handle the aforementioned case correctly, by not calling net.splice directly, but using a higher level check. Fixes #27355. Change-Id: I0d5606b4775213f2dbbb84ef82ddfc3bab662a31 Reviewed-on: https://go-review.googlesource.com/132096 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-08-08net: reduce TestSplice/big's memory usageDaniel Martí
The old code used splice on a 2GB []byte when not in short mode, meaning that running 'go test net' when one had 4GB or less free memory would easily result in "out of memory" runtime panics. Instead, use a much smaller size that is still big enough to not fit into a single splice(2) syscall. The new size is just 5MB, so the test uses a fraction of the memory it used to, and there's no longer a need for a different size on short mode. This also speeds up the test, which goes from ~1.23s to ~0.01s on my laptop. Fixes #26867. Change-Id: Iae1daa5c0995b549f41992f44339be32ca1ee5e4 Reviewed-on: https://go-review.googlesource.com/128535 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Andrei Tudor Călin <mail@acln.ro> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-06-21internal/poll: use more fine-grained locking in SpliceAndrei Tudor Călin
The previous code acquired a read lock on src and a write lock on dst for the entire duration of Splice. This resulted in deadlock, in a situation akin to the following: Splice is blocking, waiting to read from src. The caller tries to close dst from another goroutine, but Close on dst blocks in runtime.semacquire, because Splice is still holding a write lock on it, and the Close didn't unblock any I/O. The caller cannot unblock the read side of Splice through other means, because they are stuck waiting in dst.Close(). Use more fine-grained locking instead: acquire the read lock on src just before trying to splice from the source socket to the pipe, and acquire the write lock on dst just before trying to splice from the pipe to the destination socket. Fixes #25985 Change-Id: I264c91c7a69bb6c5e28610e2bd801244804cf86d Reviewed-on: https://go-review.googlesource.com/120317 Run-TryBot: Aram Hăvărneanu <aram@mgk.ro> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-04-24net: add support for splice(2) in (*TCPConn).ReadFrom on LinuxAndrei Tudor Călin
This change adds support for the splice system call on Linux, for the purpose of optimizing (*TCPConn).ReadFrom by reducing copies of data from and to userspace. It does so by creating a temporary pipe and splicing data from the source connection to the pipe, then from the pipe to the destination connection. The pipe serves as an in-kernel buffer for the data transfer. No new API is added to package net, but a new Splice function is added to package internal/poll, because using splice requires help from the network poller. Users of the net package should benefit from the change transparently. This change only enables the optimization if the Reader in ReadFrom is a TCP connection. Since splice is a more general interface, it could, in theory, also be enabled if the Reader were a unix socket, or the read half of a pipe. However, benchmarks show that enabling it for unix sockets is most likely not a net performance gain. The tcp <- unix case is also fairly unlikely to be used very much by users of package net. Enabling the optimization for pipes is also problematic from an implementation perspective, since package net cannot easily get at the *poll.FD of an *os.File. A possible solution to this would be to dup the pipe file descriptor, register the duped descriptor with the network poller, and work on that *poll.FD instead of the original. However, this seems too intrusive, so it has not been done. If there was a clean way to do it, it would probably be worth doing, since splicing from a pipe to a socket can be done directly. Therefore, this patch only enables the optimization for what is likely the most common use case: tcp <- tcp. The following benchmark compares the performance of the previous userspace genericReadFrom code path to the new optimized code path. The sub-benchmarks represent chunk sizes used by the writer on the other end of the Reader passed to ReadFrom. benchmark old ns/op new ns/op delta BenchmarkTCPReadFrom/1024-4 4727 4954 +4.80% BenchmarkTCPReadFrom/2048-4 4389 4301 -2.01% BenchmarkTCPReadFrom/4096-4 4606 4534 -1.56% BenchmarkTCPReadFrom/8192-4 5219 4779 -8.43% BenchmarkTCPReadFrom/16384-4 8708 8008 -8.04% BenchmarkTCPReadFrom/32768-4 16349 14973 -8.42% BenchmarkTCPReadFrom/65536-4 35246 27406 -22.24% BenchmarkTCPReadFrom/131072-4 72920 52382 -28.17% BenchmarkTCPReadFrom/262144-4 149311 95094 -36.31% BenchmarkTCPReadFrom/524288-4 306704 181856 -40.71% BenchmarkTCPReadFrom/1048576-4 674174 357406 -46.99% benchmark old MB/s new MB/s speedup BenchmarkTCPReadFrom/1024-4 216.62 206.69 0.95x BenchmarkTCPReadFrom/2048-4 466.61 476.08 1.02x BenchmarkTCPReadFrom/4096-4 889.09 903.31 1.02x BenchmarkTCPReadFrom/8192-4 1569.40 1714.06 1.09x BenchmarkTCPReadFrom/16384-4 1881.42 2045.84 1.09x BenchmarkTCPReadFrom/32768-4 2004.18 2188.41 1.09x BenchmarkTCPReadFrom/65536-4 1859.38 2391.25 1.29x BenchmarkTCPReadFrom/131072-4 1797.46 2502.21 1.39x BenchmarkTCPReadFrom/262144-4 1755.69 2756.68 1.57x BenchmarkTCPReadFrom/524288-4 1709.42 2882.98 1.69x BenchmarkTCPReadFrom/1048576-4 1555.35 2933.84 1.89x Fixes #10948 Change-Id: I3ce27f21f7adda8b696afdc48a91149998ae16a5 Reviewed-on: https://go-review.googlesource.com/107715 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>