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

fix: disable keepalive for control clients #542

Merged
merged 3 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ public interface IVectorIndexTransportStrategy
/// <param name="clientTimeout"></param>
/// <returns>A new IVectorIndexTransportStrategy with the specified client timeout</returns>
public IVectorIndexTransportStrategy WithClientTimeout(TimeSpan clientTimeout);

/// <summary>
/// Copy constructor to update the SocketsHttpHandler's options
/// </summary>
/// <param name="options"></param>
/// <returns></returns>
public IVectorIndexTransportStrategy WithSocketsHttpHandlerOptions(SocketsHttpHandlerOptions options);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
return new StaticVectorIndexTransportStrategy(_loggerFactory, GrpcConfig.WithDeadline(clientTimeout));
}

public IVectorIndexTransportStrategy WithSocketsHttpHandlerOptions(SocketsHttpHandlerOptions options)

Check warning on line 40 in src/Momento.Sdk/Config/Transport/StaticVectorIndexTransportStrategy.cs

View workflow job for this annotation

GitHub Actions / build_csharp (ubuntu-latest, net6.0)

Missing XML comment for publicly visible type or member 'StaticVectorIndexTransportStrategy.WithSocketsHttpHandlerOptions(SocketsHttpHandlerOptions)'

Check warning on line 40 in src/Momento.Sdk/Config/Transport/StaticVectorIndexTransportStrategy.cs

View workflow job for this annotation

GitHub Actions / build_csharp (ubuntu-latest, net6.0)

Missing XML comment for publicly visible type or member 'StaticVectorIndexTransportStrategy.WithSocketsHttpHandlerOptions(SocketsHttpHandlerOptions)'

Check warning on line 40 in src/Momento.Sdk/Config/Transport/StaticVectorIndexTransportStrategy.cs

View workflow job for this annotation

GitHub Actions / build_csharp (windows-latest, net6.0)

Missing XML comment for publicly visible type or member 'StaticVectorIndexTransportStrategy.WithSocketsHttpHandlerOptions(SocketsHttpHandlerOptions)'

Check warning on line 40 in src/Momento.Sdk/Config/Transport/StaticVectorIndexTransportStrategy.cs

View workflow job for this annotation

GitHub Actions / build_csharp (windows-latest, net462)

Missing XML comment for publicly visible type or member 'StaticVectorIndexTransportStrategy.WithSocketsHttpHandlerOptions(SocketsHttpHandlerOptions)'
{
return new StaticVectorIndexTransportStrategy(_loggerFactory, GrpcConfig.WithSocketsHttpHandlerOptions(options));
}

/// <summary>
/// Test equality by value.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Momento.Sdk/Internal/GrpcManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ internal GrpcManager(IGrpcConfiguration grpcConfig, ILoggerFactory loggerFactory
PooledConnectionIdleTimeout = grpcConfig.SocketsHttpHandlerOptions.PooledConnectionIdleTimeout,
KeepAlivePingTimeout = grpcConfig.SocketsHttpHandlerOptions.KeepAlivePingTimeout,
KeepAlivePingDelay = grpcConfig.SocketsHttpHandlerOptions.KeepAlivePingDelay,
KeepAlivePingPolicy = grpcConfig.SocketsHttpHandlerOptions.KeepAlivePermitWithoutCalls == true ? System.Net.Http.HttpKeepAlivePingPolicy.Always : System.Net.Http.HttpKeepAlivePingPolicy.WithActiveRequests,
KeepAlivePingPolicy = grpcConfig.SocketsHttpHandlerOptions.KeepAlivePermitWithoutCalls ? System.Net.Http.HttpKeepAlivePingPolicy.Always : System.Net.Http.HttpKeepAlivePingPolicy.WithActiveRequests,
};
}
#elif USE_GRPC_WEB
Expand Down
13 changes: 12 additions & 1 deletion src/Momento.Sdk/Internal/ScsControlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.Extensions.Logging;
using Momento.Protos.ControlClient;
using Momento.Sdk.Config;
using Momento.Sdk.Config.Transport;
using Momento.Sdk.Exceptions;
using Momento.Sdk.Responses;

Expand All @@ -20,7 +21,17 @@ internal sealed class ScsControlClient : IDisposable

public ScsControlClient(IConfiguration config, string authToken, string endpoint)
{
this.grpcManager = new ControlGrpcManager(config, authToken, endpoint);
// Override the sockets http handler options to disable keepalive
var overrideKeepalive = SocketsHttpHandlerOptions.Of(
pooledConnectionIdleTimeout: config.TransportStrategy.GrpcConfig.SocketsHttpHandlerOptions.PooledConnectionIdleTimeout,
enableMultipleHttp2Connections: config.TransportStrategy.GrpcConfig.SocketsHttpHandlerOptions.EnableMultipleHttp2Connections,
keepAlivePingTimeout: System.Threading.Timeout.InfiniteTimeSpan,
keepAlivePingDelay: System.Threading.Timeout.InfiniteTimeSpan,
keepAlivePermitWithoutCalls: false
);
var controlConfig = config.WithTransportStrategy(config.TransportStrategy.WithSocketsHttpHandlerOptions(overrideKeepalive));

this.grpcManager = new ControlGrpcManager(controlConfig, authToken, endpoint);
this.authToken = authToken;
this._logger = config.LoggerFactory.CreateLogger<ScsControlClient>();
this._exceptionMapper = new CacheExceptionMapper(config.LoggerFactory);
Expand Down
13 changes: 12 additions & 1 deletion src/Momento.Sdk/Internal/VectorIndexControlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Momento.Sdk.Requests.Vector;
using Momento.Sdk.Responses.Vector;
using Momento.Sdk.Config;
using Momento.Sdk.Config.Transport;

namespace Momento.Sdk.Internal;

Expand All @@ -22,7 +23,17 @@ internal sealed class VectorIndexControlClient : IDisposable

public VectorIndexControlClient(IVectorIndexConfiguration config, string authToken, string endpoint)
{
grpcManager = new VectorIndexControlGrpcManager(config, authToken, endpoint);
// Override the sockets http handler options to disable keepalive
var overrideKeepalive = SocketsHttpHandlerOptions.Of(
pooledConnectionIdleTimeout: config.TransportStrategy.GrpcConfig.SocketsHttpHandlerOptions.PooledConnectionIdleTimeout,
enableMultipleHttp2Connections: config.TransportStrategy.GrpcConfig.SocketsHttpHandlerOptions.EnableMultipleHttp2Connections,
keepAlivePingTimeout: System.Threading.Timeout.InfiniteTimeSpan,
keepAlivePingDelay: System.Threading.Timeout.InfiniteTimeSpan,
keepAlivePermitWithoutCalls: false
Comment on lines +30 to +32
Copy link
Contributor

Choose a reason for hiding this comment

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

What do these settings default to in the data client?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Defaults to enabling keepalives with:

  • timeout: 1000ms
  • delay: 5000ms
  • permit: true

Copy link
Contributor

Choose a reason for hiding this comment

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

OK. Leaving this here for the future: previously we did not have keepalives enabled at all in .NET since SocketsHttpHandler defaults to no keepalive (unlike other gRPC libraries?). So if an existing user upgrades the settings will be different, though these settings have the most impact in Lambda environments, which we've already tuned.

);
var controlConfig = config.WithTransportStrategy(config.TransportStrategy.WithSocketsHttpHandlerOptions(overrideKeepalive));

grpcManager = new VectorIndexControlGrpcManager(controlConfig, authToken, endpoint);
_logger = config.LoggerFactory.CreateLogger<VectorIndexControlClient>();
_exceptionMapper = new CacheExceptionMapper(config.LoggerFactory);
}
Expand Down
Loading