首页 > 解决方案 > 使用 take 和 InsertInto 命令的 Spark Scala 性能问题

问题描述

请查看随附的屏幕截图。

我正在尝试对我的 spark 作业进行一些性能改进,并且需要将近 5 分钟才能对数据帧执行操作。

我正在使用 take 来确保数据帧中有一些记录,如果它存在,我想继续进行进一步处理。

我尝试了采取和计算,并没有看到执行时间有太大差异。

另一种情况是大约需要 10 分钟将 datafrane 写入配置单元表(它最多有 200 行和 10 列)。

df.write.mode("append").partitionBy("date").insertInto(tablename)

请建议我们如何最大限度地减少拍摄和插入蜂巢表所花费的时间。

在此处输入图像描述

更新:

这是我的火花提交: spark-submit --master yarn-cluster --class com.xxxx.info.InfoAssets --conf "spark.executor.extraJavaOptions=-XX:+UseCompressedOops -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Djava.security.auth.login.config=kafka_spark_jaas.conf" --files /home/ngap.app.rcrp/hive-site.xml,/home//kafka_spark_jaas.conf,/​​etc/security/keytabs/ngap。 sa.rcrp.keytab --jars /usr/hdp/current/spark-client/lib/datanucleus-api-jdo-3.2.6.jar,/usr/hdp/current/spark-client/lib/datanucleus-core- 3.2.10.jar,/usr/hdp/current/spark-client/lib/datanucleus-rdbms-3.2.9.jar --executor-memory 3G --num-executors 3 --executor-cores 10 /home/InfoAssets /InfoAssets.jar

它是一个简单的数据框,它有 8 列,其中包含大约 200 条记录,我正在使用以下代码插入配置单元表。

df.write.mode("append").partitionBy("partkey").insertInto(hiveDB + "." + tableName)

谢谢,粑粑

标签: scalaapache-spark

解决方案


如果没有必要,不要在写入之前使用 count 并且如果您的表已经创建,则使用 Spark SQL 将数据插入 Hive Partitioned 表。

spark.sql("Insert into <tgt tbl> partition(<col name>) select cols,partition col from temp_tbl")

推荐阅读