Local Executor¶
LocalExecutor runs tasks by spawning processes in a controlled fashion in different modes.
Given that BaseExecutor has the option to receive a parallelism parameter to limit the number of process spawned,
when this parameter is 0 the number of processes that LocalExecutor can spawn is unlimited.
The following strategies are implemented:
- Unlimited Parallelism (
self.parallelism == 0): In this strategy, LocalExecutor willspawn a process every timeexecute_asyncis called, that is, every task submitted to theLocalExecutorwill be executed in its own process. Once the task is executed and theresult stored in theresult_queue, the process terminates. There is no need for atask_queuein this approach, since as soon as a task is received a new process will beallocated to the task. Processes used in this strategy are of classLocalWorker. - Limited Parallelism (
self.parallelism > 0): In this strategy, theLocalExecutorspawnsthe number of processes equal to the value ofself.parallelismatstarttime,using atask_queueto coordinate the ingestion of tasks and the work distribution amongthe workers, which will take a task as soon as they are ready. During the lifecycle ofthe LocalExecutor, the worker processes are running waiting for tasks, once theLocalExecutor receives the call to shutdown the executor a poison token is sent to theworkers to terminate them. Processes used in this strategy are of classQueuedLocalWorker.
Arguably, SequentialExecutor could be thought of as a LocalExecutor with limited
parallelism of just 1 worker, i.e. self.parallelism = 1.
This option could lead to the unification of the executor implementations, running
locally, into just one LocalExecutor with multiple modes.
Note
When multiple Schedulers are configured with executor = LocalExecutor in the [core] section of your airflow.cfg, each Scheduler will run a LocalExecutor. This means tasks would be processed in a distributed fashion across the machines running the Schedulers.
One consideration should be taken into account:
Restarting a Scheduler: If a Scheduler is restarted, it may take some time for other Schedulers to recognize the orphaned tasks and restart or fail them.