@@ -87,10 +87,30 @@ func (s *SecureServingInfo) Serve(handler http.Handler, shutdownTimeout time.Dur
87
87
secureServer .TLSConfig .ClientCAs = s .ClientCA
88
88
}
89
89
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
90
102
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 )
94
114
}
95
115
96
116
glog .Infof ("Serving securely on %s" , secureServer .Addr )
0 commit comments