Azure ServiceBus SendMessageAsync偶发性能劣化问题排查求助
Azure ServiceBus 随机发送/接收超时排查求助
我有一个部署在Azure上的.NET Web API,已将消息发布者、ServiceBusClient和ServiceBusAdministrationClient都注册为单例服务。近期随机遇到性能问题,定位发现await sender.SendMessageAsync(message)是瓶颈之一:多数时候仅耗时数毫秒,但每10次调用里会有几次耗时超过10秒。
发布消息代码
public async Task PublishMessageAsync<T>(T entity, bool isQueue = false) { var queueOrTopicName = "{my topic name}"; try { if (ConnectionIsClosed()) OpenClient(); if (_client == null) return; if (!await _serviceBusAdministrator.MessageNamespaceExists(queueOrTopicName, isQueue)) throw new Exception($"Unable to create message namespace for {queueOrTopicName}!"); var serializedBody = JsonSerializer.Serialize(entity); var message = new ServiceBusMessage(serializedBody); // 复用Sender尝试优化性能 ServiceBusSender sender = null; if (_senders.ContainsKey(queueOrTopicName)) { sender = _senders[queueOrTopicName]; } else { sender = _client.CreateSender(queueOrTopicName); _senders.Add(queueOrTopicName, sender); } // 此处随机出现超长耗时 await sender.SendMessageAsync(message).ConfigureAwait(false); } catch (TimeoutException ex) { _logger.LogInformation(ex, $"Timeout exception raised when publishing to {queueOrTopicName}. Detail: {ex.Message}"); } }
使用的ServiceBus包版本
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.11.1" />
更奇怪的是,在App Insights中,ServiceBus的Receive调用也出现极长耗时,不确定两者是否相关,但确实属于异常情况。我们使用的是标准层,且消息量并不大,因此排除容量不足的问题,希望有人能提供排查方向,非常感谢。

内容的提问来源于stack exchange,提问作者Brandon
相关产品推荐
相关产品推荐

