我在 azure blob 存储中有试用帐户。我尝试从本地机器上传 100000 个生成的文件。该操作的持续时间已经超过 17 小时,并且仅上传了约 77000 个文件。由一个简单的 bash 脚本创建的所有文件:
for i in {1..100000}
do
echo $i
echo $i > $1\\$i.txt
done
上传代码:
using(var stream = File.OpenWrite(textBoxManyUploadFileName.Text))
using(var writer = new StreamWriter(stream)) {
foreach(var file in Directory.GetFiles(textBoxManyUploadFrom.Text)) {
Guid id = Guid.NewGuid();
storage.StoreFile(file, id, ((FileType)comboBoxManyUploadTypes.SelectedItem).Number);
writer.WriteLine("{0}={1}", id, file);
}
}
public void StoreFile(Stream stream, Guid id, string container) {
try {
var blob = GetBlob(id, container);
blob.UploadFromStream(stream);
} catch(StorageException exception) {
throw TranslateException(exception, id, container);
}
}
public void StoreFile(string filename, Guid id, int type = 0) {
using(var stream = File.OpenRead(filename)) {
StoreFile(stream, id, type);
}
}
CloudBlob GetBlob(Guid id, string containerName) {
var container = azureBlobClient.GetContainerReference(containerName);
if(container.CreateIfNotExist()) {
container.SetPermissions(new BlobContainerPermissions {
PublicAccess = BlobContainerPublicAccessType.Container
});
}
return container.GetBlobReference(id.ToString());
}
前 10000 个文件在 20-30 分钟内上传了 bean,然后速度下降。我认为这可能是因为文件名是 GUID 并且 Azure 尝试构建聚集索引。如何加快速度?问题是什么?