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

Improve performance of queries against SYSTEM.SEGMENT table. #11008

Merged
merged 1 commit into from
Mar 18, 2021

Conversation

samarthjain
Copy link
Contributor

Fixes #11007 .

After hooking up Yourkit against the broker instance running the queries mentioned in the above issue, it turns out that a lot of time is being spent in resizing HashMap and HashSet that have been created with the default constructor. Also, a lot of CPU cycles are wasted unnecessarily looping through and authorizing resources even though the authorizer configured is AllowAllAuthorizer.

After making these changes, on my test cluster, I see that the query times went down from ~12seconds to ~7seconds.

This PR has:

  • been self-reviewed.
  • [X ] been tested in a test Druid cluster.

synchronized (lock) {
final Map<SegmentId, AvailableSegmentMetadata> segmentMetadata = Maps.newHashMapWithExpectedSize(
segmentMetadataInfo.values().size());
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be segmentMetadataInfo.values().stream().mapToInt(v -> v.size()).sum() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing that out. Fixed.

Copy link
Contributor

@abhishekagarwal87 abhishekagarwal87 left a comment

Choose a reason for hiding this comment

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

LGTM. 👍

@jihoonson
Copy link
Contributor

+1 after CI

Size HashMap and HashSet appropriately. Perf analysis of the queries
revealed that over 25% of the query time was spent in resizing HashMap and HashSet
collections. Also, prevent the need to examine and authorize all resources when
AllowAllAuthorizer is the configured authorizer.
@samarthjain samarthjain merged commit 83fcab1 into apache:master Mar 18, 2021
@samarthjain samarthjain deleted the console_perf branch March 18, 2021 05:24
@@ -263,6 +263,10 @@ public static Access authorizeAllResourceActions(
throw new ISE("No authorizer found with name: [%s].", authenticationResult.getAuthorizerName());
}

if (authorizer instanceof AllowAllAuthorizer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

earlier this code will filter a resource if resourceActionGenerator.apply(resource) returns null but now it won't. does that difference matter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, looks like this isn't the right thing to do.
Also, the following loop needs to be executed because there could be duplicates in Iterable<ResourceAction. Will file an issue and a PR to revert this change.

Copy link
Contributor

Choose a reason for hiding this comment

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

do you intend to get rid of the duplicates or keep them? From the description in #11012, it seems we want to de-dup the entries though that wasn't happening earlier.

samarthjain added a commit to samarthjain/druid that referenced this pull request Mar 18, 2021
samarthjain added a commit to samarthjain/druid that referenced this pull request Mar 18, 2021
suneet-s pushed a commit that referenced this pull request Mar 20, 2021
* Fix regression introduced by #11008

* Add back and tweak the check to not inspect resources for authorization when AllowAllAuthorizer is configured.
Add a unit test to validate that the change doesn't introduce new behavior.
@clintropolis clintropolis added this to the 0.22.0 milestone Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve performance of queries against SYSTEM.SEGMENT tables
4 participants