Apache spark Pypark write.csv()被Thread关闭,以超出内存限制

Apache spark Pypark write.csv()被Thread关闭,以超出内存限制,apache-spark,pyspark,apache-spark-sql,Apache Spark,Pyspark,Apache Spark Sql,前提:我不能控制我的集群,我工作的前提是问题出在我的代码中,而不是我学校使用的设置。也许这是错误的,但这是一个假设,是这个问题的基础 以前在更大版本的数据上进行的许多操作都成功了,为什么write.csv()会导致pyspark/slurm作业超出内存限制?对此我能做些什么 我得到的错误是(多次迭代…): 我知道我可以改变内存限制,但我已经增加了好几次,结果没有任何变化,而且我非常确信我不应该使用任何接近这个内存量的东西。作为参考,我的slurm呼叫是: spark-submit \ -

前提:我不能控制我的集群,我工作的前提是问题出在我的代码中,而不是我学校使用的设置。也许这是错误的,但这是一个假设,是这个问题的基础

以前在更大版本的数据上进行的许多操作都成功了,为什么write.csv()会导致pyspark/slurm作业超出内存限制?对此我能做些什么

我得到的错误是(多次迭代…):

我知道我可以改变内存限制,但我已经增加了好几次,结果没有任何变化,而且我非常确信我不应该使用任何接近这个内存量的东西。作为参考,我的slurm呼叫是:

spark-submit \
    --master yarn \
    --num-executors 100 \
   --executor-memory 6g \
   3main.py
那么我到底想写什么呢?我读到了一个39G.bz2JSON,到一个RDD

allposts = ss.read.json(filename)
过滤了一堆,数了数单词,对RDD进行了分组,做了一些计算,过滤了更多,最后我用这两个打印语句给出了剩下的一些想法

abscounts = calculatePosts2(postRDD, sc, spark)
abscounts.printSchema()
print(abscounts.count())
这些打印语句有效(输出如下)。结果RDD约为60 cols乘以2000行+/-。这60列包括1个相当于子Reddit名称长度的字符串和59个双精度字符串

root
 |-- subreddit: string (nullable = true)
 |-- count(1): long (nullable = false)
 |-- sum(wordcount): long (nullable = true)
 |-- ingestfreq: double (nullable = true)
 |-- causefreq: double (nullable = true)
 |-- insightfreq: double (nullable = true)
 |-- cogmechfreq: double (nullable = true)
 |-- sadfreq: double (nullable = true)
 |-- inhibfreq: double (nullable = true)
 |-- certainfreq: double (nullable = true)
 |-- tentatfreq: double (nullable = true)
 |-- discrepfreq: double (nullable = true)
 |-- spacefreq: double (nullable = true)
 |-- timefreq: double (nullable = true)
 |-- exclfreq: double (nullable = true)
 |-- inclfreq: double (nullable = true)
 |-- relativfreq: double (nullable = true)
 |-- motionfreq: double (nullable = true)
 |-- quantfreq: double (nullable = true)
 |-- numberfreq: double (nullable = true)
 |-- swearfreq: double (nullable = true)
 |-- functfreq: double (nullable = true)
 |-- absolutistfreq: double (nullable = true)
 |-- ppronfreq: double (nullable = true)
 |-- pronounfreq: double (nullable = true)
 |-- wefreq: double (nullable = true)
 |-- ifreq: double (nullable = true)
 |-- shehefreq: double (nullable = true)
 |-- youfreq: double (nullable = true)
 |-- ipronfreq: double (nullable = true)
 |-- theyfreq: double (nullable = true)
 |-- deathfreq: double (nullable = true)
 |-- biofreq: double (nullable = true)
 |-- bodyfreq: double (nullable = true)
 |-- hearfreq: double (nullable = true)
 |-- feelfreq: double (nullable = true)
 |-- perceptfreq: double (nullable = true)
 |-- seefreq: double (nullable = true)
 |-- fillerfreq: double (nullable = true)
 |-- healthfreq: double (nullable = true)
 |-- sexualfreq: double (nullable = true)
 |-- socialfreq: double (nullable = true)
 |-- familyfreq: double (nullable = true)
 |-- friendfreq: double (nullable = true)
 |-- humansfreq: double (nullable = true)
 |-- affectfreq: double (nullable = true)
 |-- posemofreq: double (nullable = true)
 |-- negemofreq: double (nullable = true)
 |-- anxfreq: double (nullable = true)
 |-- angerfreq: double (nullable = true)
 |-- assentfreq: double (nullable = true)
 |-- nonflfreq: double (nullable = true)
 |-- verbfreq: double (nullable = true)
 |-- articlefreq: double (nullable = true)
 |-- pastfreq: double (nullable = true)
 |-- auxverbfreq: double (nullable = true)
 |-- futurefreq: double (nullable = true)
 |-- presentfreq: double (nullable = true)
 |-- prepsfreq: double (nullable = true)
 |-- adverbfreq: double (nullable = true)
 |-- negatefreq: double (nullable = true)
 |-- conjfreq: double (nullable = true)
 |-- homefreq: double (nullable = true)
 |-- leisurefreq: double (nullable = true)
 |-- achievefreq: double (nullable = true)
 |-- workfreq: double (nullable = true)
 |-- religfreq: double (nullable = true)
 |-- moneyfreq: double (nullable = true)

...

2026
在此之后,我的代码中唯一剩下的一行是:

  abscounts.write.csv('bigoutput.csv', header=True)
这会因为内存错误而崩溃。这绝对不应该占用空间。。。我做错了什么

谢谢你的帮助


如果你好奇/这有帮助,我的全部代码首先是executor.memoryOverhead与executor memory不同。如你所见

对于Pyspark,memoryOverhead很重要,因为它控制python执行某些操作所需的额外内存(请参阅),在您的例子中,每个分区收集和保存一个CSV文件


帮助Python,你也可以考虑在写之前使用.< /P> AtPraseDATAFRAME有多少个分区(ALSTPOST.RDD.GETNUBECTIONTIONS())?您可能需要对其重新分区,并创建更多更小的分区,以确保每个分区+开销都适合存储在内存中executor@DenisMakarenkoallposts有318个分区(在对数据进行任何过滤或处理之前)。abscounts(这就是我要写的)有200个。当你说我可能需要重新分区时——这和下面用户3689574的答案是一样的吗?原谅我,但我在这件事上有点不知所措,我只是在关注我在这里得到的大部分回应……谢谢你的回答。我必须承认我并没有完全理解你们链接中的内容,但我知道我确实需要独立设置内存开销。想必联合会以某种方式减少开销?但是,对于一个最多120k条目的RDD(大约60个双精度RDD和一个20个字符的字符串),我需要多少分区/多少内存开销?

  abscounts.write.csv('bigoutput.csv', header=True)