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

New configuration parameter for HTTP2 maxFrameSize. #1253

Merged
merged 1 commit into from
Sep 8, 2021

Conversation

gcjenkinson
Copy link
Contributor

Motivation:

In gRPC calls that process large payloads, the default settings of the
HTTP2 maxFrameSize (16384) within swift-nio-http2 results in significant
performance impact (for large payloads this performance impact has been
demonstrated to result in timeouts where RPCs fail to complete within
their assigned deadline).

Allowing programmatic configuration of the HTTP2 maxFrameSize when the
server is built allows the parameter to be optimised for the expected
payload sizes.

Modifications:

Added new gRPC configuration parameter for the HTTP2 parameter
maxFrameSize (which can be configured in the Server.Builder using the
new method withHTTPMaxFrameSize()).

Result:

The Server.Builder can be used to configure the HTTP2 maxFrameSize
parameter as:

Server.insecure(group: serverGroup).withHTTPMaxFrameSize(1024 * 1024)...

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Sep 7, 2021

CLA Signed

The committers are authorized under a signed CLA.

@gcjenkinson gcjenkinson force-pushed the gcj/http2-performance branch from 5c9a02a to 0faa956 Compare September 7, 2021 15:27
Comment on lines 459 to 463
private func clamped<T>(_ value: T, lower: T, upper: T) -> T where T : Comparable {
return min(max(value, lower), upper)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be expressed a little more Swift-ly as:

extension Comparable {
  fileprivate func clamped(to range: ClosedRange<Self>) -> Self {
    return min(max(self, range.lowerBound), range.upperBound)
  }
}

/// inclusive.
public var httpMaxFrameSize: Int = 16384 {
didSet(httpMaxFrameSize) {
self.httpMaxFrameSize = clamped(httpMaxFrameSize, lower: 16_384, upper: 16_777_216)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The upper-bound is off-by-one here; the upper limit should be 2^24 - 1.

@@ -332,6 +332,14 @@ extension Server {
}
}

/// The HTTP/2 max frame size. Defaults to 16384. Must be value between 2^14 and 2^24-1 octets
/// inclusive.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a note saying that we clamp the value if it's outside the range?

@glbrntt glbrntt added the 🆕 semver/minor Adds new public API. label Sep 7, 2021
@gcjenkinson gcjenkinson force-pushed the gcj/http2-performance branch from 0faa956 to 4ceab7f Compare September 8, 2021 08:15
Motivation:

In gRPC calls that process large payloads, the default settings of the
HTTP2 maxFrameSize (16384) within swift-nio-http2 results in significant
performance impact (for large payloads this performance impact has been
demonstrated to result in timeouts where RPCs fail to complete within
their assigned deadline).

Allowing programmatic configuration of the HTTP2 maxFrameSize when the
server is built allows the parameter to be optimised for the expected
payload sizes.

Modifications:

Added new gRPC configuration parameter for the HTTP2 parameter
maxFrameSize (which can be configured in the Server.Builder using the
new method `withHTTPMaxFrameSize()`).

Result:

The Server.Builder can be used to configure the HTTP2 maxFrameSize
parameter as:

Server.insecure(group: serverGroup).withHTTPMaxFrameSize(1024 * 1024)...
Copy link
Collaborator

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks @gcjenkinson!

@glbrntt glbrntt merged commit b12b52f into grpc:main Sep 8, 2021
glbrntt added a commit to glbrntt/grpc-swift that referenced this pull request Sep 8, 2021
Motivation:

Having more control over the configuration of the http/2 layer is useful
for certain performance sensitive situations. We recently exposed the
max frame size setting on the server (grpc#1253); we should do the same on
the client.

Modifications:

- Add configuration for the max frame size to the client
- Fix the clamping of the max frame size on the server (this was missed
  when reviewing grpc#1253)
- Add tests to validate that the configured values are correctly clamped
- Send `SETTINGS_INITIAL_WINDOW_SIZE` in the initial SETTINGS frame set to the
  value of the target window size.

Result:

Users have more control over HTTP/2 settings.
glbrntt added a commit that referenced this pull request Sep 8, 2021
Motivation:

Having more control over the configuration of the http/2 layer is useful
for certain performance sensitive situations. We recently exposed the
max frame size setting on the server (#1253); we should do the same on
the client.

Modifications:

- Add configuration for the max frame size to the client
- Fix the clamping of the max frame size on the server (this was missed
  when reviewing #1253)
- Add tests to validate that the configured values are correctly clamped
- Send `SETTINGS_INITIAL_WINDOW_SIZE` in the initial SETTINGS frame set to the
  value of the target window size.

Result:

Users have more control over HTTP/2 settings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants