Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Spark数据帧脚本运行非常慢_Python_Apache Spark_Pyspark_Spark Dataframe - Fatal编程技术网

Python Spark数据帧脚本运行非常慢

Python Spark数据帧脚本运行非常慢,python,apache-spark,pyspark,spark-dataframe,Python,Apache Spark,Pyspark,Spark Dataframe,我对大数据非常陌生,目前正在学习Spark。我已经在我的windows笔记本电脑上安装了Spark 2.0,并使用Python3.4中的Spark Dataframe api创建了一个脚本,以查找1个特定列的总和。时间太长,约5分钟3秒。 此文本文件非常大(约500mb),包含240万条记录。 任务管理器显示100%的CPU消耗和50%的RAM消耗。 以下是我所做的: import sys from pyspark.sql import SparkSession, Row def mapLog

我对大数据非常陌生,目前正在学习Spark。我已经在我的windows笔记本电脑上安装了Spark 2.0,并使用Python3.4中的Spark Dataframe api创建了一个脚本,以查找1个特定列的总和。时间太长,约5分钟3秒。
此文本文件非常大(约500mb),包含240万条记录。
任务管理器显示100%的CPU消耗和50%的RAM消耗。
以下是我所做的:

import sys
from pyspark.sql import SparkSession, Row

def mapLogs(line):
    fields = line.split("|")
    return Row(userID=int(fields[0]), trackID=int(fields[1]), shared=int(fields[2]), radio=int(fields[3]), skip=int(fields[4]))

spark = SparkSession\
    .builder\
    .config("spark.sql.warehouse.dir","file:///F:/temp")\
    .appName("MusciTrackShared")\
    .getOrCreate()

lines = spark.sparkContext.textFile("bigTextFile.txt")          # format : UserId|TrackId|Shared|Radio|Skip
music_logs = lines.map(mapLogs)                                 # convert each line to Row

df = spark.createDataFrame(music_logs)                          # create dataframe

df.filter(df['shared'] == 1).groupBy(df['trackID']).sum('shared').orderBy("sum(shared)", ascending=False).show(5)

spark.stop()
我做错了什么?有人能给我指出正确的方向吗?


感谢Pig脚本提供相同的查询和测试数据,在ubuntu虚拟机上需要3分钟。Spark应该工作得更快,对吧?我用基本的RDD命令在saprk中重新编写了相同的程序,仍然需要5分钟1秒。14个小时过去了,社区没有任何评论。我真的很惊讶。