Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion plugins/in_kafka/in_kafka.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,25 @@ static int in_kafka_collect(struct flb_input_instance *ins,
ret = FLB_EVENT_ENCODER_SUCCESS;

while (ret == FLB_EVENT_ENCODER_SUCCESS) {
rkm = rd_kafka_consumer_poll(ctx->kafka.rk, 1);
/* Set the Kafka poll timeout based on execution mode:
*
* a) Running in the main event loop (non-threaded):
* - Use a minimal timeout to avoid blocking other inputs.
*
* b) Running in a dedicated thread:
* - Optimize for throughput by allowing Kafka's internal batching.
* - Align with 'fetch.wait.max.ms' (default: 500ms) to maximize batch efficiency.
* - Set timeout slightly higher than 'fetch.wait.max.ms' (e.g., 1.5x - 2x) to
* ensure it does not interfere with Kafka’s fetch behavior, while still
* keeping the consumer responsive.
*/
if (ctx->ins->flags & FLB_INPUT_THREADED) {
/* Threaded mode: Optimize for batch processing and efficiency */
rkm = rd_kafka_consumer_poll(ctx->kafka.rk, ctx->poll_timeout_ms);
} else {
/* Main event loop: Minimize delay for non-blocking execution */
rkm = rd_kafka_consumer_poll(ctx->kafka.rk, 1);
}

if (!rkm) {
break;
Expand Down Expand Up @@ -428,6 +446,14 @@ static struct flb_config_map config_map[] = {
0, FLB_TRUE, offsetof(struct flb_in_kafka_config, buffer_max_size),
"Set the maximum size of chunk"
},
{
FLB_CONFIG_MAP_INT, "poll_timeout_ms", "1",
0, FLB_TRUE, offsetof(struct flb_in_kafka_config, poll_timeout_ms),
"Set the timeout in milliseconds for Kafka consumer poll operations. "
"This option only takes effect when running in a dedicated thread (i.e., when 'threaded' is enabled). "
"Using a higher timeout (e.g., 1.5x - 2x 'rdkafka.fetch.wait.max.ms') "
"can improve efficiency by leveraging Kafka's batching mechanism."
},
/* EOF */
{0}
};
Expand Down
1 change: 1 addition & 0 deletions plugins/in_kafka/in_kafka.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct flb_in_kafka_config {
int coll_fd;
size_t buffer_max_size; /* Maximum size of chunk allocation */
size_t polling_threshold;
int poll_timeout_ms;
};

#endif
Loading