Search code examples
apache-kafkaperformance-testingperformance-measuring

how to capture processing times of messages flowing thru MQ -> App -> Kafka -> App -> Kafka


I have systems pipeline as "IBM MQ queue --> Springboot app (Message Formatter) --> Kafka topic-1 (message queue) --> Springboot app (Message Transformer) --> --> Kafka topic-2 (message queue)".

My requirement is to test end to end processing time of messages generated in IBM MQ and processed thru the pipeline. I have a JMeter Load test script with JMS client that generates loads of messages pumped thru the pipeline. Dynatrace Kafka monitoring is not yet implemented but Confluent Control Center for Kafka monitoring is used here.

Can you please suggest possible options to measure the individual and end to end processing times of messages processed by Springboot apps (Message Formatter and Message Transformer apps being deployed via DevOps Jenkins pipeline)?


Solution

  • Theoretically you can get the number of pending messages in the Kafka topic from JMeter itself using Kafka Client Consumer code from JSR223 Test Elements

    Example code:

    KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
    consumer.subscribe(Collections.singletonList("test"));
    while(true) {
        ConsumerRecords<String, String> records = consumer.poll(100);
        for (ConsumerRecord<String, String> record : records) {
            System.out.printf("offset = %d, key = %s, value = %s%n", record.offset(), record.key(), record.value());
    
            // after each message, query the number of messages of the topic
            Set<TopicPartition> partitions = consumer.assignment();
            Map<TopicPartition, Long> offsets = consumer.endOffsets(partitions);
            for(TopicPartition partition : offsets.keySet()) {
                System.out.printf("partition %s is at %d\n", partition.topic(), offsets.get(partition));
            }
        }
    }
    

    The values can be stored into Sample Variables using vars shorthand and plotted into JMeter HTML Reporting Dashboard as custom charts.