Performance Tuning

Target Version: NServiceBus 5.x
Standard support for version 5.x of NServiceBus has expired. For more information see our Support Policy.
This page refers to the legacy Azure Service Bus transport that uses the WindowsAzure.ServiceBus NuGet package. This package is currently on extended support until May 2022, after which it will be out of support according to the support policy. All users should migrate to the Azure Service Bus transport transport.

CPU vs I/O-bound processing

The following settings are used in order to tune performance:

  • MaximumConcurrencyLevel
  • BatchSize
  • LockDuration
  • MaxDeliveryCount

In scenarios where handlers perform CPU intensive and not I/O intensive work (such as in-memory computations), it is recommended to lower the number of threads to one and increase the BatchSize. LockDuration and MaxDeliveryCount might require an adjustment to match the batch size, taking into account the number of messages that end up in the dead letter queue.

In scenarios where handlers perform I/O intensive work, it is recommended to set the number of threads to 12 threads per logical core using MaximumConcurrencyLevel setting and set the BatchSize to a number of messages that takes to process. Take into account the expected (or measured) processing time and I/O latency of a single message. Start with a small BatchSize and through adjustment and measurement gradually increase it, while adjusting accordingly LockDuration and MaxDeliveryCount.

The number 12 is a good starting point, but might need to be changed in particular systems. It was determined as an optimal value in a series of experiments. The older versions of CLR by default used 25 threads per logical core. When 12 threads are assigned for receiving and processing messages, the other half is dealing with other background operations like transaction completions, sending, GC, etc. In recent versions of the CLR, the number of threads is determined dynamically, so it's necessary to verify if 12 will be still an optimal value empirically.

For more information on those settings, refer to the Tuning endpoint message processing, ASB Batching, ASB Message lock renewal and ASB Retry behavior articles.

Related Articles

Last modified