Skip to content

Commit

Permalink
Disable batch receive timer for Readers (apache#8381)
Browse files Browse the repository at this point in the history
- since the Reader implementation doesn't use the batch receiving
  functionality, it's more efficient to set the timeout to 0 of the
  BatchReceivePolicy of the internal consumer of the Reader
  implementation
  - this disables the timer that would get called every 100ms by default
    just for nothing
  • Loading branch information
lhotari authored Oct 26, 2020
1 parent c6560ee commit eea86a5
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
import org.apache.pulsar.common.naming.TopicName;

public class ReaderImpl<T> implements Reader<T> {

private static final BatchReceivePolicy DISABLED_BATCH_RECEIVE_POLICY = BatchReceivePolicy.builder()
.timeout(0, TimeUnit.MILLISECONDS)
.maxNumMessages(1)
.build();
private final ConsumerImpl<T> consumer;

public ReaderImpl(PulsarClientImpl client, ReaderConfigurationData<T> readerConfiguration,
Expand All @@ -50,6 +53,10 @@ public ReaderImpl(PulsarClientImpl client, ReaderConfigurationData<T> readerConf
consumerConfiguration.setReceiverQueueSize(readerConfiguration.getReceiverQueueSize());
consumerConfiguration.setReadCompacted(readerConfiguration.isReadCompacted());

// Reader doesn't need any batch receiving behaviours
// disable the batch receive timer for the ConsumerImpl instance wrapped by the ReaderImpl
consumerConfiguration.setBatchReceivePolicy(DISABLED_BATCH_RECEIVE_POLICY);

if (readerConfiguration.getReaderName() != null) {
consumerConfiguration.setConsumerName(readerConfiguration.getReaderName());
}
Expand Down

0 comments on commit eea86a5

Please sign in to comment.