Proposal Details
The Go http.Server
currently uses a hard coded 4 KB buffer for the response writer. In some cases, developers of certain applications may prefer increasing the default 4 KB for higher throughput and better performance.
This has been discussed previously at #13870 and at https://groups.google.com/g/golang-dev/c/OuFtcKEyGrg
The performance with the default 4 KB buffer size:
go test -test.bench=".*" -benchmem -benchtime=5s
BenchmarkBigWrite-4 100000 79756 ns/op 37929 B/op 72 allocs/op
ok mytest/httpbuf 8.857s
BenchmarkBigWrite-4 100000 78570 ns/op 37948 B/op 72 allocs/op
ok mytest/httpbuf 8.665s
BenchmarkBigWrite-4 100000 79072 ns/op 37876 B/op 72 allocs/op
ok mytest/httpbuf 8.718s
The performance with a 10 KB buffer size:
go test -test.bench=".*" -benchmem -benchtime=5s
BenchmarkBigWrite-4 100000 69645 ns/op 39890 B/op 73 allocs/op
ok mytest/httpbuf 7.692s
BenchmarkBigWrite-4 100000 69816 ns/op 39961 B/op 73 allocs/op
ok mytest/httpbuf 7.702s
BenchmarkBigWrite-4 100000 67768 ns/op 39856 B/op 73 allocs/op
ok mytest/httpbuf 7.516s
Proposed solution:
Add a configurable WriteBufferSize
option to the http.Server
struct, which then the HTTP server will use when set instead of the hard coded 4 << 10
value.
I have recently opened a pull request that possibly addresses this https://github.com/golang/go/pull/68143
Comment From: gabyhelp
Similar Issues
- net/http: make ResponseWriter buffer size configurable #7467
- net/http: make the http server con write buffer size configurable #68143
- net/http: make the http server con write buffer size configurable #68142
- net/http: Can the http.Server add set read/write buffer size? #13870
- net/http: consider adding configurable buffer sizes to Transport #22618
- net/http: server sets TCPConn writebuf through ConnContext hook will block the send of a big response body #50795
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: seankhliao
Let's just keep the conversation in #13870
Comment From: gopherbot
Change https://go.dev/cl/594196 mentions this issue: net/http: make the http server con write buffer size configurable