火花从记忆中升起

2024-09-24 22:28:22 发布

您现在位置:Python中文网/ 问答频道 /正文

当我运行spark python代码时,如下所示:

import pyspark
conf = (pyspark.SparkConf()
     .setMaster("local")
     .setAppName("My app")
     .set("spark.executor.memory", "512m"))
sc = pyspark.SparkContext(conf = conf)        #start the conf
data =sc.textFile('/Users/tsangbosco/Downloads/transactions')
data = data.flatMap(lambda x:x.split()).take(all)

该文件约为20G,我的计算机有8G ram,当我在独立模式下运行程序时,会引发OutOfMemoryError:

^{pr2}$

spark无法处理比我的ram大的文件吗?你能告诉我怎么修吗?在


Tags: 文件代码importappdatamylocalconf
1条回答
网友
1楼 · 发布于 2024-09-24 22:28:22

Spark能处理一些案子。但是您使用take强制Spark将所有数据提取到一个数组(内存中)。在这种情况下,您应该将它们存储到文件中,就像使用saveAsTextFile。在

如果您对查看某些数据感兴趣,可以使用sample或{}。在

相关问题 更多 >