gpt4 book ai didi

c# - 将文件上传到 Azure Blob 时的 ASP.NET Core 内存消耗

转载 作者:行者123 更新时间:2023-11-30 12:55:57 24 4
gpt4 key购买 nike

当我将文件上传到 Azure Blob 时,内存消耗似乎相当高。以下数据来自上传的 200 MB 文件。

public async Task<IActionResult> PostFile(IFormFile file)
{
var filePath = Path.GetTempFileName();

using (var stream = new FileStream(filePath, FileMode.Create))
{
-> Memory used: 108 MB

await file.CopyToAsync(stream);

-> Memory used: 308 MB

await blockBlob.UploadFromStreamAsync(stream);

-> Memory used: 988 MB
}
}

由于文件已经加载到流中,我无法理解UploadFromStreamAsync()导致的内存消耗急剧增加。我正在使用 Microsoft.WindowsAzure.Storage 8.1.4 和 .NET Core 1.1。

我做错了什么还是这是预期的行为?

最佳答案

我的测试应用程序是MVC应用程序,因此只需要243内存使用量。

Web api 应用程序与 MVC 应用程序内存使用情况不同。

我的 Web api 应用程序使用量为 1G,如下图所示:

enter image description here

Am I doing anything wrong or is this expected behavior?

这是预期的行为。

我建议您可以使用快照来查看堆大小变化信息。

可以看到堆大小已释放,但内存使用量仍为 1G。

enter image description here

关于c# - 将文件上传到 Azure Blob 时的 ASP.NET Core 内存消耗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44546073/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com