You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/12/29 02:39:56 UTC

[GitHub] [iotdb] JackieTien97 commented on a diff in pull request #8529: [IOTDB-5171] Add query metrics

JackieTien97 commented on code in PR #8529:
URL: https://github.com/apache/iotdb/pull/8529#discussion_r1058678891


##########
server/src/main/java/org/apache/iotdb/db/mpp/metric/QueryMetricsManager.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.iotdb.db.mpp.metric;
+
+import org.apache.iotdb.commons.service.metric.MetricService;
+import org.apache.iotdb.commons.service.metric.enums.Metric;
+import org.apache.iotdb.commons.service.metric.enums.Tag;
+import org.apache.iotdb.metrics.utils.MetricInfo;
+import org.apache.iotdb.metrics.utils.MetricLevel;
+
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.iotdb.db.mpp.metric.DataExchangeMetricSet.GET_DATA_BLOCK_NUM;
+
+public class QueryMetricsManager {
+
+  private final MetricService metricService = MetricService.getInstance();
+
+  public void recordPlanCost(String stage, long costTimeInNanos) {
+    metricService.timer(
+        costTimeInNanos,
+        TimeUnit.NANOSECONDS,
+        Metric.QUERY_PLAN_COST.toString(),
+        MetricLevel.IMPORTANT,
+        Tag.STAGE.toString(),
+        stage);
+  }
+
+  public void recordOperatorExecutionCost(String operatorType, long costTimeInNanos) {
+    metricService.timer(
+        costTimeInNanos,
+        TimeUnit.NANOSECONDS,
+        Metric.OPERATOR_EXECUTION_COST.toString(),
+        MetricLevel.IMPORTANT,
+        Tag.NAME.toString(),
+        operatorType);
+  }
+
+  public void recordOperatorExecutionCount(String operatorType, long count) {
+    metricService.count(
+        count,
+        Metric.OPERATOR_EXECUTION_COUNT.toString(),
+        MetricLevel.IMPORTANT,
+        Tag.NAME.toString(),
+        operatorType);
+  }
+
+  public void recordSeriesScanCost(String stage, long costTimeInNanos) {
+    MetricInfo metricInfo = SeriesScanCostMetricSet.metricInfoMap.get(stage);
+    metricService.timer(
+        costTimeInNanos,
+        TimeUnit.NANOSECONDS,
+        metricInfo.getName(),
+        MetricLevel.IMPORTANT,
+        metricInfo.getTagsInArray());
+  }
+
+  public void recordExecutionCost(String stage, long costTimeInNanos) {
+    MetricInfo metricInfo = QueryExecutionMetricSet.metricInfoMap.get(stage);
+    metricService.timer(
+        costTimeInNanos,
+        TimeUnit.NANOSECONDS,
+        metricInfo.getName(),
+        MetricLevel.IMPORTANT,
+        metricInfo.getTagsInArray());
+  }
+
+  public void recordQueryResourceNum(String type, int count) {
+    metricService.rate(

Review Comment:
   I think `histogram` will be better.



##########
server/src/main/java/org/apache/iotdb/db/mpp/execution/schedule/DriverScheduler.java:
##########
@@ -306,7 +319,10 @@ public void blockedToReady(DriverTask task) {
         if (task.getStatus() != DriverTaskStatus.BLOCKED) {
           return;
         }
+
         task.setStatus(DriverTaskStatus.READY);
+        QUERY_METRICS.recordTaskQueueTime(

Review Comment:
   You still need to update enter ready queue time here.
   
   `task.setLastEnterReadyQueueTime(System.nanoTime());`



##########
server/src/main/java/org/apache/iotdb/db/mpp/execution/exchange/SourceHandle.java:
##########
@@ -129,14 +136,21 @@ public SourceHandle(
   public synchronized TsBlock receive() {
     ByteBuffer tsBlock = getSerializedTsBlock();
     if (tsBlock != null) {
-      return serde.deserialize(tsBlock);
+      long startTime = System.nanoTime();
+      try {
+        return serde.deserialize(tsBlock);
+      } finally {
+        QUERY_METRICS.recordDataExchangeCost(
+            SOURCE_HANDLE_SERIALIZE_TSBLOCK_REMOTE, System.nanoTime() - startTime);

Review Comment:
   `SOURCE_HANDLE_DESERIALIZE_TSBLOCK_REMOTE`



##########
server/src/main/java/org/apache/iotdb/db/mpp/plan/scheduler/FragmentInstanceDispatcherImpl.java:
##########
@@ -98,6 +102,7 @@ private Future<FragInstanceDispatchResult> dispatchRead(List<FragmentInstance> i
     return executor.submit(
         () -> {
           for (FragmentInstance instance : instances) {
+            long startTime = System.nanoTime();

Review Comment:
   change it to sync style in your pr.



##########
server/src/main/java/org/apache/iotdb/db/engine/cache/TimeSeriesMetadataCacheMetrics.java:
##########
@@ -30,7 +30,7 @@
 
 public class TimeSeriesMetadataCacheMetrics implements IMetricSet {
 
-  private TimeSeriesMetadataCache timeSeriesMetadataCache;
+  private final TimeSeriesMetadataCache timeSeriesMetadataCache;

Review Comment:
   better move this class to mpp.metric package



##########
server/src/main/java/org/apache/iotdb/db/engine/cache/ChunkCacheMetrics.java:
##########
@@ -29,7 +29,8 @@
 import java.util.Objects;
 
 public class ChunkCacheMetrics implements IMetricSet {
-  private ChunkCache chunkCache;
+
+  private final ChunkCache chunkCache;

Review Comment:
   better move this class to mpp.metric package



##########
server/src/main/java/org/apache/iotdb/db/mpp/metric/QueryMetricsManager.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.iotdb.db.mpp.metric;
+
+import org.apache.iotdb.commons.service.metric.MetricService;
+import org.apache.iotdb.commons.service.metric.enums.Metric;
+import org.apache.iotdb.commons.service.metric.enums.Tag;
+import org.apache.iotdb.metrics.utils.MetricInfo;
+import org.apache.iotdb.metrics.utils.MetricLevel;
+
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.iotdb.db.mpp.metric.DataExchangeMetricSet.GET_DATA_BLOCK_NUM;
+
+public class QueryMetricsManager {
+
+  private final MetricService metricService = MetricService.getInstance();
+
+  public void recordPlanCost(String stage, long costTimeInNanos) {
+    metricService.timer(
+        costTimeInNanos,
+        TimeUnit.NANOSECONDS,
+        Metric.QUERY_PLAN_COST.toString(),
+        MetricLevel.IMPORTANT,
+        Tag.STAGE.toString(),
+        stage);
+  }
+
+  public void recordOperatorExecutionCost(String operatorType, long costTimeInNanos) {
+    metricService.timer(
+        costTimeInNanos,
+        TimeUnit.NANOSECONDS,
+        Metric.OPERATOR_EXECUTION_COST.toString(),
+        MetricLevel.IMPORTANT,
+        Tag.NAME.toString(),
+        operatorType);
+  }
+
+  public void recordOperatorExecutionCount(String operatorType, long count) {
+    metricService.count(
+        count,
+        Metric.OPERATOR_EXECUTION_COUNT.toString(),
+        MetricLevel.IMPORTANT,
+        Tag.NAME.toString(),
+        operatorType);
+  }
+
+  public void recordSeriesScanCost(String stage, long costTimeInNanos) {
+    MetricInfo metricInfo = SeriesScanCostMetricSet.metricInfoMap.get(stage);
+    metricService.timer(
+        costTimeInNanos,
+        TimeUnit.NANOSECONDS,
+        metricInfo.getName(),
+        MetricLevel.IMPORTANT,
+        metricInfo.getTagsInArray());
+  }
+
+  public void recordExecutionCost(String stage, long costTimeInNanos) {
+    MetricInfo metricInfo = QueryExecutionMetricSet.metricInfoMap.get(stage);
+    metricService.timer(
+        costTimeInNanos,
+        TimeUnit.NANOSECONDS,
+        metricInfo.getName(),
+        MetricLevel.IMPORTANT,
+        metricInfo.getTagsInArray());
+  }
+
+  public void recordQueryResourceNum(String type, int count) {
+    metricService.rate(
+        count, Metric.QUERY_RESOURCE.toString(), MetricLevel.IMPORTANT, Tag.TYPE.toString(), type);
+  }
+
+  public void recordDataExchangeCost(String stage, long costTimeInNanos) {
+    MetricInfo metricInfo = DataExchangeMetricSet.metricInfoMap.get(stage);
+    metricService.timer(
+        costTimeInNanos,
+        TimeUnit.NANOSECONDS,
+        metricInfo.getName(),
+        MetricLevel.IMPORTANT,
+        metricInfo.getTagsInArray());
+  }
+
+  public void recordDataBlockNum(int num) {
+    metricService.rate(

Review Comment:
   I think `histogram` will be better.



##########
server/src/main/java/org/apache/iotdb/db/mpp/metric/QueryMetricsManager.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.iotdb.db.mpp.metric;
+
+import org.apache.iotdb.commons.service.metric.MetricService;
+import org.apache.iotdb.commons.service.metric.enums.Metric;
+import org.apache.iotdb.commons.service.metric.enums.Tag;
+import org.apache.iotdb.metrics.utils.MetricInfo;
+import org.apache.iotdb.metrics.utils.MetricLevel;
+
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.iotdb.db.mpp.metric.DataExchangeMetricSet.GET_DATA_BLOCK_NUM;
+
+public class QueryMetricsManager {
+
+  private final MetricService metricService = MetricService.getInstance();
+
+  public void recordPlanCost(String stage, long costTimeInNanos) {
+    metricService.timer(
+        costTimeInNanos,
+        TimeUnit.NANOSECONDS,
+        Metric.QUERY_PLAN_COST.toString(),
+        MetricLevel.IMPORTANT,
+        Tag.STAGE.toString(),
+        stage);
+  }
+
+  public void recordOperatorExecutionCost(String operatorType, long costTimeInNanos) {
+    metricService.timer(
+        costTimeInNanos,
+        TimeUnit.NANOSECONDS,
+        Metric.OPERATOR_EXECUTION_COST.toString(),
+        MetricLevel.IMPORTANT,
+        Tag.NAME.toString(),
+        operatorType);
+  }
+
+  public void recordOperatorExecutionCount(String operatorType, long count) {
+    metricService.count(
+        count,
+        Metric.OPERATOR_EXECUTION_COUNT.toString(),

Review Comment:
   It seems that you didn't create this metric in `QueryExecutionMetricSet.bindTo`



##########
server/src/main/java/org/apache/iotdb/db/mpp/metric/DataExchangeMetricSet.java:
##########
@@ -0,0 +1,195 @@
+/*
+ * 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.iotdb.db.mpp.metric;
+
+import org.apache.iotdb.commons.service.metric.enums.Metric;
+import org.apache.iotdb.commons.service.metric.enums.Tag;
+import org.apache.iotdb.metrics.AbstractMetricService;
+import org.apache.iotdb.metrics.metricsets.IMetricSet;
+import org.apache.iotdb.metrics.utils.MetricInfo;
+import org.apache.iotdb.metrics.utils.MetricLevel;
+import org.apache.iotdb.metrics.utils.MetricType;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class DataExchangeMetricSet implements IMetricSet {
+
+  private static final String metric = Metric.DATA_EXCHANGE_COST.toString();
+
+  public static final Map<String, MetricInfo> metricInfoMap = new HashMap<>();
+
+  public static final String SOURCE_HANDLE_GET_TSBLOCK_LOCAL = "source_handle_get_tsblock_local";
+  public static final String SOURCE_HANDLE_GET_TSBLOCK_REMOTE = "source_handle_get_tsblock_remote";
+  public static final String SOURCE_HANDLE_SERIALIZE_TSBLOCK_LOCAL =
+      "source_handle_serialize_tsblock_local";
+  public static final String SOURCE_HANDLE_SERIALIZE_TSBLOCK_REMOTE =

Review Comment:
   ```suggestion
     public static final String SOURCE_HANDLE_DESERIALIZE_TSBLOCK_REMOTE =
   ```



##########
server/src/main/java/org/apache/iotdb/db/mpp/metric/QueryMetricsManager.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.iotdb.db.mpp.metric;
+
+import org.apache.iotdb.commons.service.metric.MetricService;
+import org.apache.iotdb.commons.service.metric.enums.Metric;
+import org.apache.iotdb.commons.service.metric.enums.Tag;
+import org.apache.iotdb.metrics.utils.MetricInfo;
+import org.apache.iotdb.metrics.utils.MetricLevel;
+
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.iotdb.db.mpp.metric.DataExchangeMetricSet.GET_DATA_BLOCK_NUM;
+
+public class QueryMetricsManager {
+
+  private final MetricService metricService = MetricService.getInstance();
+
+  public void recordPlanCost(String stage, long costTimeInNanos) {
+    metricService.timer(
+        costTimeInNanos,
+        TimeUnit.NANOSECONDS,
+        Metric.QUERY_PLAN_COST.toString(),
+        MetricLevel.IMPORTANT,
+        Tag.STAGE.toString(),
+        stage);
+  }
+
+  public void recordOperatorExecutionCost(String operatorType, long costTimeInNanos) {
+    metricService.timer(
+        costTimeInNanos,
+        TimeUnit.NANOSECONDS,
+        Metric.OPERATOR_EXECUTION_COST.toString(),

Review Comment:
   It seems that you didn't create this metric in `QueryExecutionMetricSet.bindTo`



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org