scala - 使用 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)
谢谢,粑粑
解决方案
如果没有必要,不要在写入之前使用 count 并且如果您的表已经创建,则使用 Spark SQL 将数据插入 Hive Partitioned 表。
spark.sql("Insert into <tgt tbl> partition(<col name>) select cols,partition col from temp_tbl")
推荐阅读
- libvlcsharp - C# LibVLCSharp:SetAudioDevice - 错误 0x80070057
- python - Discord.py:如果用户具有特定角色,则更改昵称
- asp.net - 印章报告与 asp.net mvc web 应用程序的集成
- reactjs - 如何使用 mapbox 和 Next.js 使弹出窗口可链接?
- linux-kernel - GPIO:虽然边缘设置为“上升”,但在两个边缘都获得 ISR
- python - 我想将一条曲线拟合到我的 5 点数据集,但它似乎不适用于 Sklearn PolynomialFeatures
- css - 在 Tailwind 中设置文本的默认颜色
- javascript - 检测 iFrame 中的元素是否在客户端视图中
- react-admin - 如何在 rowClick 显示时呈现另一个列表
- javascript - 将行动态添加到 Google 图表的时间轴