question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] High CPU utilization in Consumer App

See original GitHub issue

We implemented Consumer apps as a set of Azure Service Fabric services. Each app consumes messages only from one topic. And typical Kafka Consumer app has an infinite loop as its heart. Here is the pseudo-code for it:

public static void Main()
{
    [Initialize]
    consumer.Subscribe("my-topic");
    while (true)
    {
      var result = consumer.Consume();
      [Transform Result]
      producer.Produce(transformedResult); // Publish to another topic
    }
}

And the application above is trying to consume up to 50% of CPU.

Issue: When we deploy such service as a part of Azure Service Fabric Application then there could be a few consumer services running on the same node. And CPU usage would be ~100%.

We re-wrote this infinite loop

public static async Task Main()
{
    [Initialize]
    consumer.Subscribe("my-topic");
    while (true)
    {
      var result = consumer.Consume();
      [Transform Result]
      producer.Produce(transformedResult); // Publish to another topic
      
      //  Give chance to run other threads
      await Taks.Delay(1ms);  // We probably should use Task.Yield() or Task.Delay(0)
    }
}

And the app consumes less CPU, but a number of messages per second suffer.

Questions: Is there a deployment recommendation for Kafka consumer applications? One physical node - one consumer? Or is there a way to make a consumer application asynchronous without sacrificing performance?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mhowlettcommented, May 13, 2021

one thread per broker (3), plus an additional thread, plus a .net managed thread in the case of the producer.

0reactions
saherahwalcommented, May 13, 2021

Thank you!

On Thu, May 13, 2021 at 2:43 PM Matt Howlett @.***> wrote:

one thread per broker (3), plus an additional thread, plus a .net managed thread in the case of the producer.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/confluentinc/confluent-kafka-dotnet/issues/1261#issuecomment-840852526, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEGN257CGBXQ62DQMQNA5LTNRBZTANCNFSM4MQZS37A .

Saher Ahwal

Massachusetts Institute of Technology '13, '14 Department of Electrical Engineering and Computer Science @.*** @.**> | 617 680 4877

Read more comments on GitHub >

github_iconTop Results From Across the Web

Application consuming High CPU - Microsoft Q&A
Hello,. Our Application is running multiple processes (.exe) and each process utilizing CPU processor is always high while processing which near ...
Read more >
How do I troubleshoot a high CPU-consumption scenario?
Getting insight into what's triggering increased CPU consumption is a two-part process. First, create a process dump, and then analyze the ...
Read more >
Identify and Diagnose High CPU issues - Azure App Service
Analyze high CPU usage; Inspect CPU usage by instance; CPU Drill Down; App Level CPU Consumption; What's Next? This is part one of...
Read more >
Tanium Performance: Using Event Rules to Find High CPU ...
This article will discuss a few ways Tanium Performance can help find, visualize, and correlate commonalities among CPU issues, at enterprise ...
Read more >
High CPU Utilization in java application
I have a Java Application (web-based) that at times shows very high CPU Utilization (almost 90%) for several hours. Linux TOP command shows...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found