Skip to content

Commit 2dd71ef

Browse files
docs: Add usage guide on how to submit some tasks locally instead of k8s (#723)
* docs: Add usage guide on how to submit some tasks locally instead of k8s * Apply suggestions from code review Co-authored-by: Nick <[email protected]> --------- Co-authored-by: Nick <[email protected]>
1 parent de3fe48 commit 2dd71ef

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

docs/modules/airflow/pages/usage-guide/using-kubernetes-executors.adoc

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,52 @@ spec:
3131
# ...
3232
----
3333

34+
== Task startup latency
35+
36+
While there are many benefits to spawning a dedicated Pod for every task, this introduces some latency.
37+
The shorter the actual task runs, the higher the effect of this latency get's on the overall DAG runtime.
38+
39+
If your tasks don't do computationally expensive things (e.g. only submit a query to a Trino cluster), you can schedule them to run locally (on the scheduler) and not spawn a Pod to reduce the DAG runtime.
40+
41+
To achieve this enable the `LocalExecutor` in your Airflow stacklet with
42+
43+
[source,yaml]
44+
----
45+
spec:
46+
webservers:
47+
envOverrides: &envOverrides
48+
# We default our tasks to KubernetesExecutor, however, tasks can opt in to using the LocalExecutor
49+
# See https://docs.stackable.tech/home/stable/airflow/usage-guide/using-kubernetes-executors/
50+
AIRFLOW__CORE__EXECUTOR: KubernetesExecutor,LocalExecutor
51+
schedulers:
52+
envOverrides: *envOverrides
53+
kubernetesExecutors:
54+
envOverrides: *envOverrides
55+
----
56+
57+
Afterwards tasks can opt-in to the `LocalExecutor` using
58+
59+
[source,python]
60+
----
61+
@task(executor="LocalExecutor")
62+
def hello_world():
63+
print("hello world!")
64+
----
65+
66+
As an alternative if *all* tasks of your DAG should run locally, you can also configure this on a DAG level (tasks can still explicitly use `KubernetesExecutor`):
67+
68+
[source,python]
69+
----
70+
with DAG(
71+
dag_id="hello_worlds",
72+
default_args={"executor": "LocalExecutor"}, # Applies to all tasks in the Dag
73+
) as dag:
74+
----
75+
76+
See the https://airflow.apache.org/docs/apache-airflow/stable/core-concepts/executor/index.html#using-multiple-executors-concurrently[official Airflow documentation] for details.
77+
78+
TIP: You might need to increase the scheduler resources, as it now runs more stuff.
79+
3480
== Logging
3581

3682
Kubernetes Executors and their respective Pods only live as long as the task they are executing.

0 commit comments

Comments
 (0)