You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by sa...@apache.org on 2021/03/18 05:24:32 UTC

[druid] branch master updated: Improve performance of queries against SYSTEM.SEGMENT table. (#11008)

This is an automated email from the ASF dual-hosted git repository.

samarth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git


The following commit(s) were added to refs/heads/master by this push:
     new 83fcab1  Improve performance of queries against SYSTEM.SEGMENT table. (#11008)
83fcab1 is described below

commit 83fcab1d0f81081b5a307042ec1bdcbfa3f7d9cf
Author: Samarth Jain <sa...@apache.org>
AuthorDate: Wed Mar 17 22:24:02 2021 -0700

    Improve performance of queries against SYSTEM.SEGMENT table. (#11008)
    
    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.
---
 .../java/org/apache/druid/server/security/AuthorizationUtils.java    | 4 ++++
 .../main/java/org/apache/druid/sql/calcite/schema/DruidSchema.java   | 5 +++--
 .../main/java/org/apache/druid/sql/calcite/schema/SystemSchema.java  | 4 ++--
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/server/src/main/java/org/apache/druid/server/security/AuthorizationUtils.java b/server/src/main/java/org/apache/druid/server/security/AuthorizationUtils.java
index 64c6330..7017ac7 100644
--- a/server/src/main/java/org/apache/druid/server/security/AuthorizationUtils.java
+++ b/server/src/main/java/org/apache/druid/server/security/AuthorizationUtils.java
@@ -263,6 +263,10 @@ public class AuthorizationUtils
       throw new ISE("No authorizer found with name: [%s].", authenticationResult.getAuthorizerName());
     }
 
+    if (authorizer instanceof AllowAllAuthorizer) {
+      return resources;
+    }
+
     final Map<ResourceAction, Access> resultCache = new HashMap<>();
     final Iterable<ResType> filteredResources = Iterables.filter(
         resources,
diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/schema/DruidSchema.java b/sql/src/main/java/org/apache/druid/sql/calcite/schema/DruidSchema.java
index 20138a4..30a1576 100644
--- a/sql/src/main/java/org/apache/druid/sql/calcite/schema/DruidSchema.java
+++ b/sql/src/main/java/org/apache/druid/sql/calcite/schema/DruidSchema.java
@@ -702,13 +702,14 @@ public class DruidSchema extends AbstractSchema
 
   Map<SegmentId, AvailableSegmentMetadata> getSegmentMetadataSnapshot()
   {
-    final Map<SegmentId, AvailableSegmentMetadata> segmentMetadata = new HashMap<>();
     synchronized (lock) {
+      final Map<SegmentId, AvailableSegmentMetadata> segmentMetadata = Maps.newHashMapWithExpectedSize(
+          segmentMetadataInfo.values().stream().mapToInt(v -> v.size()).sum());
       for (TreeMap<SegmentId, AvailableSegmentMetadata> val : segmentMetadataInfo.values()) {
         segmentMetadata.putAll(val);
       }
+      return segmentMetadata;
     }
-    return segmentMetadata;
   }
 
   int getTotalSegments()
diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/schema/SystemSchema.java b/sql/src/main/java/org/apache/druid/sql/calcite/schema/SystemSchema.java
index 40352eb..0562e33 100644
--- a/sql/src/main/java/org/apache/druid/sql/calcite/schema/SystemSchema.java
+++ b/sql/src/main/java/org/apache/druid/sql/calcite/schema/SystemSchema.java
@@ -29,6 +29,7 @@ import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
 import com.google.common.net.HostAndPort;
 import com.google.common.util.concurrent.Futures;
 import com.google.inject.Inject;
@@ -90,7 +91,6 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -287,7 +287,7 @@ public class SystemSchema extends AbstractSchema
       // Coordinator.
       final Iterator<SegmentWithOvershadowedStatus> metadataStoreSegments = metadataView.getPublishedSegments();
 
-      final Set<SegmentId> segmentsAlreadySeen = new HashSet<>();
+      final Set<SegmentId> segmentsAlreadySeen = Sets.newHashSetWithExpectedSize(druidSchema.getTotalSegments());
 
       final FluentIterable<Object[]> publishedSegments = FluentIterable
           .from(() -> getAuthorizedPublishedSegments(metadataStoreSegments, root))


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org