【发布时间】:2016-04-09 01:23:19
【问题描述】:
我目前正在研究 apache spark,我正在尝试从 Web 应用程序运行 java 代码。当我尝试将代码作为 java 应用程序运行时,它工作正常。但是当我尝试将其部署为 Web 应用程序时,当程序到达保存模型的阶段时,即model.save(sparkcontext,modelpath),我收到了permgen java.lang.OutOfMemory exception。但是当我尝试将模型编写为对象文件时,例如:
File modelFile = new File(modelPath);
if(!modelFile.exists()){
modelFile.createNewFile();
}
FileOutputStream fout = new FileOutputStream(modelFile);
ObjectOutputStream oout = new ObjectOutputStream(fout);
oout.writeObject(model);
oout.close();
它工作正常。 model.save() 是如何在 apache spark 中实现的?
还有其他方法可以保存模型吗?
提前致谢
【问题讨论】:
-
模型的类是什么?
-
我正在研究随机森林回归模型。
-
@BalachandarS :模型是 RDD 吗?您是否尝试将 RDD 保存到文件中?
-
是的,它有 RDD 和哈希图!
-
@BalachandarS :你需要展示模型实现,问题不清楚..如果你有一些 RDD
然后你想把它保存在一个文件中,你可以调用 rdd. saveAsTextFile() 方法.. 这将调用 Model 类的 toString() 方法。
标签: apache-spark apache-spark-ml