Sorry for the delay in getting back with you. While we never definitively figured out why the difference between the two environments was happening on the same app, we did discover that AWS ECS images didn’t have swap memory enabled. So while our app was using 2GB of memory locally, it might have had several GB’s of memory swapped to the hard drive. In AWS ECS this just all stays in memory.
We found this out by logging the memory usage of the application at times during processing of a job. Here are the methods we used to output that information.
public static long ApplicationWorkingMemoryUsage()
return Process.GetCurrentProcess()?.WorkingSet64 ?? 0;
public static long ApplicationPrivateMemoryUsage()
return Process.GetCurrentProcess()?.PrivateMemorySize64 ?? 0;
public static long ApplicationVirtualMemoryUsage()
return Process.GetCurrentProcess()?.VirtualMemorySize64 ?? 0;
What we ultimately did was try and make our jobs slimmer and try to use as little memory as possible. We also wrangled in EF Core and didn’t let its caching take up too much memory. We ultimately got the memory usage down to a manageable (non killed instance) amount. BUT… we still run on pretty good sized instances of 8GB or 16GB.
Secondary note… if you haven’t upgraded to at least .NET Core 3.1, all support for previous versions has been dropped by Microsoft at this point (i.e. .NET Core 1.1 and 2.1.) It wouldn’t be any use to upgrade to .NET 5 as its support will drop soon after .NET 6 comes out later this year.