繁体   English   中英

Azure 存储队列性能

[英]Azure Storage Queue performance

我们正在迁移一个事务处理服务,该服务处理来自 MSMQ 的消息并将事务存储在 SQLServer 数据库中,以使用 Azure 存储队列(存储消息的 id 并将实际消息放入 Azure 存储 Blob)。

我们至少应该能够每小时处理 200.000 条消息,但目前我们每小时几乎不能达到 50.000 条消息。

我们的应用程序从队列中请求批量 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.

有没有人建议如何提高从 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)
                };
        }

谢谢,

文森特。

根据您发布的代码,我可以提出两项改进建议:

  1. 一次接收 32 条消息而不是 1 条:目前您一次只收到一条消息( var result = await queue.ReceiveMessagesAsync(1); )。 您最多可以从队列顶部接收 32 条消息。 只需将代码更改为var result = await queue.ReceiveMessagesAsync(32); 获得 32 条消息。 这将为您节省 31 次访问存储服务的次数,这应该会带来一些性能改进。

  2. 不要每次都尝试创建 blob 容器:目前您正在尝试在每次处理消息时创建一个 blob 容器( _blobContainerClient.CreateIfNotExists(); )。 这真的是不必要的。 通过获取 32 条消息,您将此方法调用减少了 31 次,但是您可以将此代码移动到应用程序启动中,以便在应用程序生命周期中只调用一次。

暂无
暂无

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

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