Nataneljpwd commented on code in PR #61769:
URL: https://github.com/apache/airflow/pull/61769#discussion_r2837206151
##########
airflow-core/src/airflow/jobs/scheduler_job_runner.py:
##########
@@ -183,15 +183,22 @@ def load(self, session: Session) -> None:
self.dag_run_active_tasks_map.clear()
self.task_concurrency_map.clear()
self.task_dagrun_concurrency_map.clear()
+ # Use one grouped query on TASK_CONCURRENCY_EXECUTION_STATES to
exclude DEFERRED from dag_run_active_tasks_map
+ #while still counting it for task-level limits.
query = session.execute(
- select(TI.dag_id, TI.task_id, TI.run_id, func.count("*"))
- .where(TI.state.in_(EXECUTION_STATES))
- .group_by(TI.task_id, TI.run_id, TI.dag_id)
+ select(TI.dag_id, TI.task_id, TI.run_id, TI.state, func.count("*"))
+ .where(TI.state.in_(TASK_CONCURRENCY_EXECUTION_STATES))
+ .group_by(TI.dag_id, TI.task_id, TI.run_id, TI.state)
)
- for dag_id, task_id, run_id, c in query:
- self.dag_run_active_tasks_map[dag_id, run_id] += c
- self.task_concurrency_map[(dag_id, task_id)] += c
- self.task_dagrun_concurrency_map[(dag_id, run_id, task_id)] += c
+ for dag_id, task_id, run_id, state, count in query:
+ # Always count towards task-level concurrency
(max_active_tis_per_dag /
+ # max_active_tis_per_dagrun), including DEFERRED.
+ self.task_concurrency_map[(dag_id, task_id)] += count
+ self.task_dagrun_concurrency_map[(dag_id, run_id, task_id)] +=
count
+ # Only count non-deferred states towards DAG-run active tasks
+ # (max_active_tasks / worker slot accounting).
+ if state != TaskInstanceState.DEFERRED:
+ self.dag_run_active_tasks_map[dag_id, run_id] += count
Review Comment:
From what I understand, it is done because the `max_active_tasks` limits
running tasks across all runs of the dag, which talks only about tasks taking
up executor slots (running state).
Yet I do agree, with you on why is this different than the other 2 limits,
as it seems like all limits are talking about running tasks, and if in some
places we consider deferred as running, why don't we do it everywhere
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]