Skip to content

Commit c9b8e35

Browse files
committed
nit: comments and logs from internal feedback
1 parent 5f8472b commit c9b8e35

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

core/src/main/java/com/datastax/oss/driver/internal/core/session/throttling/ConcurrencyLimitingRequestThrottler.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public class ConcurrencyLimitingRequestThrottler implements RequestThrottler {
6161
private final int maxConcurrentRequests;
6262
private final int maxQueueSize;
6363
private final AtomicInteger concurrentRequests = new AtomicInteger(0);
64+
// CLQ is not O(1) for size(), as it forces a full iteration of the queue. So, we track
65+
// the size of the queue explicitly.
6466
private final Deque<Throttled> queue = new ConcurrentLinkedDeque<>();
6567
private final AtomicInteger queueSize = new AtomicInteger(0);
6668
private volatile boolean closed = false;
@@ -93,13 +95,14 @@ public void register(@NonNull Throttled request) {
9395

9496
// If no backlog exists AND we get capacity, we can execute immediately
9597
if (queueSize.get() == 0) {
98+
// Take a claim first, and then check if we are OK to proceed
9699
int newConcurrent = concurrentRequests.incrementAndGet();
97100
if (newConcurrent <= maxConcurrentRequests) {
98101
LOG.trace("[{}] Starting newly registered request", logPrefix);
99102
request.onThrottleReady(false);
100103
return;
101104
} else {
102-
// We exceeded the limit, decrement the count and fall through to the queueing logic
105+
// We exceeded the limit, decrement the count and fall through to the queuing logic
103106
concurrentRequests.decrementAndGet();
104107
}
105108
}
@@ -121,6 +124,7 @@ public void register(@NonNull Throttled request) {
121124
}
122125
}
123126
} else {
127+
LOG.trace("[{}] Rejecting request because of full queue", logPrefix);
124128
queueSize.decrementAndGet();
125129
fail(
126130
request,

0 commit comments

Comments
 (0)