Hadoop 任务超时自动结束任务

2019-03-28 13:33|来源: 网络

对于一些线上任务,如果在一定时间没有结束,下一时刻任务会启动,那么上一时刻的任务将变得没有意义,但是仍然会占用Hadoop资源,所以需要程序检测并自动结束。

示例:

hadoop jar /opt/hadoop/mapred/contrib/streaming/hadoop-0.21.0-streaming.jar \
  -D mapreduce.job.name="jobname" \
  -D mapreduce.job.reduces="100" \
  -D mapreduce.job.map.capacity="500" \
  -D mapreduce.job.reduce.capacity="100" \
  -mapper "$mapper"  \
  -reducer "$reducer" \
  -input "${INPUT}" \
  -output "${OUTPUT}"  \
  -file "${mapper_file}" \
  -file ${reducer_file} \
  -jobconf mapred.min.split.size=536870912 \
  -partitioner org.apache.hadoop.mapred.lib.KeyFieldBasedPartitioner 1>log 2>&1 &
PID=$!
ps_status=`ps -ef |grep $PID|grep -v grep|wc -l`
echo "$ps_status"

KILL_CMD=`sed /-Dmapreduce.jobtracker.address=${tracker_name}:${port}/p '-n' log | awk '{print $5" "$6" "$7" "$8" "$9}'`
while [ "X$KILL_CMD" = "X" ]
do
  echo "wait for kill command for a while."
  sleep 1s


   KILL_CMD=`sed /-Dmapreduce.jobtracker.address=${tracker_name}:${port}/p '-n' log | awk '{print $5" "$6" "$7" "$8" "$9}'`
done
echo $KILL_CMD


wait_time=1
while [ 1 ]
do
   ps_status=`ps -ef |grep $PID|grep -v grep|wc -l`
   if [ $ps_status -ge 1 ]; then
      echo "hadoop is running"
      wait_time=`expr $wait_time + 1`
   else
     echo "hadoop job finished."
     break
   fi 

   if [ $wait_time -ge 60 ]; then       #等待5分钟,如果5分钟内任务没有结束,就结束该任务
      echo "timeout..."
      echo "[exec]$KILL_COMMAND"
      $KILL_COMMAND
      break
   fi 
   sleep 5s
done

exit 0

相关问答

更多
  • 是的, BigQuery Hadoop连接器自动与Dataproc集群一起部署。 Dataproc版本详细信息页面列出了每个Dataproc版本中包含哪个版本的Google Cloud Platform连接器,包括BigQuery连接器。 Yes, the BigQuery Hadoop connector is automatically deployed with Dataproc clusters. The Dataproc version detail page lists which versio ...
  • 这不可能。 因为您无法访问设置中的记录并清理mapper和reducer的任务。 在hdfs之外,执行作业的唯一方法是使用本地文件系统输入/输出。 This is not possible. Because you wont have access to the records in setup and clean up tasks of mapper and reducer. Out of hdfs, the only way to execute the jobs is to input/output ...
  • 您的作业实际上已终止,但只有在任务ID显示3次失败的地图任务尝试之后: attempt_201302270945_0181_r_000000_ 0 attempt_201302270945_0181_r_000000_ 1 attempt_201302270945_0181_r_000000_ 2 您可以通过将参数 mapred.map.max.attempts设置为1或使用JobConf#setMaxMapAttempts(int)JobConf#setMaxMapAttempts来限制每个任务的最大尝试 ...
  • Hadoop有asm 3.2而我使用的是ASM 5.在ASM5中,ClassVisitor是一个超类,而在3.2中它是一个接口。 出于某种原因,错误是Throwable(信任Shevek),catch块只捕获异常。 任何hadoop日志都没有捕获throwable错误。 因此,调试非常困难。 使用jar jar链接修复asm版本问题,现在一切正常。 如果你正在使用Hadoop并且某些东西不起作用并且没有日志显示任何错误,那么请尝试抓住Throwable。 阿伦 Hadoop had asm 3.2 and ...
  • 你用hadoop jar 运行你的jar。 这会自动设置所有内容。 You run your jar using hadoop jar . This sets up everything automatically.
  • 我不相信推测执行时间目前是可配置的。 另一方面,可能没有必要调整它。 推测执行意味着让您摆脱缓慢运行的任务(通常是由于硬件性能下降)。 如果你有可用的群集资源,那么spec exec正在进行中,让它这样做有什么害处? 请注意,对于中等或较大尺寸的作业,分钟不被视为“重要”,并且超出正常水平。 值得注意的是,虽然mapper spec exec几乎总是很好并且系统开销很低,但是reducer spec exec可能会受到伤害并且可能应该被禁用。 理由是,如果映射器进展缓慢并且存在数据为本地(正常)的可用资源, ...
  • 默认情况下,Hadoop将使用本地模式。 您可能需要在$HADOOP_HOME/conf/core-site.xml中将fs.default.name设置为hdfs://localhost.localdomain:8020/ 。 为此,请将其添加到core-site.xml : fs.default.name hdfs://localhost.localdomain:8020/ Accumulo ...
  • hadoop 0.20不支持这个,请阅读本期https://issues.apache.org/jira/browse/HADOOP-6889 hadoop 0.20 doesn't support this, please read this issue https://issues.apache.org/jira/browse/HADOOP-6889
  • 代码表明它被称为fs.trash.interval 。 编辑:对不起,误解了这个问题。 更空的实现本身就在这里 ,我们可以看到相关的常量似乎是FS_TRASH_CHECKPOINT_INTERVAL_KEY 。 在这里看到的关键是fs.trash.checkpoint.interval 。 编辑:最后在这里找到了xml conf条目。 The code suggests it is called fs.trash.interval. EDIT: Sorry, misunderstood the questi ...
  • 我猜你没有正确设置,请按照下列说明: vi $ HOME / .bashrc将以下行放在文件的末尾:(将hadoop home更改为你的) # Set Hadoop-related environment variables export HADOOP_HOME=/usr/local/hadoop # Set JAVA_HOME (we will also configure JAVA_HOME directly for Hadoop later on) export JAVA_HOME=/u ...