Apache Spark:大型数据集的pyspark崩溃

时间:2014-11-16 06:40:03

标签: apache-spark

我是Spark的新手。我的输入文件包含训练数据4000x1800。当我尝试训练这些数据(写成python)时出现以下错误:

  1. 14/11/15 22:39:13错误PythonRDD:Python工作人员意外退出(崩溃) java.net.SocketException:通过对等方重置连接:套接字写入错误

  2. org.apache.spark.SparkException:作业因阶段失败而中止:阶段0.0中的任务0失败1次,最近失败:阶段0.0中丢失任务0.0(TID 0,本地 host):java.net.SocketException:通过peer重置连接:socket write error

  3. 使用spark 1.1.0。任何建议都会有很大的帮助。

    代码:

     from pyspark.mllib.classification import SVMWithSGD
        from pyspark.mllib.regression import LabeledPoint
        from pyspark.mllib.linalg import Vectors 
        from pyspark import SparkContext
        from pyspark import SparkConf, SparkContext
        from numpy import array
    
    
        #Train the model using feature matrix
        # Load and parse the data
        def parsePoint(line):
            values = [float(x) for x in line.split(' ')]
            return LabeledPoint(values[0], values[1:])
    
        #create spark Context
        conf = (SparkConf()
             .setMaster("local")
             .setAppName("My app")
             .set("spark.executor.memory", "1g"))
        sc = SparkContext(conf = conf)
    
        data = sc.textFile("myfile.txt")
        parsedData = data.map(parsePoint)
    
        #Train SVM model
        model = SVMWithSGD.train(parsedData,100)
    

    我收到以下错误:

    14/11/15 22:38:38 INFO MemoryStore: ensureFreeSpace(32768) called with curMem=0, maxMem=278302556
    14/11/15 22:38:38 INFO MemoryStore: Block broadcast_0 stored as values in memory (estimated size 32.0 KB, free 265.4 MB)
    >>> parsedData = data.map(parsePoint)
    >>> model = SVMWithSGD.train(parsedData,100)
    14/11/15 22:39:12 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
    14/11/15 22:39:12 WARN LoadSnappy: Snappy native library not loaded
    14/11/15 22:39:12 INFO FileInputFormat: Total input paths to process : 1
    14/11/15 22:39:13 INFO SparkContext: Starting job: runJob at PythonRDD.scala:296
    14/11/15 22:39:13 INFO DAGScheduler: Got job 0 (runJob at PythonRDD.scala:296) with 1 output partitions (allowLocal=true)
    14/11/15 22:39:13 INFO DAGScheduler: Final stage: Stage 0(runJob at PythonRDD.scala:296)
    14/11/15 22:39:13 INFO DAGScheduler: Parents of final stage: List()
    14/11/15 22:39:13 INFO DAGScheduler: Missing parents: List()
    14/11/15 22:39:13 INFO DAGScheduler: Submitting Stage 0 (PythonRDD[3] at RDD at PythonRDD.scala:43), which has no missing parents
    14/11/15 22:39:13 INFO MemoryStore: ensureFreeSpace(5088) called with curMem=32768, maxMem=278302556
    14/11/15 22:39:13 INFO MemoryStore: Block broadcast_1 stored as values in memory (estimated size 5.0 KB, free 265.4 MB)
    14/11/15 22:39:13 INFO DAGScheduler: Submitting 1 missing tasks from Stage 0 (PythonRDD[3] at RDD at PythonRDD.scala:43)
    14/11/15 22:39:13 INFO TaskSchedulerImpl: Adding task set 0.0 with 1 tasks
    14/11/15 22:39:13 INFO TaskSetManager: Starting task 0.0 in stage 0.0 (TID 0, localhost, PROCESS_LOCAL, 1221 bytes)
    14/11/15 22:39:13 INFO Executor: Running task 0.0 in stage 0.0 (TID 0)
    14/11/15 22:39:13 INFO HadoopRDD: Input split: file:/G:/SparkTest/spark-1.1.0/spark-1.1.0/bin/FeatureMatrix.txt:0+8103732
    14/11/15 22:39:13 INFO PythonRDD: Times: total = 264, boot = 233, init = 29, finish = 2
    14/11/15 22:39:13 ERROR PythonRDD: Python worker exited unexpectedly (crashed)
    java.net.SocketException: Connection reset by peer: socket write error
            at java.net.SocketOutputStream.socketWrite0(Native Method)
            at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
            at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
            at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
            at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
            at java.io.DataOutputStream.write(DataOutputStream.java:107)
            at java.io.FilterOutputStream.write(FilterOutputStream.java:97)
            at org.apache.spark.api.python.PythonRDD$.writeUTF(PythonRDD.scala:533)
            at org.apache.spark.api.python.PythonRDD$$anonfun$writeIteratorToStream$2.apply(PythonRDD.scala:341)
            at org.apache.spark.api.python.PythonRDD$$anonfun$writeIteratorToStream$2.apply(PythonRDD.scala:340)
            at scala.collection.Iterator$class.foreach(Iterator.scala:727)
            at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
            at org.apache.spark.api.python.PythonRDD$.writeIteratorToStream(PythonRDD.scala:340)
            at org.apache.spark.api.python.PythonRDD$WriterThread$$anonfun$run$1.apply$mcV$sp(PythonRDD.scala:209)
            at org.apache.spark.api.python.PythonRDD$WriterThread$$anonfun$run$1.apply(PythonRDD.scala:184)
            at org.apache.spark.api.python.PythonRDD$WriterThread$$anonfun$run$1.apply(PythonRDD.scala:184)
            at org.apache.spark.util.Utils$.logUncaughtExceptions(Utils.scala:1311)
            at org.apache.spark.api.python.PythonRDD$WriterThread.run(PythonRDD.scala:183)
    14/11/15 22:39:13 ERROR PythonRDD: This may have been caused by a prior exception:
    java.net.SocketException: Connection reset by peer: socket write error
            at java.net.SocketOutputStream.socketWrite0(Native Method)
            at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
            at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
            at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
            at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
            at java.io.DataOutputStream.write(DataOutputStream.java:107)
            at java.io.FilterOutputStream.write(FilterOutputStream.java:97)
            at org.apache.spark.api.python.PythonRDD$.writeUTF(PythonRDD.scala:533)
            at org.apache.spark.api.python.PythonRDD$$anonfun$writeIteratorToStream$2.apply(PythonRDD.scala:341)
            at org.apache.spark.api.python.PythonRDD$$anonfun$writeIteratorToStream$2.apply(PythonRDD.scala:340)
            at scala.collection.Iterator$class.foreach(Iterator.scala:727)
            at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
            at org.apache.spark.api.python.PythonRDD$.writeIteratorToStream(PythonRDD.scala:340)
            at org.apache.spark.api.python.PythonRDD$WriterThread$$anonfun$run$1.apply$mcV$sp(PythonRDD.scala:209)
            at org.apache.spark.api.python.PythonRDD$WriterThread$$anonfun$run$1.apply(PythonRDD.scala:184)
            at org.apache.spark.api.python.PythonRDD$WriterThread$$anonfun$run$1.apply(PythonRDD.scala:184)
            at org.apache.spark.util.Utils$.logUncaughtExceptions(Utils.scala:1311)
            at org.apache.spark.api.python.PythonRDD$WriterThread.run(PythonRDD.scala:183)
    14/11/15 22:39:13 ERROR Executor: Exception in task 0.0 in stage 0.0 (TID 0)
    java.net.SocketException: Connection reset by peer: socket write error
            at java.net.SocketOutputStream.socketWrite0(Native Method)
            at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
            at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
            at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
            at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
            at java.io.DataOutputStream.write(DataOutputStream.java:107)
            at java.io.FilterOutputStream.write(FilterOutputStream.java:97)
            at org.apache.spark.api.python.PythonRDD$.writeUTF(PythonRDD.scala:533)
            at org.apache.spark.api.python.PythonRDD$$anonfun$writeIteratorToStream$2.apply(PythonRDD.scala:341)
            at org.apache.spark.api.python.PythonRDD$$anonfun$writeIteratorToStream$2.apply(PythonRDD.scala:340)
            at scala.collection.Iterator$class.foreach(Iterator.scala:727)
            at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
            at org.apache.spark.api.python.PythonRDD$.writeIteratorToStream(PythonRDD.scala:340)
            at org.apache.spark.api.python.PythonRDD$WriterThread$$anonfun$run$1.apply$mcV$sp(PythonRDD.scala:209)
            at org.apache.spark.api.python.PythonRDD$WriterThread$$anonfun$run$1.apply(PythonRDD.scala:184)
            at org.apache.spark.api.python.PythonRDD$WriterThread$$anonfun$run$1.apply(PythonRDD.scala:184)
            at org.apache.spark.util.Utils$.logUncaughtExceptions(Utils.scala:1311)
            at org.apache.spark.api.python.PythonRDD$WriterThread.run(PythonRDD.scala:183)
    14/11/15 22:39:13 WARN TaskSetManager: Lost task 0.0 in stage 0.0 (TID 0, localhost): java.net.SocketException: Connection reset by peer: socket write error
            java.net.SocketOutputStream.socketWrite0(Native Method)
            java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
            java.net.SocketOutputStream.write(SocketOutputStream.java:159)
            java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
            java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
            java.io.DataOutputStream.write(DataOutputStream.java:107)
            java.io.FilterOutputStream.write(FilterOutputStream.java:97)
            org.apache.spark.api.python.PythonRDD$.writeUTF(PythonRDD.scala:533)
            org.apache.spark.api.python.PythonRDD$$anonfun$writeIteratorToStream$2.apply(PythonRDD.scala:341)
            org.apache.spark.api.python.PythonRDD$$anonfun$writeIteratorToStream$2.apply(PythonRDD.scala:340)
            scala.collection.Iterator$class.foreach(Iterator.scala:727)
            scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
            org.apache.spark.api.python.PythonRDD$.writeIteratorToStream(PythonRDD.scala:340)
            org.apache.spark.api.python.PythonRDD$WriterThread$$anonfun$run$1.apply$mcV$sp(PythonRDD.scala:209)
            org.apache.spark.api.python.PythonRDD$WriterThread$$anonfun$run$1.apply(PythonRDD.scala:184)
            org.apache.spark.api.python.PythonRDD$WriterThread$$anonfun$run$1.apply(PythonRDD.scala:184)
            org.apache.spark.util.Utils$.logUncaughtExceptions(Utils.scala:1311)
            org.apache.spark.api.python.PythonRDD$WriterThread.run(PythonRDD.scala:183)
    14/11/15 22:39:13 ERROR TaskSetManager: Task 0 in stage 0.0 failed 1 times; aborting job
    14/11/15 22:39:13 INFO TaskSchedulerImpl: Removed TaskSet 0.0, whose tasks have all completed, from pool
    14/11/15 22:39:13 INFO TaskSchedulerImpl: Cancelling stage 0
    14/11/15 22:39:13 INFO DAGScheduler: Failed to run runJob at PythonRDD.scala:296
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "G:\SparkTest\spark-1.1.0\spark-1.1.0\python\pyspark\mllib\classification.py", line 178, in train
        return _regression_train_wrapper(sc, train_func, SVMModel, data, initialWeights)
      File "G:\SparkTest\spark-1.1.0\spark-1.1.0\python\pyspark\mllib\_common.py", line 430, in _regression_train_wrapper
        initial_weights = _get_initial_weights(initial_weights, data)
      File "G:\SparkTest\spark-1.1.0\spark-1.1.0\python\pyspark\mllib\_common.py", line 415, in _get_initial_weights
        initial_weights = _convert_vector(data.first().features)
      File "G:\SparkTest\spark-1.1.0\spark-1.1.0\python\pyspark\rdd.py", line 1167, in first
        return self.take(1)[0]
      File "G:\SparkTest\spark-1.1.0\spark-1.1.0\python\pyspark\rdd.py", line 1153, in take
        res = self.context.runJob(self, takeUpToNumLeft, p, True)
      File "G:\SparkTest\spark-1.1.0\spark-1.1.0\python\pyspark\context.py", line 770, in runJob
        it = self._jvm.PythonRDD.runJob(self._jsc.sc(), mappedRDD._jrdd, javaPartitions, allowLocal)
      File "G:\SparkTest\spark-1.1.0\spark-1.1.0\python\lib\py4j-0.8.2.1-src.zip\py4j\java_gateway.py", line 538, in __call__
      File "G:\SparkTest\spark-1.1.0\spark-1.1.0\python\lib\py4j-0.8.2.1-src.zip\py4j\protocol.py", line 300, in get_return_value
    py4j.protocol.Py4JJavaError: An error occurred while calling z:org.apache.spark.api.python.PythonRDD.runJob.
    : org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 0.0 failed 1 times, most recent failure: Lost task 0.0 in stage 0.0 (TID 0, lo
    host): java.net.SocketException: Connection reset by peer: socket write error
            java.net.SocketOutputStream.socketWrite0(Native Method)
            java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
            java.net.SocketOutputStream.write(SocketOutputStream.java:159)
            java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
            java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
            java.io.DataOutputStream.write(DataOutputStream.java:107)
            java.io.FilterOutputStream.write(FilterOutputStream.java:97)
            org.apache.spark.api.python.PythonRDD$.writeUTF(PythonRDD.scala:533)
            org.apache.spark.api.python.PythonRDD$$anonfun$writeIteratorToStream$2.apply(PythonRDD.scala:341)
            org.apache.spark.api.python.PythonRDD$$anonfun$writeIteratorToStream$2.apply(PythonRDD.scala:340)
            scala.collection.Iterator$class.foreach(Iterator.scala:727)
            scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
            org.apache.spark.api.python.PythonRDD$.writeIteratorToStream(PythonRDD.scala:340)
            org.apache.spark.api.python.PythonRDD$WriterThread$$anonfun$run$1.apply$mcV$sp(PythonRDD.scala:209)
            org.apache.spark.api.python.PythonRDD$WriterThread$$anonfun$run$1.apply(PythonRDD.scala:184)
            org.apache.spark.api.python.PythonRDD$WriterThread$$anonfun$run$1.apply(PythonRDD.scala:184)
            org.apache.spark.util.Utils$.logUncaughtExceptions(Utils.scala:1311)
            org.apache.spark.api.python.PythonRDD$WriterThread.run(PythonRDD.scala:183)
    Driver stacktrace:
            at org.apache.spark.scheduler.DAGScheduler.org$apache$spark$scheduler$DAGScheduler$$failJobAndIndependentStages(DAGScheduler.scala:1185)
            at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1174)
            at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1173)
            at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
            at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
            at org.apache.spark.scheduler.DAGScheduler.abortStage(DAGScheduler.scala:1173)
            at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:688)
            at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:688)
            at scala.Option.foreach(Option.scala:236)
            at org.apache.spark.scheduler.DAGScheduler.handleTaskSetFailed(DAGScheduler.scala:688)
            at org.apache.spark.scheduler.DAGSchedulerEventProcessActor$$anonfun$receive$2.applyOrElse(DAGScheduler.scala:1391)
            at akka.actor.ActorCell.receiveMessage(ActorCell.scala:498)
            at akka.actor.ActorCell.invoke(ActorCell.scala:456)
            at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:237)
            at akka.dispatch.Mailbox.run(Mailbox.scala:219)
            at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386)
            at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
            at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
            at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
            at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
    
    >>> 14/11/15 23:22:52 INFO BlockManager: Removing broadcast 1
    14/11/15 23:22:52 INFO BlockManager: Removing block broadcast_1
    14/11/15 23:22:52 INFO MemoryStore: Block broadcast_1 of size 5088 dropped from memory (free 278269788)
    14/11/15 23:22:52 INFO ContextCleaner: Cleaned broadcast 1
    

    此致 Mrutyunjay

5 个答案:

答案 0 :(得分:3)

这很简单。

conf = SparkConf().setMaster("local").setAppName("RatingsHistogram") 
sc = SparkContext(conf = conf) 
lines = sc.textFile("file:///SparkCourse/filter_1.csv",2000) 
print lines.first()

使用sc.textfile时,将分区数的另外一个参数添加到一个较大的值。 数据越大,值越大。

答案 1 :(得分:2)

Mrutynjay,

虽然我没有确切的答案。问题看起来像是与记忆有关的事情。尝试读取5 MB的文件时,我也遇到了同样的问题。我删除了文件的一部分,并减少到不到1 MB,代码工作。

我也在下面的网站上找到了同样的问题。

http://apache-spark-user-list.1001560.n3.nabble.com/pyspark-Failed-to-run-first-td7691.html

答案 2 :(得分:1)

我收到同样的错误,然后我从pyspark process big datasets problems

得到了相应的答案

解决方案是添加一些代码 python / pyspark / worker.py

将以下2行添加到主函数

中定义的过程函数的末尾
 Yii::$app->urlManagerFrontEnd->baseUrl ."/path/to/your/place";

所以过程函数现在看起来像这样(至少在spark 1.5.2中):

for obj in iterator:
 pass

这对我有用。

答案 3 :(得分:1)

我有类似的问题,我尝试过类似的事情:

numPartitions =一个数字,例如10或100 data = sc.textFile(“myfile.txt”,numPartitions)

灵感来自:如何在Spark中均匀重新分配?或者在这里:https://databricks.gitbooks.io/databricks-spark-knowledge-base/content/performance_optimization/how_many_partitions_does_an_rdd_have.html

答案 4 :(得分:0)

  1. 一种可能性是parsePoint中存在异常,包装 try except块中的代码并打印出异常。
  2. 检查您的--driver-memory参数,使其更大。