-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds customization options for SocketsHttpHandler (#539)
Overview Add SocketHttpHandler config options and plumb through. Set Lambda config to use SocketHttpHandler.PooledConnectionIdleTimeout of 6 minutes. Add target frameworks for .NET 6.0 and bump target framework net461 to net462 for async iterator support. SocketHttpHandler config In Grpc.Net.Client, the default HttpHandler on .NET runtimes .NET 5.0 or greater is SocketsHttpHandler. In this PR we create a new options class to encapsulate customizations to the handler, most importantly the pooled connection timeout and whether to enable multiple http connections. Lambda config The default value for the idle connection timeout is 1 minute. We find this too strict in lambda environments, where the container may freeze and thaw in greater than 1 minute spans but less than the server timeout (5 minutes as of writing). Therefore we set the lambda config pooled connection idle timeout higher, to 6 minutes. That way a lambda function will not needlessly reconnect when the connection is still open. Target framework Previously we relied on .NET Framework 4.61 as the .NET Framework target. The next minor version introduced async iterator features necessary for the topic client. Because of this, at the time, we added preprocessor directives to exclude the topic client if the build target wasn't .NET Standard 2.0 or greater. Now that we add another target framework, .NET 6.0, maintaining the different platform directives is difficult. Instead we bump the Framework target from net461 to net462 to gain the async iterators and remove the platform conditional compilation directives. There is no customer impact by removing exactly .NET 4.61 as a target framework. .NET 4.62 also includes WinHttpHandler, so we can revisit the use of gRPC web in that Framework.
- Loading branch information
Showing
27 changed files
with
194 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/Momento.Sdk/Config/Transport/SocketsHttpHandlerOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#pragma warning disable 1591 | ||
using System; | ||
using Momento.Sdk.Internal; | ||
namespace Momento.Sdk.Config.Transport; | ||
|
||
public class SocketsHttpHandlerOptions | ||
{ | ||
public static TimeSpan DefaultPooledConnectionIdleTimeout { get; } = TimeSpan.FromMinutes(1); | ||
public TimeSpan PooledConnectionIdleTimeout { get; } = DefaultPooledConnectionIdleTimeout; | ||
public bool EnableMultipleHttp2Connections { get; } = true; | ||
|
||
public SocketsHttpHandlerOptions() { } | ||
public SocketsHttpHandlerOptions(TimeSpan pooledConnectionIdleTimeout) : this(pooledConnectionIdleTimeout, true) { } | ||
public SocketsHttpHandlerOptions(bool enableMultipleHttp2Connections) : this(DefaultPooledConnectionIdleTimeout, enableMultipleHttp2Connections) { } | ||
|
||
public SocketsHttpHandlerOptions(TimeSpan pooledConnectionIdleTimeout, bool enableMultipleHttp2Connections) | ||
{ | ||
Utils.ArgumentStrictlyPositive(pooledConnectionIdleTimeout, nameof(pooledConnectionIdleTimeout)); | ||
PooledConnectionIdleTimeout = pooledConnectionIdleTimeout; | ||
EnableMultipleHttp2Connections = enableMultipleHttp2Connections; | ||
} | ||
|
||
public SocketsHttpHandlerOptions WithPooledConnectionIdleTimeout(TimeSpan pooledConnectionIdleTimeout) | ||
{ | ||
return new SocketsHttpHandlerOptions(pooledConnectionIdleTimeout, EnableMultipleHttp2Connections); | ||
} | ||
|
||
public SocketsHttpHandlerOptions WithEnableMultipleHttp2Connections(bool enableMultipleHttp2Connections) | ||
{ | ||
return new SocketsHttpHandlerOptions(PooledConnectionIdleTimeout, enableMultipleHttp2Connections); | ||
} | ||
|
||
public static SocketsHttpHandlerOptions Of(TimeSpan pooledConnectionIdleTimeout) | ||
{ | ||
return new SocketsHttpHandlerOptions(pooledConnectionIdleTimeout); | ||
} | ||
|
||
public static SocketsHttpHandlerOptions Of(bool enableMultipleHttp2Connections) | ||
{ | ||
return new SocketsHttpHandlerOptions(enableMultipleHttp2Connections); | ||
} | ||
|
||
public static SocketsHttpHandlerOptions Of(TimeSpan pooledConnectionIdleTimeout, bool enableMultipleHttp2Connections) | ||
{ | ||
return new SocketsHttpHandlerOptions(pooledConnectionIdleTimeout, enableMultipleHttp2Connections); | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (obj == null || GetType() != obj.GetType()) | ||
{ | ||
return false; | ||
} | ||
|
||
var other = (SocketsHttpHandlerOptions)obj; | ||
return PooledConnectionIdleTimeout.Equals(other.PooledConnectionIdleTimeout) && | ||
EnableMultipleHttp2Connections.Equals(other.EnableMultipleHttp2Connections); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return PooledConnectionIdleTimeout.GetHashCode() * 17 + EnableMultipleHttp2Connections.GetHashCode(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.