当尝试使用Task.WaitAlll同时更新多个blob时,azure存储模拟器抛出500

时间:2017-05-26 17:03:41

标签: azure azure-storage-blobs azure-storage-emulator

我试图在尝试同时更新多个blob时尝试使用Task.WaitAll来提高性能

using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.RetryPolicies;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://localhost.fiddler;");
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");

            // Create the container if it doesn't already exist.
            container.CreateIfNotExists();

            CloudBlockBlob blockBlob1 = container.GetBlockBlobReference("myblob1");
            CloudBlockBlob blockBlob2 = container.GetBlockBlobReference("myblob2");
            CloudBlockBlob blockBlob3 = container.GetBlockBlobReference("myblob3");
            CloudBlockBlob blockBlob4 = container.GetBlockBlobReference("myblob4");
            CloudBlockBlob blockBlob5 = container.GetBlockBlobReference("myblob5");

            blobClient.DefaultRequestOptions = new BlobRequestOptions()
            {
                RetryPolicy = new NoRetry()
            };
            var str = "To list the blobs in a container, first get a container reference. You can then use the container's ListBlobs method to retrieve the blobs and/or directories within it. To access the rich set of properties and methods for a returned IListBlobItem, you must cast it to a CloudBlockBlob, CloudPageBlob, or CloudBlobDirectory object. If the type is ";

            Task.WaitAll(UploadBlobAsync(blockBlob1, str), UploadBlobAsync(blockBlob2, str),  UploadBlobAsync(blockBlob3, str), UploadBlobAsync(blockBlob4, str), UploadBlobAsync(blockBlob5, str));            
        }


        private static async Task UploadBlobAsync(CloudBlockBlob blob, string content)
        {
            await blob.UploadTextAsync(content);
        }
    }
}

然后我发现模拟器有时会抛出500异常:

HTTP/1.1 500 Server encountered an internal error. Please try again after some time.
Content-Length: 253
Content-Type: application/xml
Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-id: 53a5fe0c-496a-4925-b87d-48cb59a7df37
x-ms-version: 2016-05-31
Date: Fri, 26 May 2017 16:46:28 GMT

<?xml version="1.0" encoding="utf-8"?><Error><Code>InternalError</Code><Message>Server encountered an internal error. Please try again after some time.
RequestId:53a5fe0c-496a-4925-b87d-48cb59a7df37
Time:2017-05-26T16:46:28.9534026Z</Message></Error>

如果我启用了输入逻辑,它将会成功但会花费比我想象的更长的时间,并且我可以通过提琴手看到其中一个blob操作始终在第一次失败并成功重试

它不会每次都失败,但是有很高的机会失败500

使用模拟器5.0和客户端库8.1.3进行测试。我没有使用azure云存储测试此代码。

1 个答案:

答案 0 :(得分:0)

我也可以使用azure存储模拟器v5.0在我身边使用5个uploadblob任务来重现这个问题。如果任务数小于5,则无法再现。正如您所提到的那样one of the blob operation always failed at the first time. 但我无法使用Azure云存储重现它,它适用于Azure云存储。如果对存储模拟器有任何想法,我们可以将我们的feedback提供给Azure团队。