【发布时间】:2019-05-26 13:07:40
【问题描述】:
我正在尝试使用 Microsoft.Azure.Storage.Blob (9.4.2) 将非常大 (>100GB) 的 blob 上传到 Azure。但是,即使使用基于流的 blob 写入 API,库似乎也会根据文件大小分配内存(1.2GB 的测试文件会导致 2GB 的进程内存占用)。我需要它在不断的记忆中工作。我的代码如下(使用 UploadFromFile、UploadFromStream 等类似的结果):
var container = new CloudBlobContainer(new Uri(sasToken));
var blob = container.GetBlockBlobReference("test");
const int bufferSize = 64 * 1024 * 1024; // 64MB
blob.StreamWriteSizeInBytes = bufferSize;
using (var writeStream = blob.OpenWrite())
{
using (var readStream = new FileStream(archiveFilePath, FileMode.Open))
{
var buffer = new byte[bufferSize];
var bytesRead = 0;
while ((bytesRead = readStream.Read(buffer, 0, bufferSize)) != 0)
{
writeStream.Write(buffer, 0, bytesRead);
}
}
}
这种行为非常令人困惑——我可以在 TaskMgr 中看到上传确实立即开始,所以它不像是在缓冲等待发送的东西;它没有理由需要挂在以前发送的数据上。任何人如何使用此 API 进行重要的 Blob 上传?
【问题讨论】:
-
我从内存配置文件中看到分配位于 Microsoft.WindowsAzure.Storage.Core.MultiBufferMemoryStream - 这似乎表明至少在理论上它可以释放不再存在的部分需要,但不需要。
-
这听起来像是一个错误,您应该向 Microsoft 报告。
标签: c# .net azure blob azure-blob-storage