0

我已经问过这个问题,但没有得到太多回应,而且我得到的那些也没有解决我的问题。所以在这里我试图以不同的方式再次询问。

我有一个项目将产品提要文件处理到我的系统中。对于一个特定的提要文件,整个过程大约需要 40-50 分钟。现在我已经创建了一个WebJob来处理来自提要的图像,并且我正在WebJob通过创建存储客户端将图片 url 从我的第一个项目发送到。当我在我的项目中使用它时,它显着增加了处理时间,所以我尝试将它与Task.Run使用Fire and Forget方法一起使用,但即使现在整个处理时间仍然约为 2 小时。

这是我如何调用创建存储队列的方法。

if (insertImages)
{
    #pragma warning disable 4014
    Task.Run(async () => { await new QueueUtility().CreateQueueMessage(picture); }).ConfigureAwait(false);
    #pragma warning restore 4014
}

这是我创建队列消息的代码

public async Task CreateQueueMessage(Picture picture)
    {
            Utility.Log log = new Utility.Log();
            await AddQueueMessage(picture.url);

    }


public async Task AddQueueMessage(string queueMessage)
    {
        ServicePointManager.UseNagleAlgorithm = false;

        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("ImagekWebJobStorage"));

        // Create the queue client.
        CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

        // Retrieve a reference to a container.
        CloudQueue queue = queueClient.GetQueueReference("imagequeue");

        // Create a message and add it to the queue.
        CloudQueueMessage message = new CloudQueueMessage(queueMessage);
        queue.AddMessage(message);

    }

我不明白为什么我的处理时间加倍,也找不到解决方法。任何能帮助我解决这个问题的想法都会非常有帮助。

编辑:将QueueUtility静态类和方法转换为静态方法似乎有所帮助。不知道如何或为什么。

4

1 回答 1

1

为每条发送的消息创建一个新的 CloudStorageAccount、CloudQueueClient 和 CloudQueue 效率非常低。

您应该创建一次并重复使用它们来发送每条消息。

有关优化使用 Azure 存储的应用程序性能的更多指导,请参阅:

Microsoft Azure 存储性能和可扩展性清单 https://azure.microsoft.com/en-us/documentation/articles/storage-performance-checklist/

于 2016-06-01T18:33:44.490 回答