Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cap the dispatcher batch size in bytes to fixed max #7097

Merged
merged 1 commit into from
May 29, 2020
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
3 changes: 3 additions & 0 deletions conf/broker.conf
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ dispatchThrottlingOnNonBacklogConsumerEnabled=true
# Max number of entries to read from bookkeeper. By default it is 100 entries.
dispatcherMaxReadBatchSize=100

# Max size in bytes of entries to read from bookkeeper. By default it is 5MB.
dispatcherMaxReadSizeBytes=5242880

# Min number of entries to read from bookkeeper. By default it is 1 entries.
# When there is an error occurred on reading entries from bookkeeper, the broker
# will backoff the batch size to this minimum number."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,14 @@ public class ServiceConfiguration implements PulsarConfiguration {
)
private int dispatcherMaxReadBatchSize = 100;

// <-- dispatcher read settings -->
@FieldContext(
dynamic = true,
category = CATEGORY_SERVER,
doc = "Max size in bytes of entries to read from bookkeeper. By default it is 5MB."
)
private int dispatcherMaxReadSizeBytes = 5 * 1024 * 1024;

@FieldContext(
dynamic = true,
category = CATEGORY_SERVER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ public void readMoreEntries() {
consumerList.size());
}
havePendingRead = true;
cursor.asyncReadEntriesOrWait(messagesToRead, this, ReadType.Normal);
cursor.asyncReadEntriesOrWait(messagesToRead, serviceConfig.getDispatcherMaxReadSizeBytes(), this,
ReadType.Normal);
} else {
log.debug("[{}] Cannot schedule next read until previous one is done", name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,11 @@ protected void readMoreEntries(Consumer consumer) {
log.debug("[{}-{}] Schedule read of {} messages", name, consumer, messagesToRead);
}
havePendingRead = true;

if (consumer.readCompacted()) {
topic.getCompactedTopic().asyncReadEntriesOrWait(cursor, messagesToRead, this, consumer);
} else {
cursor.asyncReadEntriesOrWait(messagesToRead, this, consumer);
cursor.asyncReadEntriesOrWait(messagesToRead, serviceConfig.getDispatcherMaxReadSizeBytes(), this, consumer);
}
} else {
if (log.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class PersistentReplicator extends AbstractReplicator implements Replicat
private Optional<DispatchRateLimiter> dispatchRateLimiter = Optional.empty();

private int readBatchSize;
private final int readMaxSizeBytes;

private final int producerQueueThreshold;

Expand Down Expand Up @@ -119,6 +120,7 @@ public PersistentReplicator(PersistentTopic topic, ManagedCursor cursor, String
readBatchSize = Math.min(
producerQueueSize,
topic.getBrokerService().pulsar().getConfiguration().getDispatcherMaxReadBatchSize());
readMaxSizeBytes = topic.getBrokerService().pulsar().getConfiguration().getDispatcherMaxReadSizeBytes();
producerQueueThreshold = (int) (producerQueueSize * 0.9);

this.initializeDispatchRateLimiterIfNeeded(Optional.empty());
Expand All @@ -138,6 +140,7 @@ public PersistentReplicator(PersistentTopic topic, String replicatorName, String
readBatchSize = Math.min(
producerQueueSize,
topic.getBrokerService().pulsar().getConfiguration().getDispatcherMaxReadBatchSize());
readMaxSizeBytes = topic.getBrokerService().pulsar().getConfiguration().getDispatcherMaxReadSizeBytes();
producerQueueThreshold = (int) (producerQueueSize * 0.9);

this.initializeDispatchRateLimiterIfNeeded(Optional.empty());
Expand Down Expand Up @@ -285,7 +288,7 @@ protected void readMoreEntries() {
log.debug("[{}][{} -> {}] Schedule read of {} messages", topicName, localCluster, remoteCluster,
messagesToRead);
}
cursor.asyncReadEntriesOrWait(messagesToRead, this, null);
cursor.asyncReadEntriesOrWait(messagesToRead, readMaxSizeBytes, this, null);
} else {
if (log.isDebugEnabled()) {
log.debug("[{}][{} -> {}] Not scheduling read due to pending read. Messages To Read {}", topicName,
Expand Down