aboutsummaryrefslogtreecommitdiff
path: root/src/net/sendfile_test.go
AgeCommit message (Collapse)Author
2026-03-10runtime/poll: fix race condition in Window's SendFileqmuntal
The destination of SendFile is a socket, which doesn't support file offsets. There is no need to keep track of the file offset, and doing so causes a race between SendFile and Read. While here, make sure that SendFile tests do call poll.SendFile. Fixes #78015 Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-race,gotip-linux-amd64-race Change-Id: I8cce45c0c110e848d9bdbc5ba340b92ca041f0a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/752860 Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Mark Freeman <markfreeman@google.com>
2025-05-20net: avoid using Windows' TransmitFile on non-server machinesShibi J M
Windows API's TransmitFile function is limited to two concurrent operations on workstation and client versions of Windows. This change modifies the net.sendFile function to perform no work in such cases so that TransmitFile is avoided. Fixes #73746 Change-Id: Iba70d5d2758bf986e80c78254c8e9e10b39bb368 GitHub-Last-Rev: 315ddc0cd8034f52632dc31baf35057a8bad9bcd GitHub-Pull-Request: golang/go#73758 Reviewed-on: https://go-review.googlesource.com/c/go/+/673855 Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2025-04-10net: deduplicate sendfile filesqmuntal
The sendfile implementation for platforms supporting it is now in net/sendfile.go, rather than being duplicated in separate files for each platform. The only difference between the implementations was the poll.SendFile parameters, which have been harmonized, and also linux strictly asserting for os.File, which now have been relaxed to allow any type implementing syscall.Conn. Change-Id: Ia1a2d5ee7380710a36fc555dbf681f7e996ea2ec Reviewed-on: https://go-review.googlesource.com/c/go/+/664075 Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Quim Muntal <quimmuntal@gmail.com>
2025-04-10net: reenable sendfile on Windowsqmuntal
Windows sendfile optimization is skipped since CL 472475, which started passing an os.fileWithoutWriteTo instead of an os.File to sendfile, and that function was only implemented for os.File. This CL fixes the issue by asserting against an interface rather than a concrete type. Some tests have been reenabled, triggering bugs in poll.SendFile which have been fixed in this CL. Fixes #67042. Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-longtest Change-Id: Id6f7a0e1e0f34a72216fa9d00c5bf36f5a994219 Reviewed-on: https://go-review.googlesource.com/c/go/+/664055 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2024-11-01internal/poll: fix the inaccurate comment and add a edge test caseAndy Pan
*BSD can also returns (>0, EAGAIN) with non-blocking socket, it's therefore not macOS-specific. Change-Id: I57a393da31fab7788ad5779a038396be8236b0f9 Reviewed-on: https://go-review.googlesource.com/c/go/+/623056 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-10-28os, net, internal/poll: combine unix sendfile implementationsDamien Neil
The internal/poll/sendfile_{bsd,linux,solaris}.go implementations have more in common than not. Combine into a single sendfile_unix.go. The net and os packages have redundant code dealing with sendfile quirks on non-Linux Unix systems, such as the need to determine the size of the source file before sending. Move the common code into internal/poll. Remove some obsolete or incorrect behaviors: Drop the maximum sendfile chunk size. If we ask the kernel to copy more data than it is willing to send, it'll copy up to its limit. There was a comment in net/sendfile_unix_alt.go indicating that copying more bytes than a file contains results in the kernel looping back to the start of the file. I am unable to replicate this behavior anywhere. Dropped the comment, the workarounds, and added a test covering this case. Darwin, Dragonfly, and FreeBSD all support copying the entire contents of a file by passing 0 for the copy limit. Take advantage of this. Change-Id: I9f707ac7a27c165020ae02a6b5bb8f6f16f3c530 Reviewed-on: https://go-review.googlesource.com/c/go/+/621416 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-04-26net, os, internal/poll: test for use of sendfileDamien Neil
The net package's sendfile tests exercise various paths where we expect sendfile to be used, but don't verify that sendfile was in fact used. Add a hook to internal/poll.SendFile to let us verify that sendfile was called when expected. Update os package tests (which use their own hook mechanism) to use this hook as well. For #66988 Change-Id: I7afb130dcfe0063d60c6ea0f8560cf8665ad5a81 Reviewed-on: https://go-review.googlesource.com/c/go/+/581778 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-10net: skip BenchmarkSendFile on WindowsAndy Pan
Follow up CL 543276 Change-Id: Ie02cf8a489a069bb0a3be1d8636e30d0658329c5 Reviewed-on: https://go-review.googlesource.com/c/go/+/562595 Reviewed-by: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
2024-02-07net: support benchmark testing for sendfile on various platformsAndy Pan
When I introduced the benchmark test code for sendfile(2) in CL 425878, I only did it on Linux while the sendfile system call is also available on other Unix-like and Windows platforms, this CL will pick up where I left out. goos: darwin goarch: arm64 pkg: net BenchmarkSendFile/file-to-tcp/1024-10 2240488 749.5 ns/op 1366.30 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-tcp/2048-10 1956669 850.4 ns/op 2408.38 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-tcp/4096-10 840103 1593 ns/op 2571.30 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-tcp/8192-10 449536 2881 ns/op 2843.35 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-tcp/16384-10 269974 6307 ns/op 2597.86 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-tcp/32768-10 137210 12646 ns/op 2591.09 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-tcp/65536-10 66642 24557 ns/op 2668.74 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-tcp/131072-10 37852 59550 ns/op 2201.03 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-tcp/262144-10 16288 107859 ns/op 2430.44 MB/s 2 B/op 0 allocs/op BenchmarkSendFile/file-to-tcp/524288-10 10540 249957 ns/op 2097.52 MB/s 3 B/op 0 allocs/op BenchmarkSendFile/file-to-tcp/1048576-10 4982 419750 ns/op 2498.09 MB/s 6 B/op 0 allocs/op BenchmarkSendFile/file-to-unix/1024-10 1180185 1187 ns/op 862.66 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-unix/2048-10 523159 2294 ns/op 892.78 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-unix/4096-10 238792 5223 ns/op 784.29 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-unix/8192-10 116611 10929 ns/op 749.58 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-unix/16384-10 57568 19870 ns/op 824.57 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-unix/32768-10 32280 33696 ns/op 972.47 MB/s 1 B/op 0 allocs/op BenchmarkSendFile/file-to-unix/65536-10 17242 72122 ns/op 908.69 MB/s 1 B/op 0 allocs/op BenchmarkSendFile/file-to-unix/131072-10 8350 159131 ns/op 823.67 MB/s 3 B/op 0 allocs/op BenchmarkSendFile/file-to-unix/262144-10 3872 318000 ns/op 824.35 MB/s 8 B/op 0 allocs/op BenchmarkSendFile/file-to-unix/524288-10 1766 600785 ns/op 872.67 MB/s 18 B/op 0 allocs/op BenchmarkSendFile/file-to-unix/1048576-10 993 1138624 ns/op 920.92 MB/s 33 B/op 0 allocs/op goos: linux goarch: amd64 pkg: net cpu: DO-Premium-AMD BenchmarkSendFile/file-to-tcp/1024-8 1796002 716.3 ns/op 1429.59 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-tcp/2048-8 1196700 896.6 ns/op 2284.23 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-tcp/4096-8 923604 2385 ns/op 1717.48 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-tcp/8192-8 638967 9722 ns/op 842.60 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-tcp/16384-8 357740 18710 ns/op 875.67 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-tcp/32768-8 147417 17489 ns/op 1873.66 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-tcp/65536-8 113054 58818 ns/op 1114.21 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-tcp/131072-8 57981 113202 ns/op 1157.86 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-tcp/262144-8 26362 253376 ns/op 1034.61 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-tcp/524288-8 13767 442053 ns/op 1186.03 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-tcp/1048576-8 4906 829984 ns/op 1263.37 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-unix/1024-8 2031691 628.9 ns/op 1628.36 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-unix/2048-8 1294472 965.0 ns/op 2122.30 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-unix/4096-8 1005753 1203 ns/op 3404.27 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-unix/8192-8 865448 6412 ns/op 1277.65 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-unix/16384-8 268946 12801 ns/op 1279.89 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-unix/32768-8 153398 6691 ns/op 4897.23 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-unix/65536-8 88911 11969 ns/op 5475.36 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-unix/131072-8 48639 107538 ns/op 1218.84 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-unix/262144-8 22720 203199 ns/op 1290.09 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-unix/524288-8 12034 97126 ns/op 5398.03 MB/s 0 B/op 0 allocs/op BenchmarkSendFile/file-to-unix/1048576-8 5374 202308 ns/op 5183.06 MB/s 0 B/op 0 allocs/op Change-Id: Ib9507bd9837ecb38b1702afa89502da18806929c Reviewed-on: https://go-review.googlesource.com/c/go/+/543276 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-10-23net,internal/poll: mark it as handled even if sendfile(2) succeeded with 0 ↵Andy Pan
bytes sent CL 415834 fixed #53658 and somehow it only fixed it on Linux, sendfile can also succeed with 0 bytes sent on other platforms according to their manuals, this CL will finish the work that CL 415834 left out on other platforms. goos: darwin goarch: arm64 pkg: net │ old │ new │ │ sec/op │ sec/op vs base │ SendfileZeroBytes-10 7.563µ ± 5% 7.184µ ± 6% -5.01% (p=0.009 n=10) │ old │ new │ │ B/op │ B/op vs base │ SendfileZeroBytes-10 3562.5 ± 7% 590.0 ± 2% -83.44% (p=0.000 n=10) │ old │ new │ │ allocs/op │ allocs/op vs base │ SendfileZeroBytes-10 0.00 ± 0% 11.00 ± 0% ? (p=0.000 n=10) [1] https://man.freebsd.org/cgi/man.cgi?sendfile(2) [2] https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/sendfile.2.html [3] https://man.dragonflybsd.org/?command=sendfile&section=2 [4] https://docs.oracle.com/cd/E88353_01/html/E37843/sendfile-3c.html Change-Id: I55832487595ee8e0f44f367cf2a3a1d827ba590d Reviewed-on: https://go-review.googlesource.com/c/go/+/536455 Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Bryan Mills <bcmills@google.com>
2023-09-18net: enable most tests on wasip1 and jsBryan C. Mills
To get them to pass, implement more fake syscalls. To make those syscalls easier to reason about, replace the use of sync.Cond with selectable channels. Fixes #59718. Fixes #50216. Change-Id: I135a6656f5c48f0e5c43dc4d4bcbdb48ee5535d2 Reviewed-on: https://go-review.googlesource.com/c/go/+/526117 Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Achille Roussel <achille.roussel@gmail.com> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-04-11net: add wasip1 supportJohan Brandhorst-Satzkorn
For #58141 Co-authored-by: Richard Musiol <neelance@gmail.com> Co-authored-by: Achille Roussel <achille.roussel@gmail.com> Co-authored-by: Julien Fabre <ju.pryz@gmail.com> Co-authored-by: Evan Phoenix <evan@phx.io> Change-Id: I09a7cf33e43cb0e17ab3793c22cbad90b9e83b62 Reviewed-on: https://go-review.googlesource.com/c/go/+/479626 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-08all: use io.Seek* instead of deprecated os.SEEK_*Tobias Klauser
These are available since Go 1.7. The version used for bootstrap is Go 1.17 for Go 1.20. For #44505 Change-Id: I497c9f617baefdeb273cd115b08b6e31bd10aad2 Reviewed-on: https://go-review.googlesource.com/c/go/+/421634 Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
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-03-09net: use io.Discard in TestSendfileOnWriteTimeoutExceededTobias Klauser
Replace ioutil.Discard which is deprecated as of Go 1.16. This was already done in CL 263142 but accidentially re-introduced in CL 285914. Change-Id: Ife0944d416294b1ba7c8f6b602aa68a3b9213c50 Reviewed-on: https://go-review.googlesource.com/c/go/+/299989 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org>
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>
2021-02-16internal/poll: netpollcheckerr before sendfileWei Fu
In net/http package, the ServeContent/ServeFile doesn't check the I/O timeout error from chunkWriter or *net.TCPConn, which means that both HTTP status and headers might be missing when WriteTimeout happens. If the poll.SendFile() doesn't check the *poll.FD state before sending data, the client will only receive the response body with status and report "malformed http response/status code". This patch is to enable netpollcheckerr before sendfile, which should align with normal *poll.FD.Write() and Splice(). Fixes #43822 Change-Id: I32517e3f261bab883a58b577b813ef189214b954 Reviewed-on: https://go-review.googlesource.com/c/go/+/285914 Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Trust: Emmanuel Odeke <emmanuel@orijtech.com> Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
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-10-09all: remove the nacl port (part 1)Brad Fitzpatrick
You were a useful port and you've served your purpose. Thanks for all the play. A subsequent CL will remove amd64p32 (including assembly files and toolchain bits) and remaining bits. The amd64p32 removal will be separated into its own CL in case we want to support the Linux x32 ABI in the future and want our old amd64p32 support as a starting point. Updates #30439 Change-Id: Ia3a0c7d49804adc87bf52a4dea7e3d3007f2b1cd Reviewed-on: https://go-review.googlesource.com/c/go/+/199499 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-12-28os: don't let sendFile put a pipe into blocking modeIan Lance Taylor
Use SyscallConn to avoid calling the Fd method in sendFile on Unix systems, since Fd has the side effect of putting the descriptor into blocking mode. Fixes #28330 Change-Id: If093417a225fe44092bd2c0dbbc3937422e98c0b Reviewed-on: https://go-review.googlesource.com/c/155137 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-10-01Revert "compress: move benchmark text from src/testdata to ↵Katie Hockman
src/compress/testdata" This reverts commit 067bb443af6b44cb026ab182a26d157dbd1b2dd6. Reason for revert: Failing Darwin-arm builds because that testing environment does not access testdata from sibling directories. A future change will likely be made to move this testdata out of src/testdata to create a solution that doesn't require the single-file directory. Updates #27151 Change-Id: I8dbf5dd9512c94a605ee749ff4655cb00b0de686 Reviewed-on: https://go-review.googlesource.com/138737 Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2018-09-28compress: move benchmark text from src/testdata to src/compress/testdataKatie Hockman
This text is used mainly for benchmark compression testing, and in one net test. The text was prevoiusly in a src/testdata directory, but since that directory would only include one file, the text is moved to the existing src/compression/testdata directory. This does not cause any change to the benchmark results. Updates #27151 Change-Id: I38ab5089dfe744189a970947d15be50ef1d48517 Reviewed-on: https://go-review.googlesource.com/138495 Run-TryBot: Katie Hockman <katie@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-09-24compress: reduce copies of new text for compression testingKatie Hockman
The previous book was 387 KiB decompressed and 119 KiB compressed, the new book is 567 KiB decompressed and 132 KiB compressed. Overall, this change will reduce the release binary size by 196 KiB. The new book will allow for slightly more extensive compression testing with a larger text. Command to run the benchmark tests used with benchstat: `../bin/go test -run='^$' -count=4 -bench=. compress/bzip2 compress/flate` When running the benchmarks locally, changed "Newton" to "Twain" and filtered the tests with the -bench flag to include only those which were relevant to these changes. benchstat results below: name old time/op new time/op delta DecodeTwain-8 19.6ms ± 2% 24.1ms ± 1% +23.04% (p=0.029 n=4+4) Decode/Twain/Huffman/1e4-8 140µs ± 3% 139µs ± 5% ~ (p=0.886 n=4+4) Decode/Twain/Huffman/1e5-8 1.27ms ± 3% 1.26ms ± 1% ~ (p=1.000 n=4+4) Decode/Twain/Huffman/1e6-8 12.4ms ± 0% 13.2ms ± 1% +6.42% (p=0.029 n=4+4) Decode/Twain/Speed/1e4-8 133µs ± 1% 123µs ± 1% -7.35% (p=0.029 n=4+4) Decode/Twain/Speed/1e5-8 1.20ms ± 0% 1.02ms ± 3% -15.32% (p=0.029 n=4+4) Decode/Twain/Speed/1e6-8 12.0ms ± 2% 10.1ms ± 3% -15.89% (p=0.029 n=4+4) Decode/Twain/Default/1e4-8 131µs ± 6% 108µs ± 5% -17.84% (p=0.029 n=4+4) Decode/Twain/Default/1e5-8 1.06ms ± 2% 0.80ms ± 1% -24.97% (p=0.029 n=4+4) Decode/Twain/Default/1e6-8 10.0ms ± 3% 8.0ms ± 3% -20.06% (p=0.029 n=4+4) Decode/Twain/Compression/1e4-8 128µs ± 4% 115µs ± 4% -9.70% (p=0.029 n=4+4) Decode/Twain/Compression/1e5-8 1.04ms ± 2% 0.83ms ± 4% -20.37% (p=0.029 n=4+4) Decode/Twain/Compression/1e6-8 10.4ms ± 4% 8.1ms ± 5% -22.25% (p=0.029 n=4+4) Encode/Twain/Huffman/1e4-8 55.7µs ± 2% 55.6µs ± 1% ~ (p=1.000 n=4+4) Encode/Twain/Huffman/1e5-8 441µs ± 0% 435µs ± 2% ~ (p=0.343 n=4+4) Encode/Twain/Huffman/1e6-8 4.31ms ± 4% 4.30ms ± 4% ~ (p=0.886 n=4+4) Encode/Twain/Speed/1e4-8 193µs ± 1% 166µs ± 2% -14.09% (p=0.029 n=4+4) Encode/Twain/Speed/1e5-8 1.54ms ± 1% 1.22ms ± 1% -20.53% (p=0.029 n=4+4) Encode/Twain/Speed/1e6-8 15.3ms ± 1% 12.2ms ± 3% -20.62% (p=0.029 n=4+4) Encode/Twain/Default/1e4-8 393µs ± 1% 390µs ± 1% ~ (p=0.114 n=4+4) Encode/Twain/Default/1e5-8 6.12ms ± 4% 6.02ms ± 5% ~ (p=0.486 n=4+4) Encode/Twain/Default/1e6-8 69.4ms ± 5% 59.0ms ± 4% -15.07% (p=0.029 n=4+4) Encode/Twain/Compression/1e4-8 423µs ± 2% 379µs ± 2% -10.34% (p=0.029 n=4+4) Encode/Twain/Compression/1e5-8 7.00ms ± 1% 7.88ms ± 3% +12.49% (p=0.029 n=4+4) Encode/Twain/Compression/1e6-8 76.6ms ± 5% 80.9ms ± 3% ~ (p=0.114 n=4+4) name old speed new speed delta DecodeTwain-8 19.8MB/s ± 2% 23.6MB/s ± 1% +18.84% (p=0.029 n=4+4) Decode/Twain/Huffman/1e4-8 71.7MB/s ± 3% 72.1MB/s ± 6% ~ (p=0.943 n=4+4) Decode/Twain/Huffman/1e5-8 78.8MB/s ± 3% 79.5MB/s ± 1% ~ (p=1.000 n=4+4) Decode/Twain/Huffman/1e6-8 80.5MB/s ± 0% 75.6MB/s ± 1% -6.03% (p=0.029 n=4+4) Decode/Twain/Speed/1e4-8 75.2MB/s ± 1% 81.2MB/s ± 1% +7.93% (p=0.029 n=4+4) Decode/Twain/Speed/1e5-8 83.4MB/s ± 0% 98.6MB/s ± 3% +18.16% (p=0.029 n=4+4) Decode/Twain/Speed/1e6-8 83.6MB/s ± 2% 99.5MB/s ± 3% +18.91% (p=0.029 n=4+4) Decode/Twain/Default/1e4-8 76.3MB/s ± 6% 92.8MB/s ± 4% +21.62% (p=0.029 n=4+4) Decode/Twain/Default/1e5-8 94.4MB/s ± 3% 125.7MB/s ± 1% +33.24% (p=0.029 n=4+4) Decode/Twain/Default/1e6-8 100MB/s ± 3% 125MB/s ± 3% +25.12% (p=0.029 n=4+4) Decode/Twain/Compression/1e4-8 78.4MB/s ± 4% 86.8MB/s ± 4% +10.73% (p=0.029 n=4+4) Decode/Twain/Compression/1e5-8 95.7MB/s ± 2% 120.3MB/s ± 4% +25.65% (p=0.029 n=4+4) Decode/Twain/Compression/1e6-8 96.4MB/s ± 4% 124.0MB/s ± 5% +28.64% (p=0.029 n=4+4) Encode/Twain/Huffman/1e4-8 179MB/s ± 2% 180MB/s ± 1% ~ (p=1.000 n=4+4) Encode/Twain/Huffman/1e5-8 227MB/s ± 0% 230MB/s ± 2% ~ (p=0.343 n=4+4) Encode/Twain/Huffman/1e6-8 232MB/s ± 4% 233MB/s ± 4% ~ (p=0.886 n=4+4) Encode/Twain/Speed/1e4-8 51.8MB/s ± 1% 60.4MB/s ± 2% +16.43% (p=0.029 n=4+4) Encode/Twain/Speed/1e5-8 65.1MB/s ± 1% 81.9MB/s ± 1% +25.83% (p=0.029 n=4+4) Encode/Twain/Speed/1e6-8 65.2MB/s ± 1% 82.2MB/s ± 3% +26.00% (p=0.029 n=4+4) Encode/Twain/Default/1e4-8 25.4MB/s ± 1% 25.6MB/s ± 1% ~ (p=0.114 n=4+4) Encode/Twain/Default/1e5-8 16.4MB/s ± 4% 16.6MB/s ± 5% ~ (p=0.486 n=4+4) Encode/Twain/Default/1e6-8 14.4MB/s ± 6% 17.0MB/s ± 4% +17.67% (p=0.029 n=4+4) Encode/Twain/Compression/1e4-8 23.6MB/s ± 2% 26.4MB/s ± 2% +11.54% (p=0.029 n=4+4) Encode/Twain/Compression/1e5-8 14.3MB/s ± 1% 12.7MB/s ± 3% -11.08% (p=0.029 n=4+4) Encode/Twain/Compression/1e6-8 13.1MB/s ± 4% 12.4MB/s ± 3% ~ (p=0.114 n=4+4) name old alloc/op new alloc/op delta DecodeTwain-8 3.63MB ± 0% 3.63MB ± 0% +0.15% (p=0.029 n=4+4) Decode/Twain/Huffman/1e4-8 42.0kB ± 0% 41.3kB ± 0% -1.62% (p=0.029 n=4+4) Decode/Twain/Huffman/1e5-8 43.5kB ± 0% 45.1kB ± 0% +3.74% (p=0.029 n=4+4) Decode/Twain/Huffman/1e6-8 71.7kB ± 0% 80.0kB ± 0% +11.55% (p=0.029 n=4+4) Decode/Twain/Speed/1e4-8 41.2kB ± 0% 41.3kB ± 0% ~ (p=0.286 n=4+4) Decode/Twain/Speed/1e5-8 45.1kB ± 0% 43.9kB ± 0% -2.80% (p=0.029 n=4+4) Decode/Twain/Speed/1e6-8 72.8kB ± 0% 81.3kB ± 0% +11.72% (p=0.029 n=4+4) Decode/Twain/Default/1e4-8 41.2kB ± 0% 41.2kB ± 0% -0.22% (p=0.029 n=4+4) Decode/Twain/Default/1e5-8 44.4kB ± 0% 43.0kB ± 0% -3.02% (p=0.029 n=4+4) Decode/Twain/Default/1e6-8 71.0kB ± 0% 61.8kB ± 0% -13.00% (p=0.029 n=4+4) Decode/Twain/Compression/1e4-8 41.3kB ± 0% 41.2kB ± 0% -0.29% (p=0.029 n=4+4) Decode/Twain/Compression/1e5-8 43.3kB ± 0% 43.0kB ± 0% -0.72% (p=0.029 n=4+4) Decode/Twain/Compression/1e6-8 69.1kB ± 0% 63.7kB ± 0% -7.90% (p=0.029 n=4+4) name old allocs/op new allocs/op delta DecodeTwain-8 51.0 ± 0% 51.2 ± 1% ~ (p=1.000 n=4+4) Decode/Twain/Huffman/1e4-8 15.0 ± 0% 14.0 ± 0% -6.67% (p=0.029 n=4+4) Decode/Twain/Huffman/1e5-8 20.0 ± 0% 23.0 ± 0% +15.00% (p=0.029 n=4+4) Decode/Twain/Huffman/1e6-8 134 ± 0% 161 ± 0% +20.15% (p=0.029 n=4+4) Decode/Twain/Speed/1e4-8 17.0 ± 0% 18.0 ± 0% +5.88% (p=0.029 n=4+4) Decode/Twain/Speed/1e5-8 30.0 ± 0% 31.0 ± 0% +3.33% (p=0.029 n=4+4) Decode/Twain/Speed/1e6-8 193 ± 0% 228 ± 0% +18.13% (p=0.029 n=4+4) Decode/Twain/Default/1e4-8 17.0 ± 0% 15.0 ± 0% -11.76% (p=0.029 n=4+4) Decode/Twain/Default/1e5-8 28.0 ± 0% 32.0 ± 0% +14.29% (p=0.029 n=4+4) Decode/Twain/Default/1e6-8 199 ± 0% 158 ± 0% -20.60% (p=0.029 n=4+4) Decode/Twain/Compression/1e4-8 17.0 ± 0% 15.0 ± 0% -11.76% (p=0.029 n=4+4) Decode/Twain/Compression/1e5-8 28.0 ± 0% 32.0 ± 0% +14.29% (p=0.029 n=4+4) Decode/Twain/Compression/1e6-8 196 ± 0% 150 ± 0% -23.47% (p=0.029 n=4+4) Updates #27151 Change-Id: I6c439694ed16a33bb4c63fbfb8570c7de46b4f2d Reviewed-on: https://go-review.googlesource.com/135495 Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2018-08-22internal/poll, net: fix sendfile on Windows, add testBrad Fitzpatrick
Fixes #27085 Change-Id: I4eb3ff7c76e0b8e4d8fe0298f739b0284d74a031 Reviewed-on: https://go-review.googlesource.com/130855 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-06-12net: update file read position after sendfile syscallTobias Klauser
On dragonfly, freebsd and solaris the sendfile syscall does not update the read position of the source fd. Update it after sendfile so successive calls start at the correct position. Fixes #25809 Change-Id: Iaac79f89704b75b8038d4bb60eaf793a262cdd8f Reviewed-on: https://go-review.googlesource.com/117895 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-11net: skip TestSendfileParts on dragonfly and solarisTobias Klauser
Skip it like on freebsd until there is proper a fix for #25809 Updates #25809 Change-Id: Id53c433aee75f2a992ab6a8d58d98fd1f8a6c1c6 Reviewed-on: https://go-review.googlesource.com/117698 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2018-06-11net: add TestSendfilePartsAlex Brainman
Add test for freebsd issue #25809. This test also fails on my Windows 10 Version 1803. My hope is that adding new test will break one of our builders. Updates #25722 Updates #25809 Change-Id: Ia103bc708b8fa3b9af57613acc44893f90b3fa18 Reviewed-on: https://go-review.googlesource.com/117775 Run-TryBot: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-04net: add js/wasm architectureRichard Musiol
This commit adds the js/wasm architecture to the net package. The net package is not supported by js/wasm, but a simple fake networking is available so tests of other packages that require basic TCP sockets can pass. The tests of the net package itself are mostly disabled. Updates #18892 Change-Id: Id287200c39f0a3e23d20ef17260ca15ccdcca032 Reviewed-on: https://go-review.googlesource.com/109995 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-04-12net: mirror Tom Sawyer in the net package for testsBrad Fitzpatrick
Fixes the darwin/arm builder, which has a special test runner which makes the assumption that tests never use testdata from another package. This looks large, but it's no more space in git. Change-Id: I81921b516443d12d21b77617d323ddebedbe40f8 Reviewed-on: https://go-review.googlesource.com/21907 Reviewed-by: David Crawshaw <crawshaw@golang.org> Run-TryBot: David Crawshaw <crawshaw@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-12net: broken sendfile on SmartOS/SolarisShawn Walker-Salas
In the event of a partial write on Solaris and some BSDs, the offset pointer passed to sendfile() will be updated even though the function returns -1 if errno is set to EAGAIN/EINTR. In that case, calculate the bytes written based on the difference between the updated offset and the original offset. If no bytes were written, and errno is set to EAGAIN/EINTR, ignore the errno. Fixes #13892 Change-Id: I6334b5ef2edcbebdaa7db36fa4f7785967313c2d Reviewed-on: https://go-review.googlesource.com/21769 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>