You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/10/25 01:50:00 UTC

[GitHub] [spark] ConeyLiu commented on a change in pull request #26239: [SPARK-29582][PYSPARK] Unify the behavior of pyspark.TaskContext with spark core

ConeyLiu commented on a change in pull request #26239: [SPARK-29582][PYSPARK] Unify the behavior of pyspark.TaskContext with spark core
URL: https://github.com/apache/spark/pull/26239#discussion_r338857363
 
 

 ##########
 File path: python/pyspark/tests/test_taskcontext.py
 ##########
 @@ -181,6 +224,40 @@ def context_barrier(x):
         for pid in pids:
             self.assertTrue(pid in worker_pids)
 
+    def test_task_context_correct_with_python_worker_reuse(self):
+        """Verify the task context correct when reused python worker"""
+        # start a normal job first to start all workers and get all worker pids
+        worker_pids = self.sc.parallelize(range(2), 2).map(lambda x: os.getpid()).collect()
+        # the worker will reuse in this barrier job
+        rdd = self.sc.parallelize(range(10), 2)
+
+        def context(iterator):
+            tp = TaskContext.get().partitionId()
+            try:
+                bp = BarrierTaskContext.get().partitionId()
+            except RuntimeError:
+                bp = -1
+
+            yield (tp, bp, os.getpid())
+
+        def verify(result, task_context_target, barrier_context_target):
+            tps = list(map(lambda x: x[0], result))
+            bps = list(map(lambda x: x[1], result))
+            pids = list(map(lambda x: x[2], result))
+            self.assertTrue(tps == task_context_target)
+            self.assertTrue(bps == barrier_context_target)
+            for pid in pids:
+                self.assertTrue(pid in worker_pids)
+        # normal stage after normal stage
+        normal_result = rdd.mapPartitions(context).collect()
+        verify(normal_result, [0, 1], [-1, -1])
+        # barrier stage after normal stage
+        barrier_result = rdd.barrier().mapPartitions(context).collect()
 
 Review comment:
   I have passed tests in python3.6. However, it failed in python2.7. It seems that the python workers aren't reused even the config is set in python2.7.
   I tested here with:
   ```python
   normal_result = rdd.mapPartitions(lambda x: x).collect()
   verify(normal_result, [0, 1], [-1, -1])   # it passed
   
   normal_result = rdd.mapPartitions(lambda x: x).collect()
   normal_result = rdd.mapPartitions(lambda x: x).collect()
   normal_result = rdd.mapPartitions(lambda x: x).collect()
   verify(normal_result, [0, 1], [-1, -1])   # it failed with pids have changed
   ``` 
   
   Hi @srowen, would you know some background about this? Thanks a lot.

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


With regards,
Apache Git Services

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