You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2021/03/13 19:37:23 UTC

[GitHub] [incubator-pinot] mcvsubbu commented on a change in pull request #6680: Instrument combine operators with total thread time

mcvsubbu commented on a change in pull request #6680:
URL: https://github.com/apache/incubator-pinot/pull/6680#discussion_r593790598



##########
File path: pinot-core/src/main/java/org/apache/pinot/core/operator/blocks/IntermediateResultsBlock.java
##########
@@ -69,6 +69,7 @@
   private boolean _numGroupsLimitReached;
   private int _numResizes;
   private long _resizeTimeMs;
+  private long _threadTime;

Review comment:
       suggest: `threadCpuTimeMicros` instead of `threadTime` (Hint: Always add the units in variable name)

##########
File path: pinot-core/src/main/java/org/apache/pinot/core/query/request/context/ThreadTimer.java
##########
@@ -0,0 +1,61 @@
+/**
+ * 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.pinot.core.query.request.context;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadMXBean;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class ThreadTimer {
+  private static final ThreadMXBean MX_BEAN = ManagementFactory.getThreadMXBean();
+  private static final boolean IS_THREAD_CPU_TIME_SUPPORTED = MX_BEAN.isThreadCpuTimeSupported();
+  private static final long NANOS_IN_MILLIS = 1;

Review comment:
       Make it MICROS_IN_MILLIS

##########
File path: pinot-core/src/main/java/org/apache/pinot/core/operator/combine/BaseCombineOperator.java
##########
@@ -53,15 +55,16 @@
   protected final long _endTimeMs;
 
   protected final int _numOperators;
-  protected int _numThreads;
   // Use a Phaser to ensure all the Futures are done (not scheduled, finished or interrupted) before the main thread
   // returns. We need to ensure this because the main thread holds the reference to the segments. If a segment is
   // deleted/refreshed, the segment will be released after the main thread returns, which would lead to undefined
   // behavior (even JVM crash) when processing queries against it.
   protected final Phaser _phaser = new Phaser(1);
-  protected Future[] _futures;
   // Use a _blockingQueue to store the per-segment result
   private final BlockingQueue<IntermediateResultsBlock> _blockingQueue;
+  private final AtomicLong totalWorkerTime = new AtomicLong(0);

Review comment:
       Suggest: `totalWorkerThreadCpuTimeMicros` or `totalThreadCpuMicros` or `execCpuTimeMicros` . Definitely include units

##########
File path: pinot-core/src/main/java/org/apache/pinot/core/operator/combine/BaseCombineOperator.java
##########
@@ -89,12 +92,28 @@ protected IntermediateResultsBlock getNextBlock() {
       _futures[i] = _executorService.submit(new TraceRunnable() {
         @Override
         public void runJob() {
+          ThreadTimer processThreadTimer = new ThreadTimer();

Review comment:
       Suggest `executionThreadTimer`

##########
File path: pinot-common/src/main/java/org/apache/pinot/common/utils/DataTable.java
##########
@@ -44,6 +44,7 @@
   String REQUEST_ID_METADATA_KEY = "requestId";
   String NUM_RESIZES_METADATA_KEY = "numResizes";
   String RESIZE_TIME_MS_METADATA_KEY = "resizeTimeMs";
+  String THREAD_TIME_MS = "threadTimeMs";

Review comment:
       Change it to micro seconds please

##########
File path: pinot-core/src/main/java/org/apache/pinot/core/query/request/context/ThreadTimer.java
##########
@@ -0,0 +1,61 @@
+/**
+ * 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.pinot.core.query.request.context;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadMXBean;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class ThreadTimer {
+  private static final ThreadMXBean MX_BEAN = ManagementFactory.getThreadMXBean();
+  private static final boolean IS_THREAD_CPU_TIME_SUPPORTED = MX_BEAN.isThreadCpuTimeSupported();
+  private static final long NANOS_IN_MILLIS = 1;
+  private static final Logger LOGGER = LoggerFactory.getLogger(ThreadTimer.class);
+
+  private long _startTimeMs = -1;

Review comment:
       Also introduce a static method that detects whether the underlying JVM supports getCurrentThreadCpuTme. If that is not supported (or if thread cpu time is not configured), then the overhead should be close to nothing.

##########
File path: pinot-core/src/main/java/org/apache/pinot/core/query/request/context/ThreadTimer.java
##########
@@ -0,0 +1,61 @@
+/**
+ * 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.pinot.core.query.request.context;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadMXBean;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class ThreadTimer {
+  private static final ThreadMXBean MX_BEAN = ManagementFactory.getThreadMXBean();
+  private static final boolean IS_THREAD_CPU_TIME_SUPPORTED = MX_BEAN.isThreadCpuTimeSupported();
+  private static final long NANOS_IN_MILLIS = 1;
+  private static final Logger LOGGER = LoggerFactory.getLogger(ThreadTimer.class);
+
+  private long _startTimeMs = -1;

Review comment:
       We need microseconds, not milliseconds

##########
File path: pinot-core/src/main/java/org/apache/pinot/core/query/request/context/ThreadTimer.java
##########
@@ -0,0 +1,61 @@
+/**
+ * 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.pinot.core.query.request.context;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadMXBean;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class ThreadTimer {

Review comment:
       Make this class configurable via instance configuration. If the instance configuration asks not to measure this, then do as appropriate in in the class below, with as minimal an overhead as possible. Even though we have measured the overhead to be near-zero in high throughput use cases, it is always useful to have a mechanism to turn it off in production when we first introduce it. It will also help us roll out the feature slowly in specific clusters or data centers
   
   Eventually, we will get rid of the config and make it standard.

##########
File path: pinot-core/src/main/java/org/apache/pinot/core/operator/streaming/StreamingSelectionOnlyCombineOperator.java
##########
@@ -47,6 +47,7 @@
 
 /**
  * Combine operator for selection only streaming queries.
+ * TODO: extends StreamingSelectionOnlyCombineOperator from BaseCombineOperator.

Review comment:
       ```suggestion
    * TODO: extend StreamingSelectionOnlyCombineOperator from BaseCombineOperator.
   ```

##########
File path: pinot-core/src/main/java/org/apache/pinot/core/query/request/context/ThreadTimer.java
##########
@@ -0,0 +1,61 @@
+/**
+ * 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.pinot.core.query.request.context;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadMXBean;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class ThreadTimer {

Review comment:
       +1

##########
File path: pinot-core/src/main/java/org/apache/pinot/core/operator/combine/BaseCombineOperator.java
##########
@@ -89,12 +92,28 @@ protected IntermediateResultsBlock getNextBlock() {
       _futures[i] = _executorService.submit(new TraceRunnable() {
         @Override
         public void runJob() {
+          ThreadTimer processThreadTimer = new ThreadTimer();
+          processThreadTimer.start();
+
           processSegments(threadIndex);
+
+          processThreadTimer.stop();
+          totalWorkerTime.addAndGet(processThreadTimer.getThreadTime());

Review comment:
       Maybe we can introduce another API `ThreadTimer.stopAndGet()`




----------------------------------------------------------------
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:
users@infra.apache.org



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