You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by lh...@apache.org on 2025/02/25 11:08:40 UTC
(pulsar) branch master updated: [improve][ml] Use lock-free queue in InflightReadsLimiter since there's no concurrent access (#23962)
This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 38a41e0d291 [improve][ml] Use lock-free queue in InflightReadsLimiter since there's no concurrent access (#23962)
38a41e0d291 is described below
commit 38a41e0d29192d0e29cc172cccf6c187cf7cb542
Author: guan46 <48...@users.noreply.github.com>
AuthorDate: Tue Feb 25 19:08:33 2025 +0800
[improve][ml] Use lock-free queue in InflightReadsLimiter since there's no concurrent access (#23962)
---
.../mledger/impl/cache/InflightReadsLimiter.java | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/cache/InflightReadsLimiter.java b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/cache/InflightReadsLimiter.java
index 1f4d2c26797..1d5e0a3568f 100644
--- a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/cache/InflightReadsLimiter.java
+++ b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/cache/InflightReadsLimiter.java
@@ -22,6 +22,7 @@ import com.google.common.annotations.VisibleForTesting;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.metrics.ObservableLongCounter;
import io.prometheus.client.Gauge;
+import java.util.ArrayDeque;
import java.util.Optional;
import java.util.Queue;
import java.util.concurrent.ScheduledExecutorService;
@@ -31,7 +32,6 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.pulsar.opentelemetry.Constants;
import org.apache.pulsar.opentelemetry.OpenTelemetryAttributes.InflightReadLimiterUtilization;
import org.apache.pulsar.opentelemetry.annotations.PulsarDeprecatedMetric;
-import org.jctools.queues.SpscArrayQueue;
@Slf4j
public class InflightReadsLimiter implements AutoCloseable {
@@ -51,6 +51,7 @@ public class InflightReadsLimiter implements AutoCloseable {
public static final String INFLIGHT_READS_LIMITER_USAGE_METRIC_NAME =
"pulsar.broker.managed_ledger.inflight.read.usage";
private final ObservableLongCounter inflightReadsUsageCounter;
+ private final int maxReadsInFlightAcquireQueueSize;
@PulsarDeprecatedMetric(newMetricName = INFLIGHT_READS_LIMITER_USAGE_METRIC_NAME)
@Deprecated
@@ -82,9 +83,10 @@ public class InflightReadsLimiter implements AutoCloseable {
this.remainingBytes = maxReadsInFlightSize;
this.acquireTimeoutMillis = acquireTimeoutMillis;
this.timeOutExecutor = timeOutExecutor;
+ this.maxReadsInFlightAcquireQueueSize = maxReadsInFlightAcquireQueueSize;
if (maxReadsInFlightSize > 0) {
enabled = true;
- this.queuedHandles = new SpscArrayQueue<>(maxReadsInFlightAcquireQueueSize);
+ this.queuedHandles = new ArrayDeque<>();
} else {
enabled = false;
this.queuedHandles = null;
@@ -174,13 +176,14 @@ public class InflightReadsLimiter implements AutoCloseable {
updateMetrics();
return Optional.of(new Handle(maxReadsInFlightSize, handle.creationTime, true));
} else {
- if (queuedHandles.offer(new QueuedHandle(handle, callback))) {
- scheduleTimeOutCheck(acquireTimeoutMillis);
- return Optional.empty();
- } else {
+ if (queuedHandles.size() >= maxReadsInFlightAcquireQueueSize) {
log.warn("Failed to queue handle for acquiring permits: {}, creationTime: {}, remainingBytes:{}",
permits, handle.creationTime, remainingBytes);
return Optional.of(new Handle(0, handle.creationTime, false));
+ } else {
+ queuedHandles.offer(new QueuedHandle(handle, callback));
+ scheduleTimeOutCheck(acquireTimeoutMillis);
+ return Optional.empty();
}
}
}