Load Testing Azure Service Bus
Published Feb 28 2024 09:34 AM 4,788 Views

Introduction

Azure Service Bus is a fully managed enterprise message broker that allows you to connect, decouple, and exchange messages between different applications and services. It supports a range of communication patterns, such as queues, topics, and event hubs, and enables reliable and secure message delivery at scale.

However, to ensure that your Azure Service Bus solution can handle the expected load and performance requirements, you need to conduct load testing and measure the throughput, latency, and resource utilization of your system under various scenarios. Load testing can help you identify and resolve any bottlenecks, errors, or failures that might occur when your system is under stress.

In this blog post, we will show you how to use JMeter and Azure Load Testing to load test Azure Service Bus using AMQP protocol and provide some tips and best practices to optimize performance.

Scenarios

Load testing an Azure Service Bus is crucial in several scenarios:

  • Performance optimization: Load testing helps identify the optimal configuration for your Service Bus namespaces, which depends on various factors involving your application architecture and how each of the Service Bus features is used.
  • Throughput Calculation: Load testing can help calculate the throughput requirement by considering the data that is being sent to and received from the Service Bus.
  • Resource Planning: Prudent planning is key in ensuring that Azure Service Bus provides the performance that your application expects. Load testing can help determine the right configuration or topology for your Service Bus namespaces.
  • Handling Network Traffic Spikes: Load testing can simulate high traffic scenarios to ensure that your Service Bus can handle sudden spikes in network traffic.

Prerequisites

  • A valid Azure subscription. If you don't have one, you can create a free account.
  • An Azure Service Bus namespace and a queue or topic to test. You can follow the instructions to create them.
  • A JMeter installation. You can download the latest version of JMeter.
  • A JMeter plugin for Azure Service Bus. You can download the plugin and copy the jar file to the lib/ext folder of your JMeter installation.

Creating a JMeter Test Plan

To create a JMeter test plan for Azure Service Bus, follow these steps:

  1. Open JMeter and create a new test plan by clicking on the File menu and selecting New.
  2. Right-click on the Test Plan node and select Add > Threads (Users) > Thread Group. Configure the number of threads, duration etc.
  3. Right-click on the thread group node and select Add > Sampler > Azure Service Bus Sampler.
  4. Configure the sampler parameters, such as the Service Bus Namespace, Queue / Topic name and configure the authentication. In this case I’m using the Shared access signature and provided the key as a secret which is store in Azure Key Vault.
  5. Enter the message body and add some message properties. 
  6. To identify the requests with successful responses, add a JSR223 PostProcessor with the script given below.

 

 

if (prev.isSuccessful() && (prev.getResponseCode() == null || prev.getResponseCode() == "")) {
    prev.setResponseCode("200");
}

 

 

Screenshot of JMeter GUI showing the Azure Service Bus SamplerScreenshot of JMeter GUI showing the Azure Service Bus Sampler

Download the JMeter script shown above here.

 

Running and Analyzing the Test

Once you have created and saved the test plan, you can run it and analyze the results on Azure Load Testing. To run the test plan, follow these steps:

  1. Navigate to your load testing resource in Azure portal.
  2. Create a test by uploading the JMeter script. Along with the JMX file, upload the jar file for the Azure Service Bus plugin.
  3. In the monitoring section, add the Service Bus namespace that you’re testing to view the metrics during the test.

Screenshot of a test run in Azure Load TestingScreenshot of a test run in Azure Load Testing

 

To analyze the results, you can look for the following indicators:

  • The active message count, which is the number of messages in the queue or topic that are ready to be received. You can use this metric to check the health of your message processing and identify any backlog or congestion issues.
  • The dead-letter message count, which is the number of messages that have been moved to the dead-letter queue due to expiration, exceeding the maximum delivery count, or other reasons. You can use this metric to troubleshoot any errors or failures in your message handling logic and take corrective actions.
  • The average message size, which is the average size of the messages in bytes that have been sent or received. You can use this metric to optimize your message payload.
  • The server errors, which is the number of errors that have occurred on the server side while processing requests. You can use this metric to monitor the availability and reliability of the service and investigate any potential issues.

A screenshot of the Azure Service Bus metricsA screenshot of the Azure Service Bus metrics

 

Optimizing perfromance of Azure Service Bus

 

Some tips to optimize the performance of Azure Service Bus are mentioned below.

  • Choose the right tier for your workload. Azure Service Bus offers three tiers: Basic, Standard, and Premium. The Basic tier is suitable for simple scenarios that do not require advanced features such as sessions, transactions, duplicate detection, dead-lettering, or batching. The Standard tier supports all these features and also enables cross-entity joins and auto-forwarding. The Premium tier provides dedicated resources and enhanced performance, availability, and security. You can use the Premium tier if you need consistent and predictable performance, high throughput, low latency, or isolation from other tenants.
  • Use AMQP or MQTT protocols instead of HTTP. Azure Service Bus supports three messaging protocols: AMQP, MQTT, and HTTP. AMQP and MQTT are binary protocols that offer higher performance and lower overhead than HTTP, which is a text-based protocol. AMQP and MQTT also support persistent connections, which reduce the network latency and improve the message delivery rate. HTTP requires opening and closing a connection for each request, which adds more overhead and delays. You can configure the protocol in your client library or SDK when creating the connection to the service bus namespace.
  • Enable partitioning for your queues and topics. Partitioning is a feature that increases the scalability and availability of your entities by distributing the load across multiple message brokers and message stores. When you use partitioned premium tier namespaces, multiple partitions with lower messaging units (MU) give you a better performance over a single partition with higher MUs.

Learn more about best practices for performance improvements using Service Bus Messaging here.

Conclusion

In this blog post, we have shown you how to use Azure Load Testing to load test Azure Service Bus and provide some tips and best practices to optimize performance. With this approach you can also test other services which are integrated with Azure Service Bus. For example, an API hosted on Azure Functions, which is triggered when a message is added to the Azure Service Bus queue can be testing using the same approach.

We hope that this guide will help you to evaluate and improve the performance and reliability of your Azure Service Bus solution. If you haven’t tried Azure Load Testing yet, create an Azure Load Testing resource and get started with your first test run in a few minutes. Let us know your feedback through our feedback forum.

 

Happy load testing!

Co-Authors
Version history
Last update:
‎Feb 28 2024 07:41 PM
Updated by: