You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run the consumer with partitionsConsumedConcurrently > 1
await consumer.run({
partitionsConsumedConcurrently: 2, // This causes the CPU load
eachMessage: async ({ topic, partition, message }) => {
console.log({
topic,
partition,
offset: message.offset,
value: message.value.toString(),
});
},
});
Don't write any messages to the topic or wait for the consumer to catch up with the lag
Wait for at least 30 seconds and observe the CPU usage
confluent-kafka-javascript Configuration Settings
Here is the full minimal snippet we use to reproduce:
const { Kafka } = require('@confluentinc/kafka-javascript').KafkaJS;
const topic = 'TestTopic';
const clientId = 'test-client-id';
const kafka = new Kafka({
kafkaJS: {
clientId: clientId,
brokers: ['localhost:9092'],
logLevel: 4, // optional, but gives a hint what overuses the CPU
},
});
const consumerRun = async () => {
const consumer = kafka.consumer({
kafkaJS: {
groupId: 'test-group',
},
});
await consumer.connect();
console.log('Consumer connected');
await consumer.subscribe({ topic });
console.log('Consumer subscribed to topic');
await consumer.run({
partitionsConsumedConcurrently: 2, // This causes the CPU load
eachMessage: async ({ topic, partition, message }) => {
console.log({
topic,
partition,
offset: message.offset,
value: message.value.toString(),
});
},
});
};
consumerRun().catch((err) => {
console.error('Error running producer or consumer:', err);
});
Additional context
When setting logLevel: 4 in the Kafka constructor and using partitionsConsumedConcurrently: 1, the following log message
{
message: 'Attempting to fetch 1 messages to the message cache',
name: 'test-client-id#consumer-1',
fac: 'BINDING',
timestamp: 1733298033731
}
``` is printed ~ once in a second, however, when setting `partitionsConsumedConcurrently: 2` the console is spammed with the message.
Setting `logLevel: 3` makes it better as IO is used less, but the code that prints the message is still running causing high usage of CPU
The text was updated successfully, but these errors were encountered:
maksym-opanasenko-ft
changed the title
High CPU usage when utilising a consumer with partitionsConsumedConcurrently > 1 following the kafkaJs constructor
partitionsConsumedConcurrently > 1 overloads CPU when consumers lag is 0
Dec 7, 2024
We're experiencing the same issue, we have multiple consumers that don't perform CPU intensive work, but we have topics with around 100 partitions so we have been using partitionsConsumedConcurrently with pretty high numbers in KafkaJS with great success. But just migrating and using same high numbers (10, 25, 5 etc) we're seeing issues with CPU, GC durations skyrocketing and that's basically when the consumers are idle. When changing it back to 1 again, everything is super cool and steady as you can see on the graphs.
I have also been testing out different high values of UV_THREADPOOL_SIZE but can't say I noticed any difference, but will keep on testing it.
Environment Information
7.7.x
,7.5.x
,7.3.x
; also confirmed withApache Kafka 3.3.x
^0.5.2
Steps to Reproduce
kafkaJs
constructor:partitionsConsumedConcurrently > 1
confluent-kafka-javascript Configuration Settings
Here is the full minimal snippet we use to reproduce:
Additional context
When setting
logLevel: 4
in the Kafka constructor and usingpartitionsConsumedConcurrently: 1
, the following log messageThe text was updated successfully, but these errors were encountered: