Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: net/http: a configurable write buffer size for the http server #68149

Closed
oddmario opened this issue Jun 24, 2024 · 3 comments · May be fixed by #68143
Closed

proposal: net/http: a configurable write buffer size for the http server #68149

oddmario opened this issue Jun 24, 2024 · 3 comments · May be fixed by #68143
Labels
Milestone

Comments

@oddmario
Copy link

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 #68143

@gopherbot gopherbot added this to the Proposal milestone Jun 24, 2024
@seankhliao
Copy link
Member

Let's just keep the conversation in #13870

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/594196 mentions this issue: net/http: make the http server con write buffer size configurable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants