Skip to content

Commit

Permalink
fix: Set container memory limit to the same as the task to ensure the…
Browse files Browse the repository at this point in the history
… .NET GC knows the correct amount of available heap space.
  • Loading branch information
normj committed Mar 8, 2023
1 parent a592ab8 commit 8520316
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ private void ConfigureECSClusterAndService(IRecipeProps<Configuration> recipeCon
{
Image = ContainerImage.FromEcrRepository(EcrRepository, recipeConfiguration.ECRImageTag),
Logging = AppLogging,
Environment = settings.ECSEnvironmentVariables
Environment = settings.ECSEnvironmentVariables,
MemoryLimitMiB = settings.TaskMemory
}));

AppContainerDefinition.AddPortMappings(new PortMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ private void ConfigureTaskDefinition(IRecipeProps<Configuration> props)
{
Image = ContainerImage.FromEcrRepository(ecrRepository, props.ECRImageTag),
Logging = AppLogging,
Environment = settings.ECSEnvironmentVariables
Environment = settings.ECSEnvironmentVariables,
MemoryLimitMiB = settings.TaskMemory
};

AppTaskDefinition.AddContainer(nameof(AppContainerDefinition), InvokeCustomizeCDKPropsEvent(nameof(AppContainerDefinition), this, AppContainerDefinition));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ private void ConfigureTaskDefinition(IRecipeProps<Configuration> props)
{
Image = ContainerImage.FromEcrRepository(ecrRepository, props.ECRImageTag),
Logging = AppLogging,
Environment = settings.ECSEnvironmentVariables
Environment = settings.ECSEnvironmentVariables,
MemoryLimitMiB = settings.TaskMemory
};

AppTaskDefinition.AddContainer(nameof(AppContainerDefinition), InvokeCustomizeCDKPropsEvent(nameof(AppContainerDefinition), this, AppContainerDefinition));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand All @@ -8,6 +8,7 @@

<ItemGroup>
<PackageReference Include="AWSSDK.CloudWatchLogs" Version="3.7.101.7" />
<PackageReference Include="AWSSDK.ECS" Version="3.7.100.14" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
Expand Down
8 changes: 8 additions & 0 deletions test/AWS.Deploy.CLI.IntegrationTests/ServerModeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Threading;
using System.Threading.Tasks;
using Amazon.CloudFormation;
using Amazon.ECS;
using Amazon.Runtime;
using AWS.Deploy.CLI.Commands;
using AWS.Deploy.CLI.Common.UnitTests.IO;
Expand Down Expand Up @@ -245,6 +246,13 @@ public async Task WebFargateDeploymentNoConfigChanges()

Assert.True(logOutput.Length > 0);

// Check to make sure the task memory setting was copied to the container defintion memory limit;
var taskDefinitionId = await _cloudFormationHelper.GetResourceId(_stackName, "RecipeAppTaskDefinitionAC7F53DB");
using var ecsClient = new AmazonECSClient(Amazon.RegionEndpoint.GetBySystemName(_awsRegion));
var taskDefinition = (await ecsClient.DescribeTaskDefinitionAsync(new Amazon.ECS.Model.DescribeTaskDefinitionRequest { TaskDefinition = taskDefinitionId })).TaskDefinition;
var containerDefinition = taskDefinition.ContainerDefinitions[0];
Assert.Equal(int.Parse(taskDefinition.Memory), containerDefinition.Memory);

// Make sure section header is return to output log
Assert.Contains("Creating deployment image", logOutput.ToString());

Expand Down

0 comments on commit 8520316

Please sign in to comment.