Airflow Performance Tuning

Performance tuning makes Airflow start tasks sooner, run more work together, and use fewer resources. Small configuration changes often cut delays from minutes to seconds. A clear view of where time goes guides every change.

The Highway Picture

Picture a highway with limited lanes. Too few lanes cause traffic jams. Too many cars at once cause crashes. Tuning sets the right number of lanes and the right number of cars. Airflow has several limits that work like lanes.

 Level                     Limit
 ───────────────────────────────────────────────────
 Whole installation     →  parallelism
 One DAG                →  max_active_tasks_per_dag
 One DAG's runs         →  max_active_runs_per_dag
 One resource           →  pools
 One task type          →  task concurrency

Concurrency Settings

SettingWhat It Limits
parallelismMaximum running tasks across the whole installation
max_active_tasks_per_dagRunning tasks inside one DAG
max_active_runs_per_dagSimultaneous runs of one DAG
max_active_tis_per_dagRunning copies of one task
poolTasks that share one resource

Set global values in airflow.cfg under [core], and set DAG values inside the DAG definition.

with DAG(
    "orders_daily",
    start_date=datetime(2024, 1, 1),
    schedule="@daily",
    max_active_runs=1,
    max_active_tasks=8,
    catchup=False,
) as dag:
    ...

Pools

A pool gives a named resource a fixed number of slots. Create a pool in Admin, then assign tasks to it.

load = PythonOperator(
    task_id="load_warehouse",
    python_callable=load_data,
    pool="warehouse",
    pool_slots=1,
)

A pool with five slots lets only five warehouse tasks run together. Extra tasks wait in the queue, which protects the database from overload.

Speed Up DAG Parsing

The scheduler parses every DAG file on a timer. Slow files delay every task. Three changes help most:

  • Move network calls and database queries out of the top level of the file.
  • Import heavy libraries inside task functions.
  • Split one giant file into several smaller ones.
def train():
    import pandas as pd      # loaded only when the task runs
    ...

Tune the Scheduler

SettingEffect
min_file_process_intervalSeconds between parses of the same file
dag_dir_list_intervalSeconds between scans for new files
parsing_processesNumber of parallel parsing processes
max_tis_per_queryTasks the scheduler handles per cycle

Raise the parse interval when you have many stable DAGs. Raise the process count when you have many files and spare CPU.

Use Waiting Tasks Wisely

Sensors in poke mode block worker slots. Switch them to reschedule mode or use deferrable operators. Slots then return to real work.

Keep the Database Healthy

Every run adds rows to the metadata database. Millions of old rows slow the UI and the scheduler.

airflow db clean --clean-before-timestamp "2024-01-01" --yes

Schedule this cleanup on a regular basis. Use PostgreSQL for production, and keep SQLite for tests.

Right-Size the Workers

 Many small tasks    →  many small workers, high worker_concurrency
 Few heavy tasks     →  fewer large workers, low worker_concurrency
 Spiky workloads     →  KubernetesExecutor, one pod per task

Measure Before You Change

  1. Open the Gantt view of a slow run and spot the long bars and the gaps.
  2. Long bars mean slow task code. Gaps mean scheduling or capacity delays.
  3. Change one setting at a time and compare the next run.

Key Takeaways

  • Concurrency limits work at global, DAG, and task levels.
  • Light DAG files speed up the scheduler.
  • Pools protect shared resources.
  • Database cleanup and right-sized workers keep Airflow responsive.