Add max_active_tis_per_dagrun for Dynamic Task Mapping#29094
Conversation
…o schedule the dagrun
max_active_tis_per_dagrun for Dynamic Task Mappingmax_active_tis_per_dagrun for Dynamic Task Mapping
|
The PR is ready for review, I tried to cover all the changes in my tests. import pendulum
import time
from airflow.decorators import dag, task
@dag(
dag_id='max_active_tis_per_dagrun',
default_args={},
start_date=pendulum.datetime(2021, 1, 1, tz="UTC"),
schedule=None
)
def processing_dag():
@task
def get_numbers():
return list(range(20))
@task(max_active_tis_per_dagrun=2)
def process(number):
print(number)
time.sleep(5)
numbers = get_numbers()
process.expand(number=numbers)
my_dag = processing_dag()You can trigger 4 DAG runs via the UI, and check how many mapped task will be running in parallel in each DAG run. |
uranusjr
left a comment
There was a problem hiding this comment.
Looks good to me in general, with some nitpicks.
* add max_active_tis_per_dagrun param to BaseOperator * set has_task_concurrency_limits when max_active_tis_per_dagrun is not None * check if max_active_tis_per_dagrun is reached in the task deps * check if all the tasks have None max_active_tis_per_dagrun before auto schedule the dagrun * check if the max_active_tis_per_dagrun is reached before queuing the ti * check max_active_tis_per_dagrun in backfill job * fix current tests and ensure everything is ok before adding new tests * refacto TestTaskConcurrencyDep * fix a bug in TaskConcurrencyDep * test max_active_tis_per_dagrun in TaskConcurrencyDep * tests max_active_tis_per_dagrun in TestTaskInstance * test dag_file_processor with max_active_tis_per_dagrun * test scheduling with max_active_tis_per_dagrun on different DAG runs * test scheduling mapped task with max_active_tis_per_dagrun * test max_active_tis_per_dagrun with backfill CLI * add new starved_tasks filter to avoid affecting the scheduling perf * unify the usage of TaskInstance filters and use TI * refacto concurrecy map type and create a new dataclass * move docstring to ConcurrencyMap class and create a method for default_factory * move concurrency_map creation to ConcurrencyMap class * replace default dicts by counters * replace all default dicts by counters in the scheduler_job_runner module * suggestions from review
|
@hussein-awala, in your example for me always one task from |
|
Could you provide the dag and the task configurations? |
|
airflow dags details example_dag: task: |
|
it is pretty much the same as example here: |
|
I guess my issue because of |
|
You have 3 queued TIs so everything is fine, and yes, with
|



closes: #29084
This PR adds a new operator parameter
max_active_tis_per_dagrunto control the number of task instances of the task can be running in parallel in the same Dag Run.This conf is useless for the normal tasks when the number of task instances of the task is always <= 1 in the same DAG run, but very useful and important for the Dynamic Task Mapping to control its parallelism in each different DAG run.