Does raising max_tis_per_query reduce Airflow burst scheduling latency, or does it move the bottleneck to the metadata database?
0 reputation · 01 Mar 2023, 03:33 UTC
0 reputation · 01 Mar 2023, 03:33 UTC
When a large number of task instances become runnable simultaneously, Airflow's scheduler processes them in bounded batches controlled by max_tis_per_query; at low concurrency this limit is invisible, but under a burst it can introduce queueing delay. The unresolved decision is whether increasing this batch size actually improves task start latency or simply shifts the bottleneck from the scheduler loop to the metadata database, where larger queries and longer lock hold times may degrade performance. This trade-off is further complicated by version-dependent defaults that have changed across Airflow releases and may vary by executor or deployment.
Global and per-DAG concurrency limits such as parallelism and max_active_tasks_per_dag can also hold tasks in a non-runnable state, making batch-size adjustments ineffective until those limits are raised. Executor choice changes where the queue forms—Local and Celery executors queue tasks for workers, while Kubernetes Executor creates pods per task—so identical scheduler settings can yield different latency profiles. In scheduler HA deployments, multiple schedulers may compete for the same task instances, so single-scheduler behavior may not generalize.
Which combination of max_tis_per_query, concurrency limits, and executor configuration minimizes end-to-end task start latency under sustained concurrent bursts in a production-scale metadata database? How should the batch size be validated against database CPU and lock contention without relying on remembered defaults? Does the optimal setting differ between single-scheduler and HA deployments?
Raising max_tis_per_query can reduce burst scheduling latency up to a point, then it moves the bottleneck to the metadata database. The setting controls how many TaskInstance rows the scheduler fetches per DB round-trip. A larger batch means fewer scheduler loop iterations to discover runnable tasks, which lowers queueing delay during a burst. A larger batch also means larger SELECT/UPDATE payloads, longer transaction hold times and more DB CPU per query. When query execution time plus lock contention exceeds the time saved by fewer loops, end-to-end task start latency stops improving and can worsen.
max_tis_per_query is a scheduler batch size for task instance queries. Increasing it reduces the number of iterations needed to find runnable tasks.parallelism and max_active_tasks_per_dag can keep tasks in a non-runnable state. If those limits are saturated, raising the batch size does not reduce task start latency.Under a burst, the scheduler loop is often the first visible bottleneck because many TIs become runnable at once. Increasing the batch size reduces loop iterations and can improve the time from "queued" to "scheduled". The trade-off is higher per-query cost and longer row-level lock hold times in the metadata DB. The optimal point is where scheduler loop duration is balanced with DB query latency and lock wait time. Excessively high values may risk DB connection timeouts or memory pressure on the DB server.
airflow.cfg or environment variables for max_tis_per_query, parallelism, and max_active_tasks_per_dag.max_tis_per_query in small steps and re-measure.queued due to parallelism or per-DAG limits, raise those limits first.One diagnostic detail that changes the recommendation: the current scheduler deployment mode and metadata database engine. Single scheduler vs HA changes lock contention risk, and DB engine changes lock and query scaling characteristics. If you can share that, the safe tuning range can be narrowed.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.