gpt4 book ai didi

hadoop - 在失败或中止时重新运行 Spark 作业

转载 作者:可可西里 更新时间:2023-11-01 14:22:44 26 4
gpt4 key购买 nike

我期待在通过 Yarn 提交任何失败的情况下自动重启 Spark 作业的配置或参数。我知道任务会在失败时自动重启。我非常期待能够触发重新运行整个作业的YARN 或 Spark 配置

现在,如果我们的任何作业由于任何问题而中止,我们必须手动重新启动它,这会导致需要处理很长的数据队列,因为这些作业旨在近乎实时地工作。

当前配置:

#!/bin/bash

export SPARK_MAJOR_VERSION=2

# Minimum TODOs on a per job basis:
# 1. define name, application jar path, main class, queue and log4j-yarn.properties path
# 2. remove properties not applicable to your Spark version (Spark 1.x vs. Spark 2.x)
# 3. tweak num_executors, executor_memory (+ overhead), and backpressure settings

# the two most important settings:
num_executors=6
executor_memory=32g

# 3-5 cores per executor is a good default balancing HDFS client throughput vs. JVM overhead
# see http://blog.cloudera.com/blog/2015/03/how-to-tune-your-apache-spark-jobs-part-2/
executor_cores=2

# backpressure
reciever_minRate=1
receiver_max_rate=10
receiver_initial_rate=10

/usr/hdp/2.6.1.0-129/spark2/bin/spark-submit --master yarn --deploy-mode cluster \
--name br1_warid_ccn_sms_production \
--class com.spark.main\
--driver-memory 16g \
--num-executors ${num_executors} --executor-cores ${executor_cores} --executor-memory ${executor_memory} \
--queue default \
--files log4j-yarn-warid-br1-ccn-sms.properties \
--conf "spark.driver.extraJavaOptions=-Dlog4j.configuration=log4j-yarn-warid-br1-ccn-sms.properties" \
--conf "spark.executor.extraJavaOptions=-Dlog4j.configuration=log4j-yarn-warid-br1-ccn-sms.properties" \
--conf spark.serializer=org.apache.spark.serializer.KryoSerializer `# Kryo Serializer is much faster than the default Java Serializer` \
--conf spark.kryoserializer.buffer.max=1g \
--conf spark.locality.wait=30 \
--conf spark.task.maxFailures=8 `# Increase max task failures before failing job (Default: 4)` \
--conf spark.ui.killEnabled=true `# Prevent killing of stages and corresponding jobs from the Spark UI` \
--conf spark.logConf=true `# Log Spark Configuration in driver log for troubleshooting` \
`# SPARK STREAMING CONFIGURATION` \
--conf spark.scheduler.mode=FAIR \
--conf spark.default.parallelism=32 \
--conf spark.streaming.blockInterval=200 `# [Optional] Tweak to balance data processing parallelism vs. task scheduling overhead (Default: 200ms)` \
--conf spark.streaming.receiver.writeAheadLog.enable=true `# Prevent data loss on driver recovery` \
--conf spark.streaming.backpressure.enabled=false \
--conf spark.streaming.kafka.maxRatePerPartition=${receiver_max_rate} `# [Spark 1.x]: Corresponding max rate setting for Direct Kafka Streaming (Default: not set)` \
`# YARN CONFIGURATION` \
--conf spark.yarn.driver.memoryOverhead=4096 `# [Optional] Set if --driver-memory < 5GB` \
--conf spark.yarn.executor.memoryOverhead=4096 `# [Optional] Set if --executor-memory < 10GB` \
--conf spark.yarn.maxAppAttempts=4 `# Increase max application master attempts (needs to be <= yarn.resourcemanager.am.max-attempts in YARN, which defaults to 2) (Default: yarn.resourcemanager.am.max-attempts)` \
--conf spark.yarn.am.attemptFailuresValidityInterval=1h `# Attempt counter considers only the last hour (Default: (none))` \
--conf spark.yarn.max.executor.failures=$((8 * ${num_executors})) `# Increase max executor failures (Default: max(numExecutors * 2, 3))` \
--conf spark.yarn.executor.failuresValidityInterval=1h `# Executor failure counter considers only the last hour` \
--conf spark.task.maxFailures=8 \
--conf spark.speculation=false \
/home//runscripts/production.jar

注意:主题领域有几个问题,但没有公认的答案,或者答案与预期的解决方案不同。 Running a Spark application on YARN, without spark-submit How to configure automatic restart of the application driver on Yarn

这个问题探讨了 YARN 和 Spark 范围内的可能解决方案。

最佳答案

只是一个想法!

让我们将脚本文件(包含上述脚本)称为 run_spark_job.sh

尝试在脚本末尾添加这些语句:

return_code=$?

if [[ ${return_code} -ne 0 ]]; then
echo "Job failed"
exit ${return_code}
fi

echo "Job succeeded"
exit 0

让我们有另一个脚本文件 spark_job_runner.sh,我们从中调用上面的脚本。例如,

./run_spark_job.sh
while [ $? -ne 0 ]; do
./run_spark_job.sh
done

基于 YARN 的方法:更新 1:这个链接将是一个很好的阅读。它讨论了 YARN REST API 以提交和跟踪:https://community.hortonworks.com/articles/28070/starting-spark-jobs-directly-via-yarn-rest-api.html

更新 2:此链接显示如何使用 Java 将 spark 应用程序提交到 YARN 环境:https://github.com/mahmoudparsian/data-algorithms-book/blob/master/misc/how-to-submit-spark-job-to-yarn-from-java-code.md

基于 Spark 的程序化方法:

How to use the programmatic spark submit capability

YARN 基于 Spark 的配置方法:

用于重新启动的 YARN 模式唯一 spark 参数是 spark.yarn.maxAppAttempts 并且它不应超过 YARN 资源管理器参数 yarn.resourcemanager.am .max-attempts

官方文档摘录https://spark.apache.org/docs/latest/running-on-yarn.html

The maximum number of attempts that will be made to submit the application.

关于hadoop - 在失败或中止时重新运行 Spark 作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46999601/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com