ローカル ストレージから BLOB ストレージにフォルダーをアップロードするための次のコードがあります。BLOB の名前にフォルダー名自体を含めます (コードは、ここにあるいくつかのメソッドに基づいていますhttp://blog.smarx.com/posts/pivot-odata -and-windows-azure-visual-netflix-browsing ) :
public static void UploadBlobDir(CloudBlobContainer container, string dirPath)
{
string dirName = new Uri(dirPath).Segments.Last();
Parallel.ForEach(enumerateDirectoryRecursive(dirPath), file =>
{
string blobName = Path.Combine(dirName, Path.GetFullPath(file)).Substring(dirPath.Length - dirName.Length);
container.GetBlobReference(blobName).UploadFile(file);
});
}
と :
private static IEnumerable<string> enumerateDirectoryRecursive(string root)
{
foreach (var file in Directory.GetFiles(root))
yield return file;
foreach (var subdir in Directory.GetDirectories(root))
foreach (var file in enumerateDirectoryRecursive(subdir))
yield return file;
}
このコードは機能し、意図したとおりにフォルダをアップロードしますが、完了するまでに非常に時間がかかります.25個のファイルをアップロードするのに20秒かかり、それぞれ40KB~です. そのため、並列ループを次のような通常のループに置き換えるのにうんざりしていました。
foreach (var file in enumerateDirectoryRecursive(i_DirPath))
{
string blobName = Path.Combine(dirName, Path.GetFullPath(file)).Substring(i_DirPath.Length - dirName.Length);
container.GetBlobReference(blobName).UploadFile(file);
}
アップロードは瞬時に完了します (約3 秒)。
It's also important to note that I am working against the storage emulator for development.
The Parallel.Forech should obviously be faster. Does this difference comes form the storage emulator limitations (And when going live, Parallel would be faster) or is it something else I might be doing wrong ?