HyukjinKwon commented on a change in pull request #26953: 
[SPARK-30306][CORE][PYTHON] Instrument Python UDF execution time and metrics 
using Spark Metrics system
URL: https://github.com/apache/spark/pull/26953#discussion_r360286954
 
 

 ##########
 File path: core/src/main/scala/org/apache/spark/api/python/PythonMetrics.scala
 ##########
 @@ -0,0 +1,179 @@
+/*
+ * 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.spark.api.python
+
+import java.util.concurrent.atomic.AtomicLong
+
+private[spark] object PythonMetrics {
+
+  // Instrument with general metrics on serialization/deserialization 
JVM-to-Python
+  private val ToWorkerWriteTime = new AtomicLong(0L)
+  private val ToWorkerBatchCount = new AtomicLong(0L)
+  private val ToWorkerBytesWritten = new AtomicLong(0L)
+  private val FromWorkerReadTime = new AtomicLong(0L)
+  private val FromWorkerBatchCount = new AtomicLong(0L)
+
+  // Instrument Map Partitions operations
+  private val MapPartitionReadTime = new AtomicLong(0L)
+  private val MapPartitionReadBatchCount = new AtomicLong(0L)
+  private val MapPartitionBytesRead = new AtomicLong(0L)
+
+  // Instrument Python UDF
+  private val UDFReadTime = new AtomicLong(0L)
+  private val UDFReadBatchCount = new AtomicLong(0L)
+  private val UDFBytesRead = new AtomicLong(0L)
+
+  // Instrument Pandas_UDF
+  private val pandasUDFReadTime = new AtomicLong(0L)
+  private val pandasUDFReadBatchCount = new AtomicLong(0L)
+  private val pandasUDFWriteBatchCount = new AtomicLong(0L)
+  private val pandasUDFReadRowCount = new AtomicLong(0L)
+  private val pandasUDFWriteRowCount = new AtomicLong(0L)
+
+  def incToWorkerWriteTime(delta: Long): Unit = {
+    ToWorkerWriteTime.getAndAdd(delta)
+  }
+
+  def getToWorkerWriteTime: Long = {
+    ToWorkerWriteTime.get
+  }
+
+  def incToWorkerBytesWritten(delta: Long): Unit = {
+    ToWorkerBytesWritten.getAndAdd(delta)
+  }
+
+  def getToWorkerBytesWritten: Long = {
+    ToWorkerBytesWritten.get
+  }
+
+  def incToWorkerBatchCount(delta: Long): Unit = {
+    ToWorkerBatchCount.getAndAdd(delta)
+  }
+
+  def getToWorkerBatchCount: Long = {
+    ToWorkerBatchCount.get
+  }
+
+  def incFromWorkerReadTime(delta: Long): Unit = {
+    FromWorkerReadTime.getAndAdd(delta)
+  }
+
+  def getFromWorkerReadTime: Long = {
+    FromWorkerReadTime.get
+  }
+
+  def incFromWorkerBatchCount(delta: Long): Unit = {
+    FromWorkerBatchCount.getAndAdd(delta)
+  }
+
+  def getFromWorkerBatchCount: Long = {
+    FromWorkerBatchCount.get
+  }
+
+  // Map Partitions
+  def incMapPartitionReadTime(delta: Long): Unit = {
 
 Review comment:
   Can we just combine mapPartitions, pandas UDF and Python UDFs into single? 
e.g. python execution.

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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to