Kafka Load Test

Gatling as maven dependencies:

<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>4.19.1</version>
</plugin>

<dependencies>
    <dependency>
      <groupId>io.gatling.highcharts</groupId>
      <artifactId>gatling-charts-highcharts</artifactId>
      <version>3.14.3</version>
      <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.kafka/kafka-clients -->
    <dependency>
        <groupId>org.apache.kafka</groupId>
        <artifactId>kafka-clients</artifactId>
        <version>4.0.0</version>
    </dependency>
</dependencies>

I have created load test:

import io.gatling.javaapi.core.*;
import org.apache.kafka.clients.producer.*;

import java.util.Properties;
import java.util.concurrent.TimeUnit;

import static io.gatling.javaapi.core.CoreDsl.*;

public class KafkaLoadTesting extends Simulation {
    private static final String TOPIC = "likes-bucket";
    private static final String BOOTSTRAP_SERVERS = "localhost:9092";


    private static void sendKafkaMessage(String message) {
        Properties props = new Properties();
        props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS);
        props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
        props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");

        Producer<String, String> producer = new KafkaProducer<>(props);
        ProducerRecord<String, String> record = new ProducerRecord<>(TOPIC, message);
        producer.send(record);
        producer.close();
    }

    ChainBuilder kafkaAction = exec(session -> {
        String payload = "{\"talkName\":\"Spring best practice\",\"likes\":1}";
        sendKafkaMessage(payload);
        return session;
    });

    {
        setUp(
                scenario("Kafka Load Test")
                        .exec(kafkaAction)
                        .pause(1, TimeUnit.SECONDS.ordinal())
                        .repeat(100).on(kafkaAction)
                        .injectOpen(atOnceUsers(10))
        ).protocols();
    }
}

I run the test ./mvnw clean gatling:test

I got loop:

What i do wrong ?

Hi,

Gatling’s session function don’t log action time, and putting blocking code in them is a really bad idea.

Just use the Kafka plugin:
:link: gatling-kafka-plugin

1 Like

This is not official plugin if i’m not mistaken. Do you know how to develop load testing for kafka with some official Gatling functionality?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.