简体   繁体   English

Azure 存储队列性能

[英]Azure Storage Queue performance

We are migrating a transaction-processing service which was processing messages from MSMQ and storing transacitons in a SQLServer Database to use the Azure Storage Queue (to store the id's of the messages and placing the actual messages in the Azure Storage Blob).我们正在迁移一个事务处理服务,该服务处理来自 MSMQ 的消息并将事务存储在 SQLServer 数据库中,以使用 Azure 存储队列(存储消息的 id 并将实际消息放入 Azure 存储 Blob)。

We should at least be able to process 200.000 messages per hour, but at the moment we barely reach 50.000 messages per hour.我们至少应该能够每小时处理 200.000 条消息,但目前我们每小时几乎不能达到 50.000 条消息。

Our application requests batches of 250 messages from the Queue (which now takes about 2 seconds to get the id's from the azure queue and about 5 seconds to get the actual data from the azure blob storage) and we're storing this data in one time into the database using a stored procedure accepting a datatable.我们的应用程序从队列中请求批量 250 条消息(现在大约需要 2 秒才能从 azure 队列中获取 id,大约需要 5 秒才能从 azure blob 存储中获取实际数据)并且我们一次性存储这些数据使用接受数据表的存储过程进入数据库。 Our service also resides in Azure on a virtual machine, and we use the nuget-libraries Azure.Storage.Queues and Azure.Storage.Blobs suggested by Microsoft to access the Azure Storage queue and blob storage. Our service also resides in Azure on a virtual machine, and we use the nuget-libraries Azure.Storage.Queues and Azure.Storage.Blobs suggested by Microsoft to access the Azure Storage queue and blob storage.

Does anyone have suggestions how to improve the speed of reading messages from the Azure Queue and then retrieving the data from the Azure Blob?有没有人建议如何提高从 Azure 队列读取消息然后从 Azure Blob 检索数据的速度?

            var managedIdentity = new ManagedIdentityCredential();

            UriBuilder fullUri = new UriBuilder()
            {
                Scheme = "https",
                Host = string.Format("{0}.queue.core.windows.net",appSettings.StorageAccount),
                Path = string.Format("{0}", appSettings.QueueName),
            };
            queue = new QueueClient(fullUri.Uri, managedIdentity);
            queue.CreateIfNotExists();
            ...
            var result = await queue.ReceiveMessagesAsync(1);
            ...
            UriBuilder fullUri = new UriBuilder()
            {
                Scheme = "https",
                Host =  string.Format("{0}.blob.core.windows.net", storageAccount),
                Path = string.Format("{0}", containerName),
            };

            _blobContainerClient = new BlobContainerClient(fullUri.Uri, managedIdentity);
            _blobContainerClient.CreateIfNotExists();
            ...


        public async Task<BlobMessage> GetBlobByNameAsync(string blobName)
        {
            Ensure.That(blobName).IsNotNullOrEmpty();

            var blobClient = _blobContainerClient.GetBlobClient(blobName);
            if (!blobClient.Exists())
            {
                _log.Error($"Blob {blobName} not found.");
                throw new InfrastructureException($"Blob {blobName} not found.");
            }

            BlobDownloadInfo download = await blobClient.DownloadAsync();
            return new BlobMessage
                {
                    BlobName = blobClient.Name,
                    BaseStream = download.Content,
                    Content = await GetBlobContentAsync(download)
                };
        }

Thanks,谢谢,

Vincent.文森特。

Based on the code you posted, I can suggest two improvements:根据您发布的代码,我可以提出两项改进建议:

  1. Receive 32 messages at a time instead of 1 : Currently you're getting just one message at a time ( var result = await queue.ReceiveMessagesAsync(1); ).一次接收 32 条消息而不是 1 条:目前您一次只收到一条消息( var result = await queue.ReceiveMessagesAsync(1); )。 You can receive a maximum of 32 messages from the top of the queue.您最多可以从队列顶部接收 32 条消息。 Just change the code to var result = await queue.ReceiveMessagesAsync(32);只需将代码更改为var result = await queue.ReceiveMessagesAsync(32); to get 32 messages.获得 32 条消息。 This will save you 31 trips to storage service and that should lead to some performance improvements.这将为您节省 31 次访问存储服务的次数,这应该会带来一些性能改进。

  2. Don't try to create blob container every time : Currently you're trying to create a blob container every time you process a message ( _blobContainerClient.CreateIfNotExists(); ).不要每次都尝试创建 blob 容器:目前您正在尝试在每次处理消息时创建一个 blob 容器( _blobContainerClient.CreateIfNotExists(); )。 It is really unnecessary.这真的是不必要的。 With fetching 32 messages, you're reducing this method call by 31 times however you can just move this code to your application startup so that you only call it once during your application lifecycle.通过获取 32 条消息,您将此方法调用减少了 31 次,但是您可以将此代码移动到应用程序启动中,以便在应用程序生命周期中只调用一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM