0
0
AirflowHow-ToBeginner ยท 3 min read

How to Configure Executor in Apache Airflow

To configure the executor in Airflow, edit the airflow.cfg file and set the executor option under the [core] section to your desired executor type like SequentialExecutor, LocalExecutor, or KubernetesExecutor. Then restart the Airflow services to apply the change.
๐Ÿ“

Syntax

The executor is configured in the airflow.cfg file under the [core] section. The key is executor and its value defines how tasks run.

  • SequentialExecutor: Runs tasks one at a time, good for testing.
  • LocalExecutor: Runs tasks in parallel on the same machine.
  • KubernetesExecutor: Runs tasks in Kubernetes pods for scalability.
ini
[core]
executor = LocalExecutor
๐Ÿ’ป

Example

This example shows how to set the executor to LocalExecutor in the airflow.cfg file. This allows Airflow to run multiple tasks in parallel on the same machine.

ini
[core]
executor = LocalExecutor
Output
After saving this change and restarting Airflow, tasks will run in parallel locally.
โš ๏ธ

Common Pitfalls

Common mistakes include:

  • Not restarting Airflow after changing the executor, so changes don't apply.
  • Using SequentialExecutor in production, which limits parallelism.
  • Misconfiguring executors that require extra setup, like KubernetesExecutor needing a Kubernetes cluster.
ini
[core]
executor = SequentialExecutor  # Wrong for production

# Correct for production with parallelism
executor = LocalExecutor
๐Ÿ“Š

Quick Reference

ExecutorDescriptionUse Case
SequentialExecutorRuns tasks one at a timeTesting or simple setups
LocalExecutorRuns tasks in parallel on one machineSmall to medium production
CeleryExecutorDistributes tasks across workersLarge scale with multiple machines
KubernetesExecutorRuns tasks in Kubernetes podsCloud-native scalable setups
โœ…

Key Takeaways

Set the executor in airflow.cfg under the [core] section using the executor key.
Restart Airflow services after changing the executor to apply changes.
Choose SequentialExecutor for testing and LocalExecutor or others for production.
Executors like KubernetesExecutor require additional infrastructure setup.
Avoid using SequentialExecutor in production to enable parallel task execution.