KafkaConsumer.PlainSource Method (in C#.Net) Using large amount of CPU

135 views Asked by At

below method using large amount of CPU can anyone help me to minimize the CPU usage with proper solution.

KafkaConsumer.PlainSource(
   consumerSettings, subscription)
     .RunForeach(result =>
      { 
          _ActorRef.Tell(result.Message.Value);
       }, materializer);
1

There are 1 answers

0
Aaronontheweb On

I'm running the SimpleProducer and SimpleConsumer samples baked into the Akka.Streams.Kafka repository - and the PlainSource is designed in a nearly identical fashion to yours:

 KafkaConsumer.PlainSource(consumerSettings, subscription)
            .RunForeach(result =>
            {
                Console.WriteLine($"Consumer: {result.Topic}/{result.Partition} {result.Offset}: {result.Message.Value}");
            }, materializer);

Akka.Streams.Kafka PlainConsumer output

Here's what my CPU utilization looks like - bearing in mind that the producer is continuously producing new events for my consumer:

Akka.Streams.Kafka CPU output

This is extremely low resource consumption - which is what Akka.Streams and all of its plugins (such as Kafka) provide out of the box.

Your setup has no backpressure support (since IActorRef.Tell is non-blocking) and therefore this stream is going to run at full blast inside your system. Whatever your actors are doing is probably what's responsible for high CPU utilization.

Your other ticket is asking about how to add backpressure support to your Akka.Streams.Kafka application, so I'll help answer that too.