An Azure service that provides cloud messaging as a service and hybrid integration.
Use the Premium tier features and client-side optimizations to remove the send latency bottleneck and avoid timeouts when load increases.
- Validate capacity and tier usage
- Premium provides dedicated messaging units (MUs). Each MU delivers about 4 MB/s of ingress and 4 MB/s of egress in benchmark tests.
- If message size × send rate under load approaches or exceeds this per-MU throughput, increase the number of MUs or enable auto-scaling so the namespace can handle spikes without throttling.
- Ensure the workload is actually using the Premium namespace (not a Standard one) and that auto-scaling is configured with appropriate minimum and maximum MUs.
- Optimize client concurrency and async usage
- High send latency often comes from serial, synchronous operations on the client side rather than the Service Bus itself.
- Use asynchronous send APIs from the .NET client and schedule multiple concurrent send operations so that the next send starts before the previous one completes.
- Run multiple concurrent senders (threads or tasks) instead of a single sender under load. This increases the number of operations per unit time and hides network latency.
- Use batching for sends
- Instead of sending one message per call, batch messages using the batch send APIs (for example,
SendMessages()equivalents in the SDK). - Batching reduces network round trips and connection overhead, which significantly improves throughput and reduces per-message latency when load increases.
- Tune connection and network behavior
- Ensure connection pooling is enabled and reuse
MessagingFactory/ServiceBusClientinstances instead of creating them per request. - Co-locate the SOAP API compute (App Service, VM, etc.) in the same Azure region as the Service Bus Premium namespace to minimize network latency.
- Verify there is no network bottleneck (firewall, proxy, or VPN) adding latency when many concurrent connections are opened.
- Configure prefetch and receive patterns on consumers
- If the queue is backing up because consumers are slow, send operations can be indirectly impacted by throttling or resource contention.
- Use prefetch on receivers and multiple concurrent receivers to keep the queue depth under control and maintain steady throughput.
- Monitor and detect throttling or bottlenecks
- Use Azure Monitor metrics for the namespace to track:
- Message throughput (ingress/egress)
- Queue depth trends
- Throttling events and server errors
- Processing latency
- If throttling is observed, increase MUs, enable/adjust auto-scaling, or distribute load across additional queues/namespaces.
- Adjust timeout and retry behavior
- Ensure the client uses the default retry policy for Service Bus so transient throttling or network delays do not immediately cause failures.
- Set reasonable operation timeouts in the client; combine this with retries rather than a single long operation that times out at 110 seconds.
- Capacity planning and load testing
- Perform capacity planning based on expected peak message volume, size, and concurrency.
- Use Azure Load Testing or similar tools to simulate realistic workloads and validate that the configured MUs, batching, and concurrency levels sustain the required throughput without hitting timeouts.
Applying these changes—Premium MU sizing/auto-scaling, async and concurrent sends, batching, regional co-location, and proper monitoring—will address the latency spikes when pushing messages under load.
References: