clintropolis commented on a change in pull request #9407: query laning and load 
shedding
URL: https://github.com/apache/druid/pull/9407#discussion_r389161093
 
 

 ##########
 File path: 
server/src/test/java/org/apache/druid/server/scheduling/HiLoQueryLaningStrategyTest.java
 ##########
 @@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.server.scheduling;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import it.unimi.dsi.fastutil.objects.Object2IntMap;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.java.util.common.granularity.Granularities;
+import org.apache.druid.query.Druids;
+import org.apache.druid.query.QueryContexts;
+import org.apache.druid.query.QueryPlus;
+import org.apache.druid.query.aggregation.CountAggregatorFactory;
+import org.apache.druid.query.timeseries.TimeseriesQuery;
+import org.apache.druid.server.QueryLaningStrategy;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class HiLoQueryLaningStrategyTest
+{
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private Druids.TimeseriesQueryBuilder queryBuilder;
+  private HiLoQueryLaningStrategy strategy;
+
+  @Before
+  public void setup()
+  {
+    this.queryBuilder = Druids.newTimeseriesQueryBuilder()
+                              .dataSource("test")
+                              .intervals(ImmutableList.of(Intervals.ETERNITY))
+                              .granularity(Granularities.DAY)
+                              .aggregators(new 
CountAggregatorFactory("count"));
+
+    this.strategy = new HiLoQueryLaningStrategy(10);
+  }
+
+  @Test
+  public void testMaxLowThreadsRequired()
+  {
+    expectedException.expect(NullPointerException.class);
+    expectedException.expectMessage("maxLowThreads must be set");
+    QueryLaningStrategy strategy = new HiLoQueryLaningStrategy(null);
+  }
+
+  @Test
+  public void testLaneLimits()
+  {
+    Object2IntMap<String> laneConfig = strategy.getLaneLimits();
+    Assert.assertEquals(1, laneConfig.size());
+    Assert.assertTrue(laneConfig.containsKey(HiLoQueryLaningStrategy.LOW));
+    Assert.assertEquals(10, laneConfig.getInt(HiLoQueryLaningStrategy.LOW));
+  }
+
+  @Test
+  public void testLaningNoPriority()
+  {
+    TimeseriesQuery query = queryBuilder.build();
+    Assert.assertFalse(strategy.computeLane(QueryPlus.wrap(query), 
ImmutableSet.of()).isPresent());
+  }
+
+  @Test
+  public void testLaningZeroPriority()
+  {
+    TimeseriesQuery query = 
queryBuilder.context(ImmutableMap.of(QueryContexts.PRIORITY_KEY, 0)).build();
+    Assert.assertFalse(strategy.computeLane(QueryPlus.wrap(query), 
ImmutableSet.of()).isPresent());
+  }
+
+  @Test
+  public void testLaningInteractivePriority()
+  {
+    TimeseriesQuery query = 
queryBuilder.context(ImmutableMap.of(QueryContexts.PRIORITY_KEY, 100)).build();
+    Assert.assertFalse(strategy.computeLane(QueryPlus.wrap(query), 
ImmutableSet.of()).isPresent());
+  }
+
+  @Test
+  public void testLaningLowPriority()
+  {
+    TimeseriesQuery query = 
queryBuilder.context(ImmutableMap.of(QueryContexts.PRIORITY_KEY, -1)).build();
+    Assert.assertTrue(strategy.computeLane(QueryPlus.wrap(query), 
ImmutableSet.of()).isPresent());
+    Assert.assertEquals(
+        HiLoQueryLaningStrategy.LOW,
+        strategy.computeLane(QueryPlus.wrap(query), ImmutableSet.of()).get()
+    );
+  }
+}
 
 Review comment:
   I think there are a few reasons to put it on the query context. For one to 
propagate the value downstream to historical and realtime tasks so they can 
utilize that information in the future to also make load management decisions. 
   
   But also, I'm not sure that lane necessarily _has_ to be related to priority 
just because the current implementation I have provided is. It is really just a 
label used to enforce limits. 
   
   In my list of potential follow-up work, I wanted to support a manual laning 
strategy that only supports explicit use defined lanes on the context [both to 
make integration tests 
easier](https://github.com/clintropolis/druid/compare/query-laning-and-load-shedding...clintropolis:manual-query-laning)
 but also just to account for scenarios where an external application drives 
these decisions and still wishes to enforce limits on classes of queries. I 
also suggested a tier based laning strategy, which would not be related to 
priority, but rather the set of servers it is going to be querying.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to