[go] net/http/internal/http2: release handler write buffers when idle

0 views
Skip to first unread message

Brad Fitzpatrick (Gerrit)

unread,
1:08 AM (5 hours ago) 1:08 AM
to Brad Fitzpatrick, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, golang...@luci-project-accounts.iam.gserviceaccount.com, Nicholas Husin, Nicholas Husin, Damien Neil, golang-co...@googlegroups.com

Brad Fitzpatrick submitted the change with unreviewed changes

Unreviewed changes

2 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:

```
The name of the file: src/net/http/internal/http2/server.go
Insertions: 2, Deletions: 3.

@@ -2322,9 +2322,6 @@
didPanic := true
defer func() {
rw.rws.stream.cancelCtx()
- if req.MultipartForm != nil {
- req.MultipartForm.RemoveAll()
- }
if didPanic {
e := recover()
sc.writeFrameFromHandler(FrameWriteRequest{
@@ -2797,7 +2794,7 @@
func (w *responseWriter) FlushError() error {
rws := w.rws
if rws == nil {
- panic("Header called after Handler finished")
+ panic("Flush called after Handler finished")
}
var err error
if rws.bw != nil && rws.bw.Buffered() > 0 {
@@ -2974,8 +2971,7 @@
}
}

-// releaseWriteBuffer returns rws.bw, which must be empty, to
-// handlerWriterPool.
+// releaseWriteBuffer returns rws.bw to handlerWriterPool.
func (rws *responseWriterState) releaseWriteBuffer() {
bw := rws.bw
rws.bw = nil
```

Change information

Commit message:
net/http/internal/http2: release handler write buffers when idle

Each in-flight server response held a 4KB bufio.Writer for the
lifetime of its handler, including handlers that sit idle
mid-response for a very long time between writes, as when streaming
long polls or server-sent events. For servers with many such
concurrent streams, that's 4KB of dead weight per stream. (e.g. 40 GB
of RAM at 10M streaming conns)

Instead of tying the buffer to the responseWriterState for the whole
response, acquire it from a pool on the first buffered write and
return it to the pool whenever a Flush leaves it empty. Handlers that
never flush keep the buffer until the handler completes, as before.

Updates #80735
Change-Id: Icf7cdb5c21abb1126f6571cb00bbe2f00bf23b3c
Reviewed-by: Nicholas Husin <hu...@google.com>
Reviewed-by: Damien Neil <dn...@google.com>
Reviewed-by: Nicholas Husin <n...@golang.org>
Files:
  • M src/net/http/internal/http2/export_test.go
  • M src/net/http/internal/http2/server.go
  • M src/net/http/internal/http2/server_test.go
Change size: M
Delta: 3 files changed, 134 insertions(+), 9 deletions(-)
Branch: refs/heads/master
Submit Requirements:
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Icf7cdb5c21abb1126f6571cb00bbe2f00bf23b3c
Gerrit-Change-Number: 811680
Gerrit-PatchSet: 4
Gerrit-Owner: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Reviewer: Damien Neil <dn...@google.com>
Gerrit-Reviewer: Nicholas Husin <hu...@google.com>
Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages