dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.5k stars 10.04k forks source link

in k8s asp core webapi causes large memory consumption in dotnet/aspnet 8.0.10-noble-amd64 #58687

Closed versus-orel closed 2 weeks ago

versus-orel commented 2 weeks ago

Description

I run local kubernetes cluster and use asp net core 8 docker container. Memory usage of pod increases and decreases time to time. I included pictures from metrics and results of dotnet-counters monitor command.

Reproduction Steps

used libraries are like this:

    <PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
    <PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.6" />
    <PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="8.0.6" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.6">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="NPOI" Version="2.7.0" />
    <PackageReference Include="QRCoder" Version="1.5.1" />
    <PackageReference Include="Quartz" Version="3.9.0" />
    <PackageReference Include="Quartz.Extensions.Hosting" Version="3.9.0" />
    <PackageReference Include="RabbitMQ.Client" Version="6.8.1" />
    <PackageReference Include="RestSharp" Version="112.1.0" />
    <PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="112.1.0" />

Expected behavior

not to consume too much memory

Actual behavior

Press p to pause, r to resume, q to quit.
    Status: Paused

Name                                                     Current Value
[System.Runtime]
    % Time in GC since last GC (%)                               0
        Allocation Rate (B / 1 sec)                          7,407,288
        CPU Usage (%)                                                0.657
    Exception Count (Count / 1 sec)                              0
        GC Committed Bytes (MB)                                    862.171
    GC Fragmentation (%)                                        25.922
    GC Heap Size (MB)                                          463.608
    Gen 0 GC Budget (MB)                                         8
        Gen 0 GC Count (Count / 1 sec)                               1
        Gen 0 Size (B)                                         162,592
        Gen 1 GC Count (Count / 1 sec)                               0
        Gen 1 Size (B)                                         425,920
        Gen 2 GC Count (Count / 1 sec)                               0
        Gen 2 Size (B)                                          3.5483e+08
    IL Bytes Jitted (B)                                 30,695,781
        LOH Size (B)                                             1.101e+08
    Monitor Lock Contention Count (Count / 1 sec)               15
        Number of Active Timers                                      7
        Number of Assemblies Loaded                                201
        Number of Methods Jitted                               467,094
        POH (Pinned Object Heap) Size (B)                        1.588e+08
    ThreadPool Completed Work Item Count (Count / 1 se         993
        ThreadPool Queue Length                                      0
        ThreadPool Thread Count                                     18
        Time paused by GC (ms / 1 sec)                               2.839
    Time spent in JIT (ms / 1 sec)                               0
        Working Set (MB)                                         1,741.713

Image

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

jasper-d commented 2 weeks ago

Did you configure resource limits (notably spec.containers[].resources.limits.memory) for the container?

If not GC will see your machines entire memory as available and will have little reason to conserve memory.

versus-orel commented 2 weeks ago

Thank for your quick response. I think not configured. I will check it out soon.

versus-orel commented 2 weeks ago

I limited the resource given and container doesn't exceed that memory. Thank you very much. But I am wondering how much memory I should give to container beforehead? closing the issue