@@ -357,7 +357,9 @@ public long getSplitBacklogBytes() {
357
357
*/
358
358
private static final Duration KAFKA_POLL_TIMEOUT = Duration .millis (1000 );
359
359
360
- private static final Duration RECORDS_DEQUEUE_POLL_TIMEOUT = Duration .millis (10 );
360
+ private Duration recordsDequeuePollTimeout ;
361
+ private static final Duration RECORDS_DEQUEUE_POLL_TIMEOUT_MIN = Duration .millis (1 );
362
+ private static final Duration RECORDS_DEQUEUE_POLL_TIMEOUT_MAX = Duration .millis (20 );
361
363
private static final Duration RECORDS_ENQUEUE_POLL_TIMEOUT = Duration .millis (100 );
362
364
363
365
// Use a separate thread to read Kafka messages. Kafka Consumer does all its work including
@@ -543,6 +545,7 @@ Instant updateAndGetWatermark() {
543
545
bytesReadBySplit = SourceMetrics .bytesReadBySplit (splitId );
544
546
backlogBytesOfSplit = SourceMetrics .backlogBytesOfSplit (splitId );
545
547
backlogElementsOfSplit = SourceMetrics .backlogElementsOfSplit (splitId );
548
+ recordsDequeuePollTimeout = Duration .millis (10 );
546
549
}
547
550
548
551
private void consumerPollLoop () {
@@ -614,8 +617,7 @@ private void nextBatch() throws IOException {
614
617
try {
615
618
// poll available records, wait (if necessary) up to the specified timeout.
616
619
records =
617
- availableRecordsQueue .poll (
618
- RECORDS_DEQUEUE_POLL_TIMEOUT .getMillis (), TimeUnit .MILLISECONDS );
620
+ availableRecordsQueue .poll (recordsDequeuePollTimeout .getMillis (), TimeUnit .MILLISECONDS );
619
621
} catch (InterruptedException e ) {
620
622
Thread .currentThread ().interrupt ();
621
623
LOG .warn ("{}: Unexpected" , this , e );
@@ -627,9 +629,19 @@ private void nextBatch() throws IOException {
627
629
if (consumerPollException .get () != null ) {
628
630
throw new IOException ("Exception while reading from Kafka" , consumerPollException .get ());
629
631
}
632
+ if (recordsDequeuePollTimeout .isLongerThan (RECORDS_DEQUEUE_POLL_TIMEOUT_MIN )) {
633
+ recordsDequeuePollTimeout = recordsDequeuePollTimeout .minus (Duration .millis (1 ));
634
+ LOG .debug ("Reducing poll timeout for reader to " + recordsDequeuePollTimeout .getMillis ());
635
+ }
630
636
return ;
631
637
}
632
638
639
+ if (recordsDequeuePollTimeout .isShorterThan (RECORDS_DEQUEUE_POLL_TIMEOUT_MAX )) {
640
+ recordsDequeuePollTimeout = recordsDequeuePollTimeout .plus (Duration .millis (1 ));
641
+ LOG .debug ("Increasing poll timeout for reader to " + recordsDequeuePollTimeout .getMillis ());
642
+ LOG .debug ("Record count: " + records .count ());
643
+ }
644
+
633
645
partitionStates .forEach (p -> p .recordIter = records .records (p .topicPartition ).iterator ());
634
646
635
647
// cycle through the partitions in order to interleave records from each.
0 commit comments