---
title: "hadoop job推测执行"
author: "essen"
date: "2013-04-08T19:32:25Z"
tags: []
categories: ["互联网"]
slug: "hadoop-job"
draft: false
lastmod: "2013-04-08T19:32:25Z"
id: 1844007
url: "https://essen.iteye.com/blog/1844007"
---

## 什么是推测执行？

所谓的推测执行，就是当所有task都开始运行之后，Job Tracker会统计所有任务的平均进度，如果某个task所在的task node机器配置比较低或者CPU load很高（原因很多），导致任务执行比总体任务的平均执行要慢，此时Job Tracker会启动一个新的任务（duplicate task），原有任务和新任务哪个先执行完就把另外一个kill掉

## 怎么配置推测执行参数？

推测执行需要设置Job的两个参数：

    mapred.map.tasks.speculative.execution

    mapred.reduce.tasks.speculative.execution

两个参数的默认值均为true.

## 推测执行调度策略是什么？

推测执行逻辑：

// 1. Check bottom up for speculative tasks from the running cache

// 2. Check breadth-wise for speculative tasks

// 3. Check non-local tips for speculation

关键逻辑比较执行时间超过平均task执行时间某个百分比，定位为需要推测执行的job

```
//SPECULATIVE_GAP =0.2
(averageProgress - progress >= SPECULATIVE_GAP ) && (currentTime - startTime >= SPECULATIVE_LAG
```

 

P.s. 看源码的时候看到调度map task的策略，故记下。

JobInProgress添加新的maptask的调度策略

// When scheduling a map task:

//  0) Schedule a failed task without considering locality

//  1) Schedule non-running tasks

//  2) Schedule speculative tasks

//  3) Schedule tasks with no location information

map task调度策略：

1、失败的task，不考虑地点

2、没跑过的task

3、推测执行的task

4、nonLocalRunningMaps中的task