Skip to content

Commit

Permalink
Optimize memory usage: support to shrink for pendingAcks map (#14515)
Browse files Browse the repository at this point in the history
(cherry picked from commit e747b8f)
  • Loading branch information
lordcheng10 authored and codelipenghui committed Apr 28, 2022
1 parent 241320f commit 2cbf9f4
Show file tree
Hide file tree
Showing 4 changed files with 1,116 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,14 @@ public class ServiceConfiguration implements PulsarConfiguration {
)
private boolean isAllowAutoUpdateSchemaEnabled = true;

@FieldContext(
category = CATEGORY_SERVER,
doc = "Whether to enable the automatic shrink of pendingAcks map, "
+ "the default is false, which means it is not enabled. "
+ "When there are a large number of share or key share consumers in the cluster, "
+ "it can be enabled to reduce the memory consumption caused by pendingAcks.")
private boolean autoShrinkForConsumerPendingAcksMap = false;

@FieldContext(
category = CATEGORY_SERVER,
dynamic = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
import org.apache.bookkeeper.mledger.Entry;
import org.apache.bookkeeper.mledger.Position;
import org.apache.bookkeeper.mledger.impl.PositionImpl;
import org.apache.bookkeeper.util.collections.ConcurrentLongLongPairHashMap;
import org.apache.bookkeeper.util.collections.ConcurrentLongLongPairHashMap.LongPair;
import org.apache.commons.lang3.mutable.MutableInt;
import org.apache.commons.lang3.tuple.MutablePair;
import org.apache.pulsar.broker.service.persistent.PersistentSubscription;
Expand All @@ -58,6 +56,8 @@
import org.apache.pulsar.common.util.DateFormatter;
import org.apache.pulsar.common.util.FutureUtil;
import org.apache.pulsar.common.util.collections.BitSetRecyclable;
import org.apache.pulsar.common.util.collections.ConcurrentLongLongPairHashMap;
import org.apache.pulsar.common.util.collections.ConcurrentLongLongPairHashMap.LongPair;
import org.apache.pulsar.transaction.common.exception.TransactionConflictException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -179,7 +179,12 @@ public Consumer(Subscription subscription, SubType subType, String topicName, lo
stats.metadata = this.metadata;

if (Subscription.isIndividualAckMode(subType)) {
this.pendingAcks = new ConcurrentLongLongPairHashMap(256, 1);
this.pendingAcks = ConcurrentLongLongPairHashMap.newBuilder()
.autoShrink(subscription.getTopic().getBrokerService()
.getPulsar().getConfiguration().isAutoShrinkForConsumerPendingAcksMap())
.expectedItems(256)
.concurrencyLevel(1)
.build();
} else {
// We don't need to keep track of pending acks if the subscription is not shared
this.pendingAcks = null;
Expand Down
Loading

0 comments on commit 2cbf9f4

Please sign in to comment.