zoukankan      html  css  js  c++  java
  • Spark ML 之 ALS内存溢出的解决办法

    原帖:https://blog.csdn.net/Damonhaus/article/details/76572971

    问题:协同过滤 ALS算法。在测试过程中遇到了内存溢出的错误

    解决办法1:降低迭代次数,20次 -> 10次

      val model = new ALS().setRank(10).setIterations(20).setLambda(0.01).setImplicitPrefs(false) .run(alldata) 

    以上改成 .setIterations(10)

    解决办法2:checkpoint机制

      /**
         *  删除checkpoint留下的过程数据
         */
        val path = new Path(HDFSConnection.paramMap("hadoop_url")+"/checkpoint"); //声明要操作(删除)的hdfs 文件路径
        val hadoopConf = spark.sparkContext.hadoopConfiguration
        val hdfs = org.apache.hadoop.fs.FileSystem.get(new URI(HDFSConnection.paramMap("hadoop_url")+"/checkpoint"),hadoopConf)
        if(hdfs.exists(path)) {
          //需要递归删除设置true,不需要则设置false
          hdfs.delete(path, true) //这里因为是过程数据,可以递归删除
        }
    
      /**
       * 设置 CheckpointDir
       */
        spark.sparkContext.setCheckpointDir(HDFSConnection.paramMap("hadoop_url")+"/checkpoint")
     /**
       * Set period (in iterations) between checkpoints (default = 10). Checkpointing helps with
       * recovery (when nodes fail) and StackOverflow exceptions caused by long lineage. It also helps
       * with eliminating temporary shuffle files on disk, which can be important when there are many
       * ALS iterations. If the checkpoint directory is not set in [[org.apache.spark.SparkContext]],
       * this setting is ignored.
       */
    
    val model = new ALS().setCheckpointInterval(2).setRank(10).setIterations(20).setLambda(0.01).setImplicitPrefs(false)
          .run(alldata)
  • 相关阅读:
    M1阶段的开发过程的一些反思
    Alpha版本发布说明
    Alpha版本BUG BASH
    Notes of Daily Scrum Meeting(11.19)
    Notes of Daily Scrum Meeting(11.17)
    Notes of Daily Scrum Meeting(11.15)
    Notes of Daily Scrum Meeting(11.14)
    flask_sqlalchemy介绍
    SQLAlchemy 简单笔记
    Python-3.6 安装pycrypto 2.6
  • 原文地址:https://www.cnblogs.com/sabertobih/p/13863214.html
Copyright © 2011-2022 走看看