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

net/http: make ResponseWriter buffer size configurable #7467

Closed
alberts opened this issue Mar 4, 2014 · 4 comments
Closed

net/http: make ResponseWriter buffer size configurable #7467

alberts opened this issue Mar 4, 2014 · 4 comments
Milestone

Comments

@alberts
Copy link
Contributor

alberts commented Mar 4, 2014

What steps reproduce the problem?

I've been doing some tests here with a net/http server where the handler makes many
relatively small writes of binary data to the ResponseWriter. I am ranging over some
key-values with a LevelDB iterator, and writing a bunch of the values.

The underlying bufio.Writer's size is hard-coded at 4k:

http://golang.org/src/pkg/net/http/server.go#L433

With this size, my throughput is about 65 MB/sec. Increasing to 64k gets me to 90MB/sec
and a 1M buffer gets me to 140 MB/sec.

The throughput of writing net/http responses can be significantly improved by making the
write buffer configurable.

Discussion here:

https://groups.google.com/d/msg/golang-dev/OuFtcKEyGrg/VyKo_LqOhK8J

Please provide any additional information below.

The fix is two lines.

Given that there's still 173 Go 1.3 bugs open, I would implore you to let me send a CL
now rather than wait another 6 months. But anyway.
@gopherbot
Copy link

Comment 1 by islandberry33:

Because bufio Writer handles large writes without buffering
(https://code.google.com/p/go/source/browse/src/pkg/bufio/bufio.go#532), wrapping the
response writer with a large bufio Writer should achieve OP's goal.

@ianlancetaylor
Copy link
Contributor

Comment 2:

Labels changed: added repo-main, release-go1.4.

@rsc
Copy link
Contributor

rsc commented Sep 16, 2014

Comment 3:

I agree with comment #1: put your own buffering in the handlers that need it, and
everything will work fine.

Status changed to WorkingAsIntended.

@bradfitz
Copy link
Contributor

Comment 4:

I thought I looked into this and remembered it being outside the user's control. I
should've written down some notes at the time.

@rsc rsc added this to the Go1.4 milestone Apr 14, 2015
@rsc rsc removed the release-go1.4 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants