What is Speculative Execution in Hadoop

What is the meaning of speculative execution in Hadoop? Why is it important?


Simple Definition: If a node appears to be running slow, the master node can redundantly execute another instance of the same task and first output will be taken .this process is called as Speculative execution.

Description: Hadoop uses this speculative execution to mitigate the slow-task problem. Hadoop does not wait for a task to get failed. Whenever it is seen that a task is running slow, the Hadoop platform will schedule redundant copies of that task across several nodes which do not have other work to perform. The parallel tasks are monitored. As soon as one of the parallel tasks finishes successfully, Hadoop will use its output and kill
the other parallel tasks. This process is termed as speculative execution.

Speculative Execution

For enabling and disabling speculative execution of map and reduce tasks, the configuration parameters(Boolean) are mapred.map.tasks.speculative.execution and mapred.reduce.tasks.speculative.execution. By default both are set to true.


To configure speculative execution settings in Hadoop, you can modify the following properties in the Hadoop configuration files:

  • mapreduce.map.speculative - This property controls speculative execution for map tasks. By default, it is set to true, enabling speculative execution for map tasks. You can set it to false to disable speculative execution for map tasks.
  •  mapreduce.reduce.speculative - This property controls speculative execution for reduce tasks. By default, it is set to true, enabling speculative execution for reduce tasks. You can set it to false to disable speculative execution for reduce tasks. 
  • mapreduce.job.speculative.speculative-cap-running-tasks - This property sets the threshold for speculative execution based on the percentage of running tasks. The default value is 0.1, which means speculative execution will be triggered if the running tasks exceed 10% of the total tasks. You can adjust this value based on your cluster's characteristics and performance requirements. 
  • mapreduce.job.speculative.speculative-cap-queued-tasks - This property sets the threshold for speculative execution based on the percentage of queued tasks. The default value is 1.0, which means speculative execution will be triggered if the queued tasks exceed 100% of the total tasks. Similarly, 
  • you can modify this value as per your cluster's needs. To modify these settings, locate the appropriate configuration file (such as mapred-site.xml or yarn-site.xml) 

    In your Hadoop installation directory, and add or update the respective property with the desired value. Remember to restart the Hadoop services or jobs for the changes to take effect. By adjusting these speculative execution settings, you can fine-tune the behavior of Hadoop's speculative execution feature to optimize job execution based on the characteristics of your cluster and workload.
Speculative Execution in Hadoop

Here's how speculative execution works in Hadoop:

Task Monitoring: As tasks run, Hadoop monitors their progress. If a task's progress is notably slower than the average progress of similar tasks, it's marked as a potential candidate for speculative execution.
Duplicate Task Launch: A duplicate task is launched on a different node than the original slow task. This duplicate task works on the same input data as the original task.
Race Condition: Both the original slow task and its duplicate run concurrently. Whichever task finishes first signals its completion, and its results are considered valid.
Termination: The slower task (either the original or the duplicate) is considered the "straggler" and is terminated. The faster task's results are used for further processing.