Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
2 parents 67f316d + 5ca7411 commit 2f7aea6
Show file tree
Hide file tree
Showing 39 changed files with 2,734 additions and 213 deletions.
15 changes: 8 additions & 7 deletions examples/MomentoLoadGen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ public async Task Run()
)
);
var statsPrinterTask = LaunchStatsPrinterTask(
context,
_options.showStatsInterval,
context,
_options.showStatsInterval,
cancellationTokenSource.Token
);
asyncTasks.Append(statsPrinterTask);
Expand All @@ -138,7 +138,7 @@ public async Task Run()
// tasks throws an uncaught exception.
var firstResult = await Task.WhenAny(asyncTasks);
await firstResult;

await Task.WhenAll(asyncTasks);
}
_logger.LogInformation("Done");
Expand Down Expand Up @@ -412,7 +412,7 @@ static async Task Main(string[] args)
///
/// Each time this amount of time has passed, statistics about throughput and latency
/// will be printed.
///
///
///
showStatsInterval: TimeSpan.FromSeconds(5),
///
Expand All @@ -427,7 +427,8 @@ static async Task Main(string[] args)
/// but it will also increase CPU consumption. As CPU usage increases and there
/// is more contention between the concurrent function calls, client-side latencies
/// may increase.
///
/// Note: You are likely to see degraded performance if you increase this above 50
/// and observe elevated client-side latencies.
numberOfConcurrentRequests: 50,
///
/// Sets an upper bound on how many requests per second will be sent to the server.
Expand All @@ -441,10 +442,10 @@ static async Task Main(string[] args)
///
howLongToRun: TimeSpan.FromMinutes(1)
);

using (ILoggerFactory loggerFactory = InitializeLogging(loadGeneratorOptions.logLevel))
{
///
///
/// This is the configuration that will be used for the Momento client. Choose from
/// our pre-built configurations that are optimized for Laptop vs InRegion environments,
/// or build your own.
Expand Down
2 changes: 1 addition & 1 deletion src/Momento.Sdk/Config/AuthConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public override bool Equals(object obj)
return false;
}

var other = (Configuration)obj;
var other = (AuthConfiguration)obj;
return TransportStrategy.Equals(other.TransportStrategy) &&
LoggerFactory.Equals(other.LoggerFactory);
}
Expand Down
22 changes: 22 additions & 0 deletions src/Momento.Sdk/Config/IVectorIndexConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.Extensions.Logging;
using Momento.Sdk.Config.Transport;

namespace Momento.Sdk.Config;

/// <summary>
/// Contract for the Vector Index SDK configurables.
/// </summary>
public interface IVectorIndexConfiguration
{
/// <inheritdoc cref="Microsoft.Extensions.Logging.ILoggerFactory" />
public ILoggerFactory LoggerFactory { get; }
/// <inheritdoc cref="Momento.Sdk.Config.Transport.IVectorIndexTransportStrategy" />
public IVectorIndexTransportStrategy TransportStrategy { get; }

/// <summary>
/// Creates a new instance of the VectorIndexConfiguration object, updated to use the specified transport strategy.
/// </summary>
/// <param name="transportStrategy">This is responsible for configuring network tunables.</param>
/// <returns>A VectorIndexConfiguration object using the provided transport strategy.</returns>
public IVectorIndexConfiguration WithTransportStrategy(IVectorIndexTransportStrategy transportStrategy);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ public ExperimentalMetricsLoggingMiddleware(ILoggerFactory loggerFactory) : base
public override Task EmitMetrics(ExperimentalRequestMetrics metrics)
{
var json = "{" +
$"\"numActiveRequestsAtStart\": {metrics.NumActiveRequestsAtStart}, " +
$"\"numActiveRequestsAtFinish\": {metrics.NumActiveRequestsAtFinish}, " +
$"\"requestType\": \"{metrics.RequestType}\", " +
$"\"status\": \"{metrics.Status}\", " +
$"\"startTime\": \"{metrics.StartTime}\", " +
$"\"endTime\": \"{metrics.EndTime}\", " +
$"\"duration\": \"{metrics.Duration}\", " +
$"\"requestSize\": {metrics.RequestSize}, " +
$"\"responseSize\": {metrics.ResponseSize}" +
"\"momento\": {" +
$"\"numActiveRequestsAtStart\": {metrics.NumActiveRequestsAtStart}, " +
$"\"numActiveRequestsAtFinish\": {metrics.NumActiveRequestsAtFinish}, " +
$"\"requestType\": \"{metrics.RequestType}\", " +
$"\"status\": \"{metrics.Status}\", " +
$"\"startTime\": \"{metrics.StartTime}\", " +
$"\"endTime\": \"{metrics.EndTime}\", " +
$"\"duration\": \"{metrics.Duration}\", " +
$"\"requestSize\": {metrics.RequestSize}, " +
$"\"responseSize\": {metrics.ResponseSize}" +
"}" +
"}";

_logger.LogInformation(json);
Expand Down
2 changes: 1 addition & 1 deletion src/Momento.Sdk/Config/TopicConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public override bool Equals(object obj)
return false;
}

var other = (Configuration)obj;
var other = (TopicConfiguration)obj;
return TransportStrategy.Equals(other.TransportStrategy) &&
LoggerFactory.Equals(other.LoggerFactory);
}
Expand Down
29 changes: 29 additions & 0 deletions src/Momento.Sdk/Config/Transport/IVectorIndexTransportStrategy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;

namespace Momento.Sdk.Config.Transport;

/// <summary>
/// This is responsible for configuring network tunables for the vector index client.
/// </summary>
public interface IVectorIndexTransportStrategy
{
/// <summary>
/// Configures the low-level gRPC settings for the Momento Vector Index client's communication
/// with the Momento server.
/// </summary>
public IGrpcConfiguration GrpcConfig { get; }

/// <summary>
/// Copy constructor to update the gRPC configuration
/// </summary>
/// <param name="grpcConfig"></param>
/// <returns>A new IVectorIndexTransportStrategy with the specified grpcConfig</returns>
public IVectorIndexTransportStrategy WithGrpcConfig(IGrpcConfiguration grpcConfig);

/// <summary>
/// Copy constructor to update the client timeout
/// </summary>
/// <param name="clientTimeout"></param>
/// <returns>A new IVectorIndexTransportStrategy with the specified client timeout</returns>
public IVectorIndexTransportStrategy WithClientTimeout(TimeSpan clientTimeout);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using Microsoft.Extensions.Logging;

namespace Momento.Sdk.Config.Transport;

/// <summary>
/// The simplest way to configure the transport layer for the Momento Vector Index client.
/// Provides static values for the gRPC configuration.
/// </summary>
public class StaticVectorIndexTransportStrategy : IVectorIndexTransportStrategy
{
private readonly ILoggerFactory _loggerFactory;

/// <inheritdoc />
public IGrpcConfiguration GrpcConfig { get; }

/// <summary>
/// Configures the transport layer for the Momento client.
/// </summary>
/// <param name="loggerFactory"></param>
/// <param name="grpcConfig">Configures how Momento Vector Index client interacts with the Momento service via gRPC</param>
public StaticVectorIndexTransportStrategy(ILoggerFactory loggerFactory, IGrpcConfiguration grpcConfig)
{
_loggerFactory = loggerFactory;
GrpcConfig = grpcConfig;
}

/// <inheritdoc/>
public IVectorIndexTransportStrategy WithGrpcConfig(IGrpcConfiguration grpcConfig)
{
return new StaticVectorIndexTransportStrategy(_loggerFactory, grpcConfig);
}

/// <inheritdoc/>
public IVectorIndexTransportStrategy WithClientTimeout(TimeSpan clientTimeout)
{
return new StaticVectorIndexTransportStrategy(_loggerFactory, GrpcConfig.WithDeadline(clientTimeout));
}

/// <summary>
/// Test equality by value.
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object obj)
{
if ((obj == null) || !this.GetType().Equals(obj.GetType()))
{
return false;
}

var other = (StaticVectorIndexTransportStrategy)obj;
return GrpcConfig.Equals(other.GrpcConfig);
}

/// <summary>
/// Trivial hash code implementation.
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
return base.GetHashCode();
}
}
53 changes: 53 additions & 0 deletions src/Momento.Sdk/Config/VectorIndexConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Microsoft.Extensions.Logging;
using Momento.Sdk.Config.Transport;

namespace Momento.Sdk.Config;

/// <inheritdoc cref="IVectorIndexConfiguration" />
public class VectorIndexConfiguration : IVectorIndexConfiguration
{
/// <inheritdoc />
public ILoggerFactory LoggerFactory { get; }
/// <inheritdoc />
public IVectorIndexTransportStrategy TransportStrategy { get; }


/// <summary>
/// Create a new instance of a Vector Index Configuration object with provided arguments:
/// <see cref="Momento.Sdk.Config.IVectorIndexConfiguration.TransportStrategy"/>,
/// and <see cref="Momento.Sdk.Config.IVectorIndexConfiguration.LoggerFactory"/>
/// </summary>
/// <param name="transportStrategy">This is responsible for configuring network tunables.</param>
/// <param name="loggerFactory">This is responsible for configuring logging.</param>
public VectorIndexConfiguration(ILoggerFactory loggerFactory, IVectorIndexTransportStrategy transportStrategy)
{
LoggerFactory = loggerFactory;
TransportStrategy = transportStrategy;
}

/// <inheritdoc />
public IVectorIndexConfiguration WithTransportStrategy(IVectorIndexTransportStrategy transportStrategy)
{
return new VectorIndexConfiguration(LoggerFactory, transportStrategy);
}

/// <inheritdoc />
public override bool Equals(object obj)
{
if ((obj == null) || !this.GetType().Equals(obj.GetType()))
{
return false;
}

var other = (VectorIndexConfiguration)obj;
return TransportStrategy.Equals(other.TransportStrategy) &&
LoggerFactory.Equals(other.LoggerFactory);
}

/// <inheritdoc />
public override int GetHashCode()
{
return base.GetHashCode();
}

}
58 changes: 58 additions & 0 deletions src/Momento.Sdk/Config/VectorIndexConfigurations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Momento.Sdk.Config.Transport;

namespace Momento.Sdk.Config;

/// <summary>
/// Provide pre-built vector index client configurations.
/// </summary>
public class VectorIndexConfigurations
{
/// <summary>
/// Laptop config provides defaults suitable for a medium-to-high-latency dev environment. Permissive timeouts, retries, and
/// relaxed latency and throughput targets.
/// </summary>
public class Laptop : VectorIndexConfiguration
{
private Laptop(ILoggerFactory loggerFactory, IVectorIndexTransportStrategy transportStrategy)
: base(loggerFactory, transportStrategy)
{

}

/// <summary>
/// Provides the latest recommended configuration for a Laptop environment.
/// </summary>
/// <remark>
/// This configuration may change in future releases to take advantage of
/// improvements we identify for default configurations.
/// </remark>
/// <param name="loggerFactory"></param>
/// <returns></returns>
public static IVectorIndexConfiguration Latest(ILoggerFactory? loggerFactory = null)
{
return V1(loggerFactory);
}

/// <summary>
/// Provides version 1 configuration for a Laptop environment.
/// </summary>
/// <remark>
/// This configuration is guaranteed not to change in future
/// releases of the Momento .NET SDK.
/// </remark>
/// <param name="loggerFactory"></param>
/// <returns></returns>
public static IVectorIndexConfiguration V1(ILoggerFactory? loggerFactory = null)
{
var finalLoggerFactory = loggerFactory ?? NullLoggerFactory.Instance;
IVectorIndexTransportStrategy transportStrategy = new StaticVectorIndexTransportStrategy(
loggerFactory: finalLoggerFactory,
grpcConfig: new StaticGrpcConfiguration(deadline: TimeSpan.FromMilliseconds(15000))
);
return new Laptop(finalLoggerFactory, transportStrategy);
}
}
}
Loading

0 comments on commit 2f7aea6

Please sign in to comment.