Spenserrrr commented on code in PR #59892:
URL: https://github.com/apache/spark/pull/59892#discussion_r4548194518


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -5857,7 +5857,10 @@ object SQLConf {
   val PYTHON_UDF_DETAILED_TIMING_ENABLED =
     buildConf("spark.sql.execution.pythonUDF.detailedTiming.enabled")
       .internal()
-      .doc("When true, collect detailed timing metrics for supported Python 
UDFs.")
+      .doc("When true, collect detailed timing metrics for supported Python 
UDFs. " +
+        "With spark.python.udf.pipelined.enabled, phase timings can overlap 
and their sum " +
+        "does not represent elapsed time. Exclude reports with nonzero " +
+        "pythonNumPipelinedTasks from additive phase breakdowns.")

Review Comment:
   Kept detailed timing off in pipeline mode. No locking or per-thread 
collector changes in this PR.



##########
python/pyspark/worker.py:
##########
@@ -201,6 +201,9 @@ def pipelined_process():
             Pipelined variant of process() that pre-fetches input batches in a 
background
             reader thread while the main thread computes the UDF and writes 
output.
             This allows input deserialization to overlap with UDF computation.
+            Detailed phase timings still measure these overlapping operations; 
their sum

Review Comment:
   Detailed timing is now disabled in pipeline mode for both handlers and 
serializers. The pipeline test checks the task marker and zero timing reports.



##########
python/pyspark/sql/tests/pandas/test_pandas_map.py:
##########
@@ -627,6 +627,71 @@ def tearDownClass(cls):
         time.tzset()
         ReusedSQLTestCase.tearDownClass()
 
+    def test_phase_metrics(self):
+        def rebatch(dfs):
+            frames = list(dfs)
+            time.sleep(0.01)
+            if frames:
+                combined = pd.concat(frames)
+                yield combined.iloc[:1]
+                yield combined.iloc[1:]
+
+        phase_names = (
+            "pythonDataReadTime",
+            "pythonInputPreparationTime",
+            "pythonUDFExecutionTime",
+            "pythonOutputPreparationTime",
+            "pythonDataWriteTime",
+        )
+        with self.sql_conf(
+            {
+                "spark.sql.execution.arrow.maxRecordsPerBatch": "2",
+                "spark.sql.adaptive.enabled": "false",
+                "spark.sql.execution.pythonUDF.detailedTiming.enabled": "true",
+            }
+        ):
+            for num_rows, legacy in ((5, False), (0, False), (5, True)):
+                with (
+                    self.subTest(num_rows=num_rows, legacy=legacy),
+                    self.sql_conf(
+                        {
+                            
"spark.sql.legacy.execution.pythonUDF.pandas.conversion.enabled": str(
+                                legacy
+                            ).lower()
+                        }
+                    ),
+                ):
+                    data = self.spark.createDataFrame(
+                        self.sc.parallelize([(i,) for i in range(num_rows)], 
1), "id long"
+                    )
+                    result = data.mapInPandas(rebatch, "id long")
+                    self.assertEqual(result.collect(), [Row(i) for i in 
range(num_rows)])
+                    metrics = 
result._jdf.queryExecution().executedPlan().metrics()
+                    
self.assertEqual(metrics.apply("pythonNumTimingReports").value(), 1)
+                    self.assertEqual(
+                        metrics.apply("pythonNumTimedBatches").value(), 
(num_rows + 1) // 2
+                    )
+                    phases = [metrics.apply(name).value() for name in 
phase_names]
+                    self.assertTrue(all(value >= 0 for value in phases))

Review Comment:
   Replaced the nonnegative check with an isZero() check for every phase, 
covering both nonempty and empty input. The test now fails if a phase never 
receives an update.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to