Load testing Azure EventHubs with JMeter

Azure EventHubs architecture overview (more here)

Azure EventHubs is a reliable, resilient, scalable data ingestion service offered by Microsoft.

Being able to handle obscene amounts of events per second, it represents one of the hottest choices amongst streaming platforms that are currently offered as PaaS solutions.

It is crucial to perform efficient load testing on applications that rely on EventHubs, to detect all kinds of issues (memory leaks, inefficient code paths, bottlenecks of sorts…).

But, as important as it might be, it’s also not very straightforward.

At the time of writing, there are very few — as a matter of fact, I couldn’t find any for my specific needs — prefabricated solutions that can easily allow us to verify the performance of applications whose events are handled via EventHubs. Also, things like Avro serialization and schema registries utterly complicate a seemingly easy task.

Apache JMeter is one of the most common tools used for load and performance testing. It is very well endowed when it comes down to testing Web applications, but it isn’t as easy to test event-driven APIs with it.

While for other solutions, such as Apache Kafka, there might be JMeter plugins that can do most of the work for us, there is no such thing for Azure EventHubs.

Since I recently needed to load test an application that relies on EventHubs, I ended up doing most of the work so that you don’t have to! :-)

Let’s cut to the chase then.

JMeter Set-up

The first thing you need is to define some variables for your JMeter Test Plan.

In particular, you should define the following variables that will be needed for the next steps:

╔═══════════════════════════╦══════════════════════════════════╗
║ Variable ║ Value ║
╠═══════════════════════════╬══════════════════════════════════╣
║ storageAccount ║ my-storage-account-name ║
║ storageAccessKey ║ my-storage-account-access-key ║
║ eventHubsConnectionString ║ my-connection-string ║
║ schemaRegistryUrl ║ http://my-schema-registry.com:80
╚═══════════════════════════╩══════════════════════════════════╝

Before digging into the code that’s necessary to complete our task, we need to include all the required external libraries we’ll be using, in Apache JMeter.

With the help of the maven-assembly-plugin, you can pack them all into a single fat jar — if you don’t have maven installed, refer to this guide before going any further.

Save the following pom.xml file:

Now, move to the directory where you just put the pom.xml file and run:

mvn package

Once the build is completed, move inside the target directory and copy the jmeter-dependencies-jar-with-dependencies.jar file inside the <JMETER_FOLDER>/lib/ext directory.

A JSR223 Sampler as seen in the Apache JMeter GUI

All that’s left to do now is creating a JSR223 Sampler element in your JMeter Test Plan, that is capable of sending events to your instance of Azure EventHubs.

The sampler should look like the one shown just above; use groovy as your scripting language of choice, and pass the variables we previously created as script parameters:

${storageAccount} ${storageAccessKey} ${eventHubsConnectionString} ${schemaRegistryUrl}

The body of the script should resemble the following — make sure to replace {{my-schema-name}} with the schema name in your schema registry, {{my-topic-name}} with the EventHub/topic name, and the payload content with your payload in JSON format:

Groovy script to send Avro serialized messages to EventHubs

Wrapping Up

With this setup in place, you’re now able to send any Avro serialized event you’d like to any EventHub/topic in your EventHubs namespace, with nothing else than JMeter.

Good luck and happy performance testing! :-)

Software Developer @ https://www.linkedin.com/in/dsibilio/ — If my articles helped you, consider buying me a coffee :) https://www.buymeacoffee.com/dsibilio

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store