Mih*_*ert 5 c# memory azure azure-functions
我在 .NET Core 上使用一些简单的 C# 代码来查看 Azure Functions 的执行情况。
\n\n用例是这样的:将 1000 万个 int 值添加到 ArrayList 作为 Azure 函数的一部分,并使用设置为 1 分钟的时间触发器来调用该函数。(我知道 ArrayList 已过时,不再使用,但我只是使用它来在堆上分配大量空间)。\n因此该函数的 C# 代码是这样的:
\n\nusing System.Collections;\n\npublic static void Run(TimerInfo myTimer, ILogger log)\n{\n ArrayList numbers = new ArrayList();\n Random random = new Random(1);\n int noNumbers = 10000000;\n for(int i=0;i<noNumbers;i++) {\n numbers.Add(random.Next(10));\n }\n\n log.LogInformation($"Created an ArrayList of {numbers.Count} elements");\n log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我检查了平台设置,发现这是 32 位的(我假设这是指 .NET Core 运行时为 32 位):
\n\n
在“桌面”环境中运行相同的示例代码,针对 Windows 10 x64 上的 .NET Core 3.0,并使用AppDomain.CurrentDomain.MonitoringTotalAllocatedMemorySize获取总体分配的内存会产生以下结果(VMMap 输出,后跟控制台输出):\n
\n
这些值与预期相符,如下所示:
\n\n然而,观察到的 Azure 函数结果如下(指标图,然后手动运行函数本身):\n

图表上测得的私有字节数远高于之前在 VMMap 中看到的值,而在函数生命周期内分配的字节数既不符合 x86 代码 (~240MB) 的预期内存使用量,也不符合 x64 (~500MB) 的预期内存使用量。这表明 x86 代码正在运行,但上面有一些额外的东西(其开销不可忽略),这会显着影响私有字节。但是,观察到的值确实接近在 Azure 门户中为 Azure Function 测量的“私有字节”指标(Function App\xe2\x80\x99s \xe2\x80\x9cprivate bytes\xe2\x80\x9d 或 App Insights\xe2\x80\x99 \xe2\x80\x9cprocess private bytes\xe2\x80\x9d 大致相同)。
\n\n与在常规计算机上运行相同的代码相比,Azure Functions 中的私有字节数加倍的解释是什么?
\n\n无论如何,为什么这很重要?有两个原因:
\n\n相应的 GitHub 问题已在此处打开。
\n| 归档时间: |
|
| 查看次数: |
2434 次 |
| 最近记录: |