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

Add server-side lookup throttling #181

Merged
merged 2 commits into from
Mar 6, 2017
Merged

Conversation

rdhabalia
Copy link
Contributor

Motivation

Sometimes, broker requires a way to throttle newly incoming traffic and requires to restrict number of incoming concurrent lookup requests.

Modifications

  • Add broker side throttling to serve max allowed concurrent lookup request
  • Update value of maxConcurrentLookupRequest dynamically at broker

Result

Broker can have capability to throttle newly incoming traffic by restricting number of concurrent lookup request.

@rdhabalia rdhabalia added the type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages label Jan 31, 2017
@rdhabalia rdhabalia added this to the 1.17 milestone Jan 31, 2017
@rdhabalia rdhabalia self-assigned this Jan 31, 2017
}
return null;
});
if (service.getLookupRequestSemaphore().tryAcquire()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid indenting the whole section, what about doing:

if (!service.getLookupRequestSemaphore().tryAcquire()) {
    /// deal with error
    return;
}

// continue normal

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, here I have replaced thenAccept/exceptionally with handle(data, ex) so, don't have to keep duplicate service.getLookupRequestSemaphore().release(). So, this change anyway changed entire section so, kept into if/else.

return null;
});
} else {
log.warn("[{}] Failed Partition-Metadata lookup due to too many lookup-requets {}", remoteAddress, topic);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log at debug level

private int getLookupRequestPermits() {
int pendingLookupRequest = pulsar.getConfiguration().getMaxConcurrentLookupRequest();
try {
Optional<Map<String, String>> data = dynamicConfigurationCache.get(LOOKUP_THROTTLING_PATH);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dynamic configuration of the parameter should go in separate PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that fine if we remove this configuration-update once other PR is created?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either that, or just use the value from config file as it is (like any other config parameter) and then we can open a separate issue to discuss the broader dynamic config approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we can read from config-file but part of this PR also requires to test updating semaphore at runtime and if config value gets changed then we are also updating lookupRequestSemaphore so, even with Dynamic-config-change we might need this listener logic and we have to provide a way to inject listener on config value change in dynamic-config-PR.
So, should we keep this PR open until we come up with the approach as anyway it should be part of 1.17 release.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that makes sense

@rdhabalia
Copy link
Contributor Author

@merlimat rebased this one with the #186 changes.

Copy link
Contributor

@merlimat merlimat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -81,6 +81,7 @@ enum ServerError {
TopicNotFound = 11; // Topic not found
SubscriptionNotFound = 12; // Subscription not found
ConsumerNotFound = 13; // Consumer not found
TooManyRequest = 14; // Error with too many simultaneously request
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing: this should be plural: TooManyRequests

@merlimat merlimat merged commit 3345d24 into apache:master Mar 6, 2017
@rdhabalia rdhabalia deleted the server_throttle branch June 21, 2017 18:54
sijie pushed a commit to sijie/pulsar that referenced this pull request Mar 4, 2018
hangc0276 pushed a commit to hangc0276/pulsar that referenced this pull request May 26, 2021
fix apache#181
This pull request fix the deadlock in kop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants