簡體   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