Azure / Azure-Functions

1.12k stars 199 forks source link

3 times higher memory usage of docker image when using azure functions host vs. custom host #1810

Open deyanp opened 3 years ago

deyanp commented 3 years ago

I have converted a .net core 3.1 Azure Functions app to a self-hosted .Net 5.0 asp.net core app (using Kestrel and Webjobs SDK) and I am observing 3 times difference in memory footprint (Azure Functions Host: 180+ MiB, Custom Host: 60 Mib) in docker, running locally on my machine.

Why is the Azure Functions Host consuming 3x the memory? I have been always wondering why my relatively simple microservice pods are consuming 200-300 Mb of memory ...

Docker Image for .net Core 3.1 Azure Functions app:

FROM mcr.microsoft.com/azure-functions/dotnet:3.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

COPY ./publish /home/site/wwwroot

Docker Images for .net 5.0 Custom Host app:

FROM mcr.microsoft.com/dotnet/aspnet:5.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

COPY ./publish /home/site/wwwroot
WORKDIR /home/site/wwwroot
ENTRYPOINT ["dotnet", "CustomNamespace.CustomProject.dll"]

Note: Language is F#, and the custom host is encapsulated in an additional Program.fs file I added to my existing Azure Function App project, containing Host.CreateDefaultBuilder, builder.ConfigureServices, builder.ConfigureLogging, builder.ConfigureWebJobs, builder.ConfigureWebHostDefaults and similar ... I added also

<OutputType>Exe</OutputType>

to the project file, removed

<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.9" />

and changed

<TargetFramework>net5.0</TargetFramework>

...

v-anvari commented 3 years ago

Hi @deyanp , Certain variations is expected when upgrading to different version of the framework in lot of different areas like memory utilization. The custom host which is self migrated is not yet supported and our engineers and still figuring out all the possibilities with the latest versions. We need to know what in your scenario could have impacted the memory utilization. Are you using the default docker container. Kindly give us more details so as to understand the scenario better

deyanp commented 3 years ago

@v-anvari , I saw the 50% memory reduction for all 40 pods I have, without exception. Our system is nothing special - just writing/reading entities to/from MongoDB.

In both cases I am using the default MS docker images.

deyanp commented 3 years ago

@v-anvari Note that I need to correct above memory footprints:

With Azure Functions 3.1 host: after certain time abot 330 - 380 MB/pod

With custom host, .net 5: 160-170 MB/pod, again after certain ramp up time.

v-anvari commented 3 years ago

cc @anthonychu / @fabiocav