Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Local and Sequential Executors to Doc #8084

Merged
merged 8 commits into from
Apr 3, 2020
7 changes: 6 additions & 1 deletion airflow/executors/celery_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""Celery executor."""
"""CeleryExecutor

.. seealso::
For more information on how the CeleryExecutor works, take a look at the guide:
:ref:`executor:CeleryExecutor`
"""
import logging
import math
import os
Expand Down
8 changes: 7 additions & 1 deletion airflow/executors/dask_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""Dask executor."""
"""
DaskExecutor

.. seealso::
For more information on how the DaskExecutor works, take a look at the guide:
:ref:`executor:DaskExecutor`
"""
import subprocess
from typing import Any, Dict, Optional

Expand Down
7 changes: 5 additions & 2 deletions airflow/executors/debug_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
# specific language governing permissions and limitations
# under the License.
"""
This module contains DebugExecutor that is a single
process executor meaning it does not use multiprocessing.
DebugExecutor

.. seealso::
For more information on how the DebugExecutor works, take a look at the guide:
:ref:`executor:DebugExecutor`
"""

import threading
Expand Down
8 changes: 7 additions & 1 deletion airflow/executors/kubernetes_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""Kubernetes executor"""
"""
KubernetesExecutor

.. seealso::
For more information on how the KubernetesExecutor works, take a look at the guide:
:ref:`executor:KubernetesExecutor`
"""
import base64
import datetime
import hashlib
Expand Down
30 changes: 5 additions & 25 deletions airflow/executors/local_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,11 @@
# specific language governing permissions and limitations
# under the License.
"""
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:
1. Unlimited Parallelism (self.parallelism == 0): In this strategy, LocalExecutor will
spawn a process every time `execute_async` is called, that is, every task submitted to the
LocalExecutor will be executed in its own process. Once the task is executed and the
result stored in the `result_queue`, the process terminates. There is no need for a
`task_queue` in this approach, since as soon as a task is received a new process will be
allocated to the task. Processes used in this strategy are of class LocalWorker.

2. Limited Parallelism (self.parallelism > 0): In this strategy, the LocalExecutor spawns
the number of processes equal to the value of `self.parallelism` at `start` time,
using a `task_queue` to coordinate the ingestion of tasks and the work distribution among
the workers, which will take a task as soon as they are ready. During the lifecycle of
the LocalExecutor, the worker processes are running waiting for tasks, once the
LocalExecutor receives the call to shutdown the executor a poison token is sent to the
workers to terminate them. Processes used in this strategy are of class QueuedLocalWorker.

Arguably, `SequentialExecutor` could be thought 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.
LocalExecutor

.. seealso::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add similar annotations for other executors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

For more information on how the LocalExecutor works, take a look at the guide:
:ref:`executor:LocalExecutor`
"""
import subprocess
from multiprocessing import Manager, Process
Expand Down
8 changes: 7 additions & 1 deletion airflow/executors/sequential_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""Sequential executor."""
"""
SequentialExecutor

.. seealso::
For more information on how the SequentialExecutor works, take a look at the guide:
:ref:`executor:SequentialExecutor`
"""
import subprocess
from typing import Any, Optional

Expand Down
1 change: 1 addition & 0 deletions docs/executor/celery.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
under the License.


.. _executor:CeleryExecutor:

Celery Executor
===============
Expand Down
1 change: 1 addition & 0 deletions docs/executor/dask.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
under the License.


.. _executor:DaskExecutor:

Dask Executor
=============
Expand Down
3 changes: 3 additions & 0 deletions docs/executor/debug.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
specific language governing permissions and limitations
under the License.


.. _executor:DebugExecutor:

Debug Executor
==================

Expand Down
8 changes: 6 additions & 2 deletions docs/executor/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ full path to the module e.g. ``my_acme_company.executors.MyCustomExecutor``.

.. toctree::
:maxdepth: 1
:glob:

*
sequential
xinbinhuang marked this conversation as resolved.
Show resolved Hide resolved
debug
local
dask
celery
kubernetes
5 changes: 4 additions & 1 deletion docs/executor/kubernetes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
specific language governing permissions and limitations
under the License.

KubernetesExecutor

.. _executor:KubernetesExecutor:

Kubernetes Executor
===================

The kubernetes executor is introduced in Apache Airflow 1.10.0. The Kubernetes executor will create a new pod for every task instance.
Expand Down
49 changes: 49 additions & 0 deletions docs/executor/local.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.. Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

.. http://www.apache.org/licenses/LICENSE-2.0

.. Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.


.. _executor:LocalExecutor:

Local Executor
==============

:class:`~airflow.executors.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 will
| spawn a process every time ``execute_async`` is called, that is, every task submitted to the
| :class:`~airflow.executors.local_executor.LocalExecutor` will be executed in its own process. Once the task is executed and the
| result stored in the ``result_queue``, the process terminates. There is no need for a
| ``task_queue`` in this approach, since as soon as a task is received a new process will be
| allocated to the task. Processes used in this strategy are of class :class:`~airflow.executors.local_executor.LocalWorker`.

- | **Limited Parallelism** (``self.parallelism > 0``): In this strategy, the :class:`~airflow.executors.local_executor.LocalExecutor` spawns
| the number of processes equal to the value of ``self.parallelism`` at ``start`` time,
| using a ``task_queue`` to coordinate the ingestion of tasks and the work distribution among
| the workers, which will take a task as soon as they are ready. During the lifecycle of
| the LocalExecutor, the worker processes are running waiting for tasks, once the
| LocalExecutor receives the call to shutdown the executor a poison token is sent to the
| workers to terminate them. Processes used in this strategy are of class :class:`~airflow.executors.local_executor.QueuedLocalWorker`.

Arguably, :class:`~airflow.executors.sequential_executor.SequentialExecutor` could be thought 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 :class:`~airflow.executors.local_executor.LocalExecutor` with multiple modes.
26 changes: 26 additions & 0 deletions docs/executor/sequential.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.. Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

.. http://www.apache.org/licenses/LICENSE-2.0

.. Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.


.. _executor:SequentialExecutor:

Sequential Executor
===================

The :class:`~airflow.executors.sequential_executor.SequentialExecutor` is the default executor when you first install ``airflow``.
It is the only executor that can be used with ``sqlite`` since ``sqlite`` doesn't support multiple connections.
This executor will only run one task instance at a time. For production use case, please use other executors.