Spark partitionBy much slower than without it

房东的猫 提交于 2019-12-04 13:40:32

问题


I tested writing with:

 df.write.partitionBy("id", "name")
    .mode(SaveMode.Append)
    .parquet(filePath)

However if I leave out the partitioning:

 df.write
    .mode(SaveMode.Append)
    .parquet(filePath)

It executes 100x(!) faster.

Is it normal for the same amount of data to take 100x longer to write when partitioning?

There are 10 and 3000 unique id and name column values respectively. The DataFrame has 10 additional integer columns.


回答1:


The first code snippet will write a parquet file per partition to file system (local or HDFS). This means that if you have 10 distinct ids and 3000 distinct names this code will create 30000 files. I suspect that overhead of creating files, writing parquet metadata, etc is quite large (in addition to shuffling).

Spark is not the best database engine, if your dataset fits in memory I suggest to use a relational database. It will be faster and easier to work with.



来源:https://stackoverflow.com/questions/32898218/spark-partitionby-much-slower-than-without-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!