在 Pyspark 中使用 checkpoint 后程序运行速度更快,为什么?

问题描述

我的火花设置是这样的:

  spark_conf = SparkConf().setAppName('app_name') \
    .setMaster("local[4]") \
    .set('spark.executor.memory',"8g") \
    .set('spark.executor.cores',4) \
    .set('spark.task.cpus',1)
  sc = SparkContext.getorCreate(conf=spark_conf)
  sc.setCheckpointDir(dirName='checkpoint')

当我在火花链中没有任何检查点并且我的程序是这样的:

  result = sc.parallelize(group,4) \
    .map(func_read,preservesPartitioning=True)\
    .map(func2,preservesPartitioning=True) \
    .flatMap(df_to_dic,preservesPartitioning=True) \
    .reduceByKey(func3) \
    .map(func4,preservesPartitioning=True) \
    .reduceByKey(func5) \
    .map(write_to_db) \
    .count()

运行时间约为 8 小时。 但是当我像这样使用检查点和缓存 RDD 时:

result = sc.parallelize(group,preservesPartitioning=True) \
    .reduceByKey(func5) \
    .map(write_to_db)
result.cache()
result.checkpoint()
result.count()

程序运行大约需要 3 个小时。请您指导如何在缓存 RDD 和使用检查点后程序运行得更快?

任何帮助将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)