Skip to content

Commit

Permalink
feat: add lambda configuration (#427)
Browse files Browse the repository at this point in the history
Adds a configuration optimized for Lambda environments. This is the
same as the InRegion.Default config but also eagerly connects the
client. This avoids the cold start penalty from before where we
established the connection on the first request, leading to
first-request timeouts.
  • Loading branch information
malandis authored Apr 26, 2023
1 parent d453faa commit 1751cd5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Momento.Sdk/Config/Configurations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,33 @@ public static IConfiguration V1(ILoggerFactory? loggerFactory = null)
return new LowLatency(finalLoggerFactory, retryStrategy, transportStrategy);
}
}

/// <summary>
/// This config optimizes for lambda environments. In addition to the in region settings of
/// <see cref="Default"/>, this configures the clients to eagerly connect to the Momento service
/// to avoid the cold start penalty of establishing a connection on the first request.
/// </summary>
public class Lambda : Configuration
{
private Lambda(ILoggerFactory loggerFactory, IRetryStrategy retryStrategy, ITransportStrategy transportStrategy)
: base(loggerFactory, retryStrategy, transportStrategy)
{

}

/// <summary>
/// Provides the latest recommended configuration for a lambda environment.
/// </summary>
/// <param name="loggerFactory"></param>
/// <returns></returns>
public static IConfiguration Latest(ILoggerFactory? loggerFactory = null)
{
var config = Default.V1(loggerFactory);
var transportStrategy = config.TransportStrategy.WithEagerConnectionTimeout(
TimeSpan.FromSeconds(30)
);
return config.WithTransportStrategy(transportStrategy);
}
}
}
}
7 changes: 7 additions & 0 deletions tests/Unit/Momento.Sdk.Tests/ConfigTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ public void V1VConfigs_EqualLatest_HappyPath()
Assert.Equal(Configurations.InRegion.Default.Latest(), Configurations.InRegion.Default.V1());
Assert.Equal(Configurations.InRegion.LowLatency.Latest(), Configurations.InRegion.LowLatency.V1());
}

[Fact]
public void LambdaLatest_HasEagerConnectionTimeout_HappyPath()
{
var config = Configurations.InRegion.Lambda.Latest();
Assert.Equal(TimeSpan.FromSeconds(30), config.TransportStrategy.EagerConnectionTimeout);
}
}

0 comments on commit 1751cd5

Please sign in to comment.