Loading Academy Hub...
Master enterprise Airflow performance tuning: eliminating top-level code traps, optimizing `dag_dir_list_interval`, tuning scheduler parsing threads, and database connection pool sizing.
[!NOTE] Slow Airflow task execution is almost always caused by Scheduler contention resulting from heavy top-level code in DAG files.
.py file in dags/ every few seconds.requests.get(), boto3 connection, or database query in global scope stalls the scheduler parsing loop.min_file_process_interval:
.airflowignore:
.py file inside dags/ every 30 seconds (min_file_process_interval). Putting Variable.get(), boto3.client("s3").list_objects(), or PostgresHook().get_records() outside a task body executes that API call thousands of times per hour—crashing Metadata DBs and stalling DAG scheduling! Always place Variable.get(), Hooks, and heavy imports (pandas, torch, pyspark) strictly inside execute() / @task bodies (or use Jinja {{ var.value.my_key }}).Dynamic Task Mapping runs.airflow db clean (--clean-before-timestamp)—unpruned task_instance, xcom, and log tables across millions of historical runs silently slow every Scheduler query to a crawl.Review the production code, company interview Q&As, incident traces, and comprehension quiz inside this lesson.
# Enterprise Airflow Configuration (airflow.cfg) [scheduler] # Number of processes to parse DAG files concurrently parsing_processes = 8 # Minimum seconds between parsing the same DAG file (reduces CPU) min_file_process_interval = 120 # Heartbeat frequency scheduler_heartbeat_sec = 5 [core] # Maximum concurrent active task instances per worker parallelism = 64 max_active_tasks_per_dag = 16 max_active_runs_per_dag = 4 [database] # Pool size for PostgreSQL metadata database sql_alchemy_pool_size = 20 sql_alchemy_max_overflow = 10
AirflowFileProcessorTimeout: The file 'dags/finance_etl.py' took 45.2s to parse, exceeding timeout of 30s.