Load Testing AWS MSK with Apache JMeter : Kafka Producer setup and KPI's

 Amazon Managed Streaming for Apache Kafka (MSK) is a fully managed service that makes it easy to build and run applications that use Apache Kafka for real-time data streaming.

In this guide, we’ll walk through how to use Apache JMeter — an open-source load testing tool — to test AWS MSK Kafka setup. We’ll cover:

  • Required plugins and JAR files
  • Configuration settings for Kafka producer/consumer samplers
  • A sample JMeter script (JMX) for sending and reading messages from MSK
  • Authentication (SASL/SCRAM, IAM) needed

Plugins and JAR files :

  • kafka-clients-3.3.1
  • guava-31.1-jre
  • lz4-java-1.8.0
  • snappy-java-1.1.8.4
  • zstd-jni-1.5.2–1

These jar files will be installed when you will install “DI KafkaMeter ” from plugin manager

Press enter or click to view image in full size

Configuration settings for Kafka producer config and samplers :

Add the Kafka producer config from Add > Config Element > Kafka Producer Config path and add the required details as below :

Press enter or click to view image in full size

Add below details to your Kafka producer config key value pairs to successfully create the connection/authentication:

Kafka Brokers : Address of the brokers , this can be found from Amazon Account> MSK > Clusters > Select your MSK cluster > Properties > Brokers .

it will list all the brokers configured on for the msk in the format b-2.msk***.kafka.eu-west-2.amazonaws.com:9096,b-1.msk***.kafka.eu-west-2.amazonaws.com:9096,b-3.msk***.kafka.eu-west-2.amazonaws.com:9096

Batch Size : leave default i.e. 16384

Client ID : Name of the sender , any randome name like kafka-jmeter

Serializer key and Serializer value : leave default i.e. org.apache.kafka.common.serialization.StringSerializer

Security : Kafka uses two main layers of security below , in my kafka setup it is using SASL/SSL .

Configure the SASL properties in the Additional Properties section as below :

security.protocol = SASL_SSL

sasl.mechanism = SCRAM-SHA-512

sasl.jaas.config = org.apache.kafka.common.security.scram.ScramLoginModule required username=”YOUR_USERNAME” password=”YOUR_PASSWORD”;

ssl.endpoint.identification.algorithm=https

Add the Kafka producer sampler from Add > Sampler > Kafka Producer Sampler under your choice of thread group and add the required details as below :

Press enter or click to view image in full size

Add below details to your Kafka producer sampler key value pairs to successfully send the message :

Variable name of the producer — Same variable name which is used in kafka producer config

Kafka Topic — Your kafka topic on which you want to send the message

Kafka message – The message which is to be send in the format it is expected .

Partition string – Leave it blank if you do not want to sned it to any specific partition

Kafka message key – unique message key

Message headers — Required headers with your message

Running the test :

After adding this details to your test plan you will be able to run the test same way as any other jmeter tests with different thread groups .

You can run these tests from same VPC on which your Kafka cluster is hosted , if you are running it locally you will get below errors :

Error from view results tree :
Response code:500
java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.TimeoutException: Topic ****** not present in metadata after 60000 ms.

Error in Jmeter logs :
2025–09–04 11:29:15,929 INFO o.a.k.c.NetworkClient: [Producer clientId=kafka-jmeter] Disconnecting from node -2 due to socket connection setup timeout. The timeout value is 9907 ms.
2025–09–04 11:29:15,931 WARN o.a.k.c.NetworkClient: [Producer clientId=kafka-jmeter] Bootstrap broker b-1.msk***.kafka.eu-west-2.amazonaws.com:9096 (id: -2 rack: null) disconnected

Monitoring Kafka :

Consumer lag :

Monitor consumer lag to ensure consumers keep up with message production. High consumer lag indicates issues with the consumer or the Kafka cluster.

Broker resource utilisation:

Keep track of broker resource utilisation, such as CPU and memory usage. High resource utilisation indicates that the Kafka cluster requires additional resources to function correctly.

Topic and partition metrics :

Topics and partitions are key Kafka concepts that help organise and distribute data within a Kafka cluster. Monitoring metrics like the number of messages produced, consumed, and lagging can help in identifying any problems with data processing or consumer performance.

Replication and failover monitoring :

Monitoring replication and failover mechanisms are critical for ensuring the high availability and reliability of Kafka clusters. Ensure that replicas are in sync, detect out-of-sync replicas, and monitor the replication and failover systems’ performance.

Under Replicated Partitions:

The Under Replicated Partitions metric displays the number of partitions that do not have enough replicas to meet the desired replication factor. A partition will also be considered under-replicated if the correct number of replicas exist, but one or more of the replicas have fallen significantly behind the partition leader. Expected value: 0

Active Controller Count:

The Active controller panel identifies which broker in the cluster is reporting as the Active controller. In a Kafka cluster, one of the brokers serves as the controller, which is responsible for managing the states of partitions and replicas and for performing administrative tasks like reassigning partitions. Expected value: 1 . More than 1 active controller results in risk of executing administrative commands multiple times without any consistency.

Offline Partitions Count:

The number of partitions that do not have an active leader and are hence not writable or readable. Expected value: 0

Comments

Popular posts from this blog

Performance Testing Interview Preparation Guide

Performance Testing Interview Tutorials

Performance Testing Interview Question - Part 02