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

[Issue #11351] Parallel Precise Publish Rate Limiting Fix #11372

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -63,6 +63,13 @@ public boolean isPublishRateExceeded() {
return false;
}

private void tryReleaseConnectionThrottle() {
lhotari marked this conversation as resolved.
Show resolved Hide resolved
if ((topicPublishRateLimiterOnMessage != null && topicPublishRateLimiterOnMessage.getAvailablePermits() <= 0)
|| (topicPublishRateLimiterOnByte != null && topicPublishRateLimiterOnByte.getAvailablePermits() <= 0)) {
return;
}
this.rateLimitFunction.apply();
}

@Override
public void update(Policies policies, String clusterName) {
Expand All @@ -79,10 +86,13 @@ public void update(PublishRate maxPublishRate) {
this.publishMaxByteRate = Math.max(maxPublishRate.publishThrottlingRateInByte, 0);
if (this.publishMaxMessageRate > 0) {
topicPublishRateLimiterOnMessage =
new RateLimiter(publishMaxMessageRate, 1, TimeUnit.SECONDS, rateLimitFunction);
new RateLimiter(publishMaxMessageRate, 1, TimeUnit.SECONDS,
this::tryReleaseConnectionThrottle);
}
if (this.publishMaxByteRate > 0) {
topicPublishRateLimiterOnByte = new RateLimiter(publishMaxByteRate, 1, TimeUnit.SECONDS);
topicPublishRateLimiterOnByte =
new RateLimiter(publishMaxByteRate, 1, TimeUnit.SECONDS,
this::tryReleaseConnectionThrottle);
}
} else {
this.publishMaxMessageRate = 0;
Expand Down
Expand Up @@ -59,7 +59,7 @@ public void update(PublishRate maxPublishRate) {
@Override
public boolean tryAcquire(int numbers, long bytes) {
// No-op
return false;
return true;
ronfarkash marked this conversation as resolved.
Show resolved Hide resolved
}

}
Expand Up @@ -54,8 +54,8 @@ public class RateLimiter implements AutoCloseable{
private TimeUnit timeUnit;
private final boolean externalExecutor;
private ScheduledFuture<?> renewTask;
private long permits;
private long acquiredPermits;
private volatile long permits;
private volatile long acquiredPermits;
private boolean isClosed;
// permitUpdate helps to update permit-rate at runtime
private Supplier<Long> permitUpdater;
Expand Down Expand Up @@ -203,7 +203,7 @@ public synchronized boolean tryAcquire(long acquirePermit) {
*
* @return returns 0 if permits is not available
*/
public synchronized long getAvailablePermits() {
public long getAvailablePermits() {
lhotari marked this conversation as resolved.
Show resolved Hide resolved
return Math.max(0, this.permits - this.acquiredPermits);
}

Expand Down