为什么pyspark脚本在我的个人计算机上而不在我的工作计算机上运行?

时间:2019-04-19 04:25:11

标签: windows ubuntu memory-management pyspark

我正在尝试运行一个简单的脚本,该脚本在我的个人计算机上工作得很好,但在我的工作计算机上却不能。 sepcs非常相似(实际上,我认为我的工作计算机更好)。这是一个独立的实现。

conf = SparkConf().setAll([('spark.executor.memory', '5g'), ('spark.executor.cores', '2'), ('spark.cores.max', '2'), ('spark.driver.memory','10g'), ('spark.driver.maxResultSize', '5g')]).setAppName('test').setMaster('local[4]')
sc = SparkContext(conf=conf)
sqlContext = SQLContext(sc)
df = sqlContext.read.parquet(path)
distance_udf = F.udf(lambda lat1, lon1, lat2, lon2: haversine((lat1, lon1), (lat2, lon2)))
bb_df = df.select('idfa',
                   distance_udf(df.latitude, df.longitude, F.lit(lat), F.lit(lon)).alias('distance'))         

当我做bb_df.show()时,出现以下错误:

Traceback (most recent call last):
  File "C:\Users\admin\Desktop\Sidd\SG\Adcity x MW\park it\revision - pyspark.py", line 67, in <module>
    bb_df.show()
  File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\site-packages\pyspark\sql\dataframe.py", line 378, in show
    print(self._jdf.showString(n, 20, vertical))
  File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\site-packages\py4j\java_gateway.py", line 1257, in __call__
    answer, self.gateway_client, self.target_id, self.name)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\site-packages\pyspark\sql\utils.py", line 63, in deco
    return f(*a, **kw)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\site-packages\py4j\protocol.py", line 328, in get_return_value
    format(target_id, ".", name), value)
py4j.protocol.Py4JJavaError: An error occurred while calling o124.showString.
: org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 2.0 failed 1 times, most recent failure: Lost task 0.0 in stage 2.0 (TID 2, localhost, executor driver): org.apache.spark.SparkException: Python worker failed to connect back.

    at org.apache.spark.api.python.PythonWorkerFactory.createSimpleWorker(PythonWorkerFactory.scala:170)

    at org.apache.spark.api.python.PythonWorkerFactory.create(PythonWorkerFactory.scala:97)

    at org.apache.spark.SparkEnv.createPythonWorker(SparkEnv.scala:117)

    at org.apache.spark.api.python.BasePythonRunner.compute(PythonRunner.scala:108)

    at org.apache.spark.sql.execution.python.BatchEvalPythonExec.evaluate(BatchEvalPythonExec.scala:77)

    at org.apache.spark.sql.execution.python.EvalPythonExec$$anonfun$doExecute$1.apply(EvalPythonExec.scala:127)

    at org.apache.spark.sql.execution.python.EvalPythonExec$$anonfun$doExecute$1.apply(EvalPythonExec.scala:89)

    at org.apache.spark.rdd.RDD$$anonfun$mapPartitions$1$$anonfun$apply$23.apply(RDD.scala:801)

    at org.apache.spark.rdd.RDD$$anonfun$mapPartitions$1$$anonfun$apply$23.apply(RDD.scala:801)

    at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:52)

    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:324)

    at org.apache.spark.rdd.RDD.iterator(RDD.scala:288)

    at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:52)

    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:324)

    at org.apache.spark.rdd.RDD.iterator(RDD.scala:288)

    at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:52)

    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:324)

    at org.apache.spark.rdd.RDD.iterator(RDD.scala:288)

    at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:52)

    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:324)

    at org.apache.spark.rdd.RDD.iterator(RDD.scala:288)

    at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:90)

    at org.apache.spark.scheduler.Task.run(Task.scala:121)

    at org.apache.spark.executor.Executor$TaskRunner$$anonfun$10.apply(Executor.scala:402)

    at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1360)

    at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:408)

    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

    at java.lang.Thread.run(Thread.java:748)

Caused by: java.net.SocketTimeoutException: Accept timed out

    at java.net.DualStackPlainSocketImpl.waitForNewConnection(Native Method)

    at java.net.DualStackPlainSocketImpl.socketAccept(DualStackPlainSocketImpl.java:135)

    at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409)

    at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:199)

    at java.net.ServerSocket.implAccept(ServerSocket.java:545)

    at java.net.ServerSocket.accept(ServerSocket.java:513)

    at org.apache.spark.api.python.PythonWorkerFactory.createSimpleWorker(PythonWorkerFactory.scala:164)

    ... 28 more


Driver stacktrace:

    at org.apache.spark.scheduler.DAGScheduler.org$apache$spark$scheduler$DAGScheduler$$failJobAndIndependentStages(DAGScheduler.scala:1887)

    at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1875)

    at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1874)

    at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)

    at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)

    at org.apache.spark.scheduler.DAGScheduler.abortStage(DAGScheduler.scala:1874)

    at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:926)

    at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:926)

    at scala.Option.foreach(Option.scala:257)

    at org.apache.spark.scheduler.DAGScheduler.handleTaskSetFailed(DAGScheduler.scala:926)

    at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.doOnReceive(DAGScheduler.scala:2108)

    at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:2057)

    at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:2046)

    at org.apache.spark.util.EventLoop$$anon$1.run(EventLoop.scala:49)

    at org.apache.spark.scheduler.DAGScheduler.runJob(DAGScheduler.scala:737)

    at org.apache.spark.SparkContext.runJob(SparkContext.scala:2061)

    at org.apache.spark.SparkContext.runJob(SparkContext.scala:2082)

    at org.apache.spark.SparkContext.runJob(SparkContext.scala:2101)

    at org.apache.spark.sql.execution.SparkPlan.executeTake(SparkPlan.scala:365)

    at org.apache.spark.sql.execution.CollectLimitExec.executeCollect(limit.scala:38)

    at org.apache.spark.sql.Dataset.org$apache$spark$sql$Dataset$$collectFromPlan(Dataset.scala:3384)

    at org.apache.spark.sql.Dataset$$anonfun$head$1.apply(Dataset.scala:2545)

    at org.apache.spark.sql.Dataset$$anonfun$head$1.apply(Dataset.scala:2545)

    at org.apache.spark.sql.Dataset$$anonfun$53.apply(Dataset.scala:3365)

    at org.apache.spark.sql.execution.SQLExecution$$anonfun$withNewExecutionId$1.apply(SQLExecution.scala:78)

    at org.apache.spark.sql.execution.SQLExecution$.withSQLConfPropagated(SQLExecution.scala:125)

    at org.apache.spark.sql.execution.SQLExecution$.withNewExecutionId(SQLExecution.scala:73)

    at org.apache.spark.sql.Dataset.withAction(Dataset.scala:3364)

    at org.apache.spark.sql.Dataset.head(Dataset.scala:2545)

    at org.apache.spark.sql.Dataset.take(Dataset.scala:2759)

    at org.apache.spark.sql.Dataset.getRows(Dataset.scala:255)

    at org.apache.spark.sql.Dataset.showString(Dataset.scala:292)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

    at java.lang.reflect.Method.invoke(Method.java:498)

    at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)

    at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)

    at py4j.Gateway.invoke(Gateway.java:282)

    at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)

    at py4j.commands.CallCommand.execute(CallCommand.java:79)

    at py4j.GatewayConnection.run(GatewayConnection.java:238)

    at java.lang.Thread.run(Thread.java:748)

Caused by: org.apache.spark.SparkException: Python worker failed to connect back.

    at org.apache.spark.api.python.PythonWorkerFactory.createSimpleWorker(PythonWorkerFactory.scala:170)

    at org.apache.spark.api.python.PythonWorkerFactory.create(PythonWorkerFactory.scala:97)

    at org.apache.spark.SparkEnv.createPythonWorker(SparkEnv.scala:117)

    at org.apache.spark.api.python.BasePythonRunner.compute(PythonRunner.scala:108)

    at org.apache.spark.sql.execution.python.BatchEvalPythonExec.evaluate(BatchEvalPythonExec.scala:77)

    at org.apache.spark.sql.execution.python.EvalPythonExec$$anonfun$doExecute$1.apply(EvalPythonExec.scala:127)

    at org.apache.spark.sql.execution.python.EvalPythonExec$$anonfun$doExecute$1.apply(EvalPythonExec.scala:89)

    at org.apache.spark.rdd.RDD$$anonfun$mapPartitions$1$$anonfun$apply$23.apply(RDD.scala:801)

    at org.apache.spark.rdd.RDD$$anonfun$mapPartitions$1$$anonfun$apply$23.apply(RDD.scala:801)

    at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:52)

    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:324)

    at org.apache.spark.rdd.RDD.iterator(RDD.scala:288)

    at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:52)

    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:324)

    at org.apache.spark.rdd.RDD.iterator(RDD.scala:288)

    at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:52)

    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:324)

    at org.apache.spark.rdd.RDD.iterator(RDD.scala:288)

    at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:52)

    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:324)

    at org.apache.spark.rdd.RDD.iterator(RDD.scala:288)

    at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:90)

    at org.apache.spark.scheduler.Task.run(Task.scala:121)

    at org.apache.spark.executor.Executor$TaskRunner$$anonfun$10.apply(Executor.scala:402)

    at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1360)

    at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:408)

    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

    ... 1 more

Caused by: java.net.SocketTimeoutException: Accept timed out

    at java.net.DualStackPlainSocketImpl.waitForNewConnection(Native Method)

    at java.net.DualStackPlainSocketImpl.socketAccept(DualStackPlainSocketImpl.java:135)

    at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409)

    at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:199)

    at java.net.ServerSocket.implAccept(ServerSocket.java:545)

    at java.net.ServerSocket.accept(ServerSocket.java:513)

    at org.apache.spark.api.python.PythonWorkerFactory.createSimpleWorker(PythonWorkerFactory.scala:164)

    ... 28 more

我的个人计算机上的相同代码有效。我检查了空值,相同的文件类型,相同的文件。 我也尝试过SQLContext.sql,但也收到错误消息。

我应该切换到Ubuntu,因为它是PySpark的推荐系统?但是我仍然不知道为什么如果我可以在较旧的(游戏)笔记本电脑上运行,该错误为什么会首先出现。

这是我尝试运行的非常简单的脚本。在切换到Ubuntu之前,谁能建议我可以做的任何优化?(.toPandas()不是一个选择)

非常感谢。

0 个答案:

没有答案