我在AWS EC2上运行Spark 1.4.0,使用MLLIB对我的数据进行随机林的测试运行。经过几个阶段后它一直悬挂着。我试过在netty和nio之间切换,但没有帮助。
查看任务,我看到完成了以下工作
collect at DecisionTree.scala:977
count at DecisionTreeMetadata.scala:111
take at DecisionTreeMetadata.scala:110
take at DecisionTreeMetadata.scala:110
runJob at PythonRDD.scala:366
runJob at PythonRDD.scala:366
看看存储,我看到两个RDD:PythonRDD和MapPartitionsRDD分别为27MB和47.5MB。
我有1个Master和10个工作人员总共550GB的存储空间,由sparkUI报告,我的数据要小得多。当我在UI中查看作业时,它将被列为正在进行中,所有任务都已完成。但它不会进入下一步。
我运行随机森林的代码非常简单:
(trainingData, testData) = data.randomSplit([0.7, 0.3])
model = RandomForest.trainClassifier(trainingData, numClasses=2, categoricalFeaturesInfo={},
numTrees=3, featureSubsetStrategy="auto",
impurity='gini', maxDepth=4, maxBins=32)
这是挂起的:
15/09/17 01:16:47 INFO scheduler.TaskSetManager: Finished task 121.0 in stage 7.0 (TID 346) in 279 ms on 10.0.29.252 (158/160)
15/09/17 01:16:47 INFO scheduler.TaskSetManager: Finished task 45.0 in stage 7.0 (TID 254) in 319 ms on 10.0.28.53 (159/160)
15/09/17 01:16:47 INFO scheduler.TaskSetManager: Finished task 91.0 in stage 7.0 (TID 316) in 302 ms on 10.0.29.252 (160/160)
15/09/17 01:16:47 INFO scheduler.TaskSchedulerImpl: Removed TaskSet 7.0, whose tasks have all completed, from pool
15/09/17 01:16:47 INFO scheduler.DAGScheduler: ResultStage 7 (collect at DecisionTree.scala:977) finished in 0.339 s
15/09/17 01:16:47 INFO scheduler.DAGScheduler: Job 7 finished: collect at DecisionTree.scala:977, took 0.370436 s
15/09/17 01:17:03 INFO storage.BlockManagerInfo: Removed broadcast_7_piece0 on 10.0.28.139:47025 in memory (size: 4.7 KB, free: 45.5 GB)
15/09/17 01:17:03 INFO storage.BlockManagerInfo: Removed broadcast_7_piece0 on 10.0.29.154:38339 in memory (size: 4.7 KB, free: 50.5 GB)
...
...
15/09/17 01:17:03 INFO storage.BlockManagerInfo: Removed broadcast_1_piece0 on 10.0.28.139:47025 in memory (size: 4.2 KB, free: 45.5 GB)
15/09/17 01:17:03 INFO storage.BlockManagerInfo: Removed broadcast_1_piece0 on 10.0.28.111:47295 in memory (size: 4.2 KB, free: 50.5 GB)
15/09/17 01:17:03 INFO storage.BlockManagerInfo: Removed broadcast_1_piece0 on 10.0.28.211:35071 in memory (size: 4.2 KB, free: 50.5 GB)
15/09/17 01:17:03 INFO storage.BlockManagerInfo: Removed broadcast_1_piece0 on 10.0.29.155:53837 in memory (size: 4.2 KB, free: 50.5 GB)
15/09/17 01:17:03 INFO storage.BlockManagerInfo: Removed broadcast_1_piece0 on 10.0.29.158:45929 in memory (size: 4.2 KB, free: 50.5 GB)
修改 有关如何创建数据的其他信息: 我的数据是来自MLLIB的LabeledPoint类型的RDD。每个标记的点对象都包含SparseVector类型的标签和特征
>>> type(data.first())
<class 'pyspark.mllib.regression.LabeledPoint'>
>>> type(data.first().features)
<class 'pyspark.mllib.linalg.SparseVector'>
每个标记点的格式为:
LabeledPoint(0.0, (1080963,[44673,64508,65588,122081,306819,306820,382530 ...], [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0 ...]))
>>> d = data.first()
>>> d.label
0.0
>>> d.features.size
1080963
>>> len(d.features.values)
2286
EDIT2: 我让它坐了一个多小时,它终于破了。这是断点处的错误输出。
15/09/17 19:36:13 INFO storage.BlockManagerInfo: Removed broadcast_4_piece0 on 10.0.28.233:38432 in memory (size: 4.4 KB, free: 45.5 GB)
15/09/17 19:36:13 INFO storage.BlockManagerInfo: Removed broadcast_4_piece0 on 10.0.28.28:58416 in memory (size: 4.4 KB, free: 50.5 GB)
15/09/17 19:36:13 INFO storage.BlockManager: Removing RDD 10
15/09/17 19:36:13 INFO spark.ContextCleaner: Cleaned RDD 10
15/09/17 19:36:13 INFO storage.BlockManagerInfo: Removed broadcast_3_piece0 on 10.0.28.233:38432 in memory (size: 4.2 KB, free: 45.5 GB)
15/09/17 19:36:13 INFO storage.BlockManagerInfo: Removed broadcast_3_piece0 on 10.0.28.28:58416 in memory (size: 4.2 KB, free: 50.5 GB)
15/09/17 19:36:13 INFO storage.BlockManagerInfo: Removed broadcast_2_piece0 on 10.0.28.233:38432 in memory (size: 3.7 KB, free: 45.5 GB)
15/09/17 19:36:13 INFO storage.BlockManagerInfo: Removed broadcast_2_piece0 on 10.0.28.28:58416 in memory (size: 3.7 KB, free: 50.5 GB)
15/09/17 19:36:13 INFO storage.BlockManagerInfo: Removed broadcast_2_piece0 on 10.0.28.31:56554 in memory (size: 3.7 KB, free: 50.5 GB)
15/09/17 20:33:43 INFO rdd.MapPartitionsRDD: Removing RDD 28 from persistence list
15/09/17 20:33:43 INFO storage.BlockManager: Removing RDD 28
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "random_forest_spark.py", line 144, in trainModel
impurity='gini', maxDepth=4, maxBins=32)
File "/root/spark/python/pyspark/mllib/tree.py", line 352, in trainClassifier
maxDepth, maxBins, seed)
File "/root/spark/python/pyspark/mllib/tree.py", line 270, in _train
maxDepth, maxBins, seed)
File "/root/spark/python/pyspark/mllib/common.py", line 128, in callMLlibFunc
return callJavaFunc(sc, api, *args)
File "/root/spark/python/pyspark/mllib/common.py", line 121, in callJavaFunc
return _java2py(sc, func(*args))
File "/root/spark/python/lib/py4j-0.8.2.1-src.zip/py4j/java_gateway.py", line 538, in __call__
File "/root/spark/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 o104.trainRandomForestModel.
: java.lang.OutOfMemoryError
at java.io.ByteArrayOutputStream.hugeCapacity(ByteArrayOutputStream.java:123)
at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:117)
at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:153)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1876)
at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1785)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1188)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
at org.apache.spark.serializer.JavaSerializationStream.writeObject(JavaSerializer.scala:44)
at org.apache.spark.serializer.JavaSerializerInstance.serialize(JavaSerializer.scala:81)
at org.apache.spark.util.ClosureCleaner$.ensureSerializable(ClosureCleaner.scala:312)
at org.apache.spark.util.ClosureCleaner$.org$apache$spark$util$ClosureCleaner$$clean(ClosureCleaner.scala:305)
at org.apache.spark.util.ClosureCleaner$.clean(ClosureCleaner.scala:132)
at org.apache.spark.SparkContext.clean(SparkContext.scala:1891)
at org.apache.spark.rdd.RDD$$anonfun$map$1.apply(RDD.scala:294)
at org.apache.spark.rdd.RDD$$anonfun$map$1.apply(RDD.scala:293)
at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:148)
at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:109)
at org.apache.spark.rdd.RDD.withScope(RDD.scala:286)
at org.apache.spark.rdd.RDD.map(RDD.scala:293)
at org.apache.spark.mllib.tree.impl.TreePoint$.convertToTreeRDD(TreePoint.scala:65)
at org.apache.spark.mllib.tree.RandomForest.run(RandomForest.scala:160)
at org.apache.spark.mllib.tree.RandomForest$.trainClassifier(RandomForest.scala:289)
at org.apache.spark.mllib.api.python.PythonMLLibAPI.trainRandomForestModel(PythonMLLibAPI.scala:666)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:379)
at py4j.Gateway.invoke(Gateway.java:259)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:207)
at java.lang.Thread.run(Thread.java:745)