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

Allow to config pulsar client allocator out of memory policy #12200

Merged
merged 4 commits into from
Oct 20, 2021
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.bookkeeper.common.allocator.ByteBufAllocatorBuilder;
import org.apache.bookkeeper.common.allocator.LeakDetectionPolicy;
import org.apache.bookkeeper.common.allocator.OutOfMemoryPolicy;
import org.apache.bookkeeper.common.allocator.PoolingPolicy;

/**
Expand All @@ -39,6 +40,7 @@ public class PulsarByteBufAllocator {
public static final String PULSAR_ALLOCATOR_POOLED = "pulsar.allocator.pooled";
public static final String PULSAR_ALLOCATOR_EXIT_ON_OOM = "pulsar.allocator.exit_on_oom";
public static final String PULSAR_ALLOCATOR_LEAK_DETECTION = "pulsar.allocator.leak_detection";
public static final String PULSAR_ALLOCATOR_FALL_BACK_TO_HEAP = "pulsar.allocator.fall_back_to_heap";
shoothzj marked this conversation as resolved.
Show resolved Hide resolved

public static final ByteBufAllocator DEFAULT;

Expand All @@ -53,6 +55,7 @@ public static void registerOOMListener(Consumer<OutOfMemoryError> listener) {
static {
boolean isPooled = "true".equalsIgnoreCase(System.getProperty(PULSAR_ALLOCATOR_POOLED, "true"));
EXIT_ON_OOM = "true".equalsIgnoreCase(System.getProperty(PULSAR_ALLOCATOR_EXIT_ON_OOM, "false"));
boolean fallBackToHeap = "true".equalsIgnoreCase(System.getProperty(PULSAR_ALLOCATOR_FALL_BACK_TO_HEAP, "true"));

LeakDetectionPolicy leakDetectionPolicy = LeakDetectionPolicy
.valueOf(System.getProperty(PULSAR_ALLOCATOR_LEAK_DETECTION, "Disabled"));
Expand Down Expand Up @@ -85,6 +88,11 @@ public static void registerOOMListener(Consumer<OutOfMemoryError> listener) {
} else {
builder.poolingPolicy(PoolingPolicy.UnpooledHeap);
}
if (fallBackToHeap) {
builder.outOfMemoryPolicy(OutOfMemoryPolicy.FallbackToHeap);
} else {
builder.outOfMemoryPolicy(OutOfMemoryPolicy.ThrowException);
}

DEFAULT = builder.build();
}
Expand Down