Skip to content

Commit 554c0d7

Browse files
committed
Size http2 buffers to allow concurrent streams
1 parent b2b3c36 commit 554c0d7

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

staging/src/k8s.io/apiserver/pkg/server/secure_serving.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,30 @@ func (s *SecureServingInfo) Serve(handler http.Handler, shutdownTimeout time.Dur
8787
secureServer.TLSConfig.ClientCAs = s.ClientCA
8888
}
8989

90+
// At least 99% of serialized resources in surveyed clusters were smaller than 256kb.
91+
// This should be big enough to accommodate most API POST requests in a single frame,
92+
// and small enough to allow a per connection buffer of this size multiplied by `MaxConcurrentStreams`.
93+
const resourceBody99Percentile = 256 * 1024
94+
95+
http2Options := &http2.Server{}
96+
97+
// shrink the per-stream buffer and max framesize from the 1MB default while still accommodating most API POST requests in a single frame
98+
http2Options.MaxUploadBufferPerStream = resourceBody99Percentile
99+
http2Options.MaxReadFrameSize = resourceBody99Percentile
100+
101+
// use the overridden concurrent streams setting or make the default of 250 explicit so we can size MaxUploadBufferPerConnection appropriately
90102
if s.HTTP2MaxStreamsPerConnection > 0 {
91-
http2.ConfigureServer(secureServer, &http2.Server{
92-
MaxConcurrentStreams: uint32(s.HTTP2MaxStreamsPerConnection),
93-
})
103+
http2Options.MaxConcurrentStreams = uint32(s.HTTP2MaxStreamsPerConnection)
104+
} else {
105+
http2Options.MaxConcurrentStreams = 250
106+
}
107+
108+
// increase the connection buffer size from the 1MB default to handle the specified number of concurrent streams
109+
http2Options.MaxUploadBufferPerConnection = http2Options.MaxUploadBufferPerStream * int32(http2Options.MaxConcurrentStreams)
110+
111+
// apply settings to the server
112+
if err := http2.ConfigureServer(secureServer, http2Options); err != nil {
113+
return fmt.Errorf("error configuring http2: %v", err)
94114
}
95115

96116
glog.Infof("Serving securely on %s", secureServer.Addr)

0 commit comments

Comments
 (0)