gpt4 book ai didi

c# - 将数百万个项目从一个存储帐户移动到另一个存储帐户

转载 作者:太空狗 更新时间:2023-10-29 23:32:35 25 4
gpt4 key购买 nike

我需要将大约 420 万个图像从美国中北部移动到美国西部,作为利用 Azure VM 支持的大型迁移的一部分(对于那些不知道的人,美国中北部不支持他们)。这些图像全部位于一个容器中,分为大约 119,000 个目录。

我正在使用 Copy Blob API 中的以下内容:

public static void CopyBlobDirectory(
CloudBlobDirectory srcDirectory,
CloudBlobContainer destContainer)
{
// get the SAS token to use for all blobs
string blobToken = srcDirectory.Container.GetSharedAccessSignature(
new SharedAccessBlobPolicy
{
Permissions = SharedAccessBlobPermissions.Read |
SharedAccessBlobPermissions.Write,
SharedAccessExpiryTime = DateTime.UtcNow + TimeSpan.FromDays(14)
});

var srcBlobList = srcDirectory.ListBlobs(
useFlatBlobListing: true,
blobListingDetails: BlobListingDetails.None).ToList();

foreach (var src in srcBlobList)
{
var srcBlob = src as ICloudBlob;

// Create appropriate destination blob type to match the source blob
ICloudBlob destBlob;
if (srcBlob.Properties.BlobType == BlobType.BlockBlob)
destBlob = destContainer.GetBlockBlobReference(srcBlob.Name);
else
destBlob = destContainer.GetPageBlobReference(srcBlob.Name);

// copy using src blob as SAS
destBlob.BeginStartCopyFromBlob(new Uri(srcBlob.Uri.AbsoluteUri + blobToken), null, null);
}
}

问题是,它太慢了。太慢了。按照发出命令来复制所有这些内容的速度,大约需要四天的时间。我不太确定瓶颈是什么(客户端连接限制、Azure 端的速率限制、多线程等)。

所以,我想知道我的选择是什么。有什么办法可以加快速度,还是我只是被困在需要四天才能完成的工作上?

编辑:我如何分发工作以复制所有内容

//set up tracing
InitTracer();

//grab a set of photos to benchmark this
var photos = PhotoHelper.GetAllPhotos().Take(500).ToList();

//account to copy from
var from = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(
"oldAccount",
"oldAccountKey");
var fromAcct = new CloudStorageAccount(from, true);
var fromClient = fromAcct.CreateCloudBlobClient();
var fromContainer = fromClient.GetContainerReference("userphotos");

//account to copy to
var to = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(
"newAccount",
"newAccountKey");
var toAcct = new CloudStorageAccount(to, true);
var toClient = toAcct.CreateCloudBlobClient();

Trace.WriteLine("Starting Copy: " + DateTime.UtcNow.ToString());

//enumerate sub directories, then move them to blob storage
//note: it doesn't care how high I set the Parallelism to,
//console output indicates it won't run more than five or so at a time
var plo = new ParallelOptions { MaxDegreeOfParallelism = 10 };
Parallel.ForEach(photos, plo, (info) =>
{
CloudBlobDirectory fromDir = fromContainer.GetDirectoryReference(info.BuildingId.ToString());

var toContainer = toClient.GetContainerReference(info.Id.ToString());
toContainer.CreateIfNotExists();

Trace.WriteLine(info.BuildingId + ": Starting copy, " + info.Photos.Length + " photos...");

BlobHelper.CopyBlobDirectory(fromDir, toContainer, info);
//this monitors the container, so I can restart any failed
//copies if something goes wrong
BlobHelper.MonitorCopy(toContainer);
});

Trace.WriteLine("Done: " + DateTime.UtcNow.ToString());

最佳答案

同一数据中心内的异步 blob 复制操作将会非常快(最近我在大约 1-2 秒内将 30GB vhd 复制到另一个 blob)。在整个数据中心中,操作会排队并在没有 SLA 的空闲容量上进行(请参阅 this article 其中特别指出了这一点)

从这个角度来看:我跨数据中心复制了相同的 30GB VHD,大约花了 1 小时。

我不知道您的图像大小,但假设平均图像大小为 500K,您看到的大小约为 2,000 GB。在我的示例中,大约一个小时内吞吐量达到 30GB。据此推断,大约需要 (2000/30) = 60 小时即可估算出 2000 GB 的数据。再次强调,没有 SLA。只是最好的猜测。

其他人建议禁用 Nagle 算法。这应该有助于更快地推送 400 万条复制命令,并让它们更快地排队。我认为这不会对复制时间产生任何影响。

关于c# - 将数百万个项目从一个存储帐户移动到另一个存储帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15179726/

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