From 6e1f90a225863a6b603ef623cf5a0988fe2d68ff Mon Sep 17 00:00:00 2001 From: George Barnett Date: Wed, 25 Aug 2021 13:42:25 +0100 Subject: [PATCH] Raise the default HTTP/2 target window size Motivation: The default flow control window size is 64kb which is quite small. As a result connections may spend longer than necessary waiting for window updates. Modifications: Increase the target window size to 8MB. Result: HTTP target window size is 8MB by default. --- Sources/GRPC/ClientConnection.swift | 6 +++--- Sources/GRPC/GRPCChannel/GRPCChannelBuilder.swift | 2 +- Sources/GRPC/Server.swift | 6 +++--- Sources/GRPC/ServerBuilder.swift | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/GRPC/ClientConnection.swift b/Sources/GRPC/ClientConnection.swift index 3372cb5f3..8919c5c3b 100644 --- a/Sources/GRPC/ClientConnection.swift +++ b/Sources/GRPC/ClientConnection.swift @@ -341,9 +341,9 @@ extension ClientConnection { /// Defaults to `waitsForConnectivity`. public var callStartBehavior: CallStartBehavior = .waitsForConnectivity - /// The HTTP/2 flow control target window size. Defaults to 65535. Values are clamped between + /// The HTTP/2 flow control target window size. Defaults to 8MB. Values are clamped between /// 1 and 2^31-1 inclusive. - public var httpTargetWindowSize = 65535 { + public var httpTargetWindowSize = 8 * 1024 * 1024 { didSet { self.httpTargetWindowSize = self.httpTargetWindowSize.clamped(to: 1 ... Int(Int32.max)) } @@ -418,7 +418,7 @@ extension ClientConnection { connectionKeepalive: ClientConnectionKeepalive = ClientConnectionKeepalive(), connectionIdleTimeout: TimeAmount = .minutes(30), callStartBehavior: CallStartBehavior = .waitsForConnectivity, - httpTargetWindowSize: Int = 65535, + httpTargetWindowSize: Int = 8 * 1024 * 1024, backgroundActivityLogger: Logger = Logger( label: "io.grpc", factory: { _ in SwiftLogNoOpLogHandler() } diff --git a/Sources/GRPC/GRPCChannel/GRPCChannelBuilder.swift b/Sources/GRPC/GRPCChannel/GRPCChannelBuilder.swift index 212af9e98..ab32e7b69 100644 --- a/Sources/GRPC/GRPCChannel/GRPCChannelBuilder.swift +++ b/Sources/GRPC/GRPCChannel/GRPCChannelBuilder.swift @@ -387,7 +387,7 @@ extension ClientConnection.Builder.Secure { #endif extension ClientConnection.Builder { - /// Sets the HTTP/2 flow control target window size. Defaults to 65,535 if not explicitly set. + /// Sets the HTTP/2 flow control target window size. Defaults to 8MB if not explicitly set. /// Values are clamped between 1 and 2^31-1 inclusive. @discardableResult public func withHTTPTargetWindowSize(_ httpTargetWindowSize: Int) -> Self { diff --git a/Sources/GRPC/Server.swift b/Sources/GRPC/Server.swift index 098e5ab7d..86586297b 100644 --- a/Sources/GRPC/Server.swift +++ b/Sources/GRPC/Server.swift @@ -322,9 +322,9 @@ extension Server { } } - /// The HTTP/2 flow control target window size. Defaults to 65535. Values are clamped between + /// The HTTP/2 flow control target window size. Defaults to 8MB. Values are clamped between /// 1 and 2^31-1 inclusive. - public var httpTargetWindowSize = 65535 { + public var httpTargetWindowSize = 8 * 1024 * 1024 { didSet { self.httpTargetWindowSize = self.httpTargetWindowSize.clamped(to: 1 ... Int(Int32.max)) } @@ -391,7 +391,7 @@ extension Server { connectionKeepalive: ServerConnectionKeepalive = ServerConnectionKeepalive(), connectionIdleTimeout: TimeAmount = .nanoseconds(.max), messageEncoding: ServerMessageEncoding = .disabled, - httpTargetWindowSize: Int = 65535, + httpTargetWindowSize: Int = 8 * 1024 * 1024, logger: Logger = Logger(label: "io.grpc", factory: { _ in SwiftLogNoOpLogHandler() }), debugChannelInitializer: ((Channel) -> EventLoopFuture)? = nil ) { diff --git a/Sources/GRPC/ServerBuilder.swift b/Sources/GRPC/ServerBuilder.swift index 2f1d17b42..3d5c5f548 100644 --- a/Sources/GRPC/ServerBuilder.swift +++ b/Sources/GRPC/ServerBuilder.swift @@ -152,7 +152,7 @@ extension Server.Builder.Secure { } extension Server.Builder { - /// Sets the HTTP/2 flow control target window size. Defaults to 65,535 if not explicitly set. + /// Sets the HTTP/2 flow control target window size. Defaults to 8MB if not explicitly set. /// Values are clamped between 1 and 2^31-1 inclusive. @discardableResult public func withHTTPTargetWindowSize(_ httpTargetWindowSize: Int) -> Self {