airflow 에서 Task 를 병렬 실행 할 때,

Task 의 수를 조절하는 옵션값들이 헷갈려서 정리함

2022.05.07

 

 

parallelism [공식 문서]

 

(모든 DAG 내에서 실행되는) 최대 task 수

예를 들어 parallelism 이 3이면, 모든 실행중인 DAG 내의 수 많은 task 들 중 단 3개의 task 만 실행됨

여기서 말하는 '실행되는 task'는 'running 상태인 task' 를 의미함

이 값은 scheduler 나 worker 수와 관계 없음

 

parallelism 이 0이면 모든 DAG 내의 task 들이 제한없이 실행됨

task 가 실행된다는 말은, executor 가 실행된다는 말이 됨

executor 는 process 를 하나 생성한 후 그 위에서 실행되는데

이 말인 즉슨, executor 가 무수히 실행될 때 시스템의 자원(cpu, mem)을 가능한대로 가져다가 사용한다는 말이 됨

따라서 parallelism 은 0 이상인 것이 좋음

병렬성을 최대로 활용하기 위해서, parallelism 은 "시스템 cpu 코어수 -1 개"로 설정해주는 것이 좋다고 함

(이것을 CPU-bound 라고 부름)

 

This defines the maximum number of task instances that can run concurrently in Airflow regardless of scheduler count and worker count. Generally, this value is reflective of the number of task instances with the running state in

 

기본값 : 32

환경변수명 : AIRFLOW__CORE__PARALLELISM

 

 

 

max_active_runs_per_dag [공식 문서]

 

최대 활성 DAG 수

이 옵션값 수 만큼의 DAG 만이 자신들의 task 를 실행할 수 있음

예를 들어 max_active_runs_per_dag 가 1이면,

DAG 가 아무리 많아도 한 타임라인에 실행되는 DAG 의 수는 1개가 됨

max_active_runs_per_dag 가 2이면,

DAG 가 아무리 많아도 한 타임라인에 실행되는 DAG 의 수는 2개가 됨

 

The maximum number of active DAG runs per DAG. The scheduler will not create more DAG runs if it reaches the limit. This is configurable at the DAG level with max_active_runs, which is defaulted as max_active_runs_per_dag.

기본값 : 16
환경변수명 : AIRFLOW__CORE__MAX_ACTIVE_RUNS_PER_DAG

 

 

max_active_tasks_per_dag [공식 문서]

 

(하나의 DAG 내에서 실행되는) 최대 task 수

예를 들어 max_active_tasks_per_dag 값이 2면,

하나의 DAG 내에 아무리 많은 task 들이 있다고 해도 단 2개의 task 만 실행 가능

(DAG 가 5개인 상황에서 max_active_tasks_per_dag 값이 2면,

모든 DAG 에서 실행중인 task 는 10개 이하가 됨. 5*2=10

'이하'인 이유는, 어떤 DAG 는 task 가 1개 이하일지도 모르기 때문)

 

2.2.0 버전 이후부터 새롭게 등장

dag_concurrency 옵션값이 deprecated 되고, 대신 max_active_tasks_per_dag 가 사용됨

 

The maximum number of task instances allowed to run concurrently in each DAG. To calculate the number of tasks that is running concurrently for a DAG, add up the number of running tasks for all DAG runs of the DAG. This is configurable at the DAG level with max_active_tasks, which is defaulted as max_active_tasks_per_dag.

An example scenario when this would be useful is when you want to stop a new dag with an early start date from stealing all the executor slots in a cluster.

 

기본값 : 16

환경변수값 : AIRFLOW__CORE__MAX_ACTIVE_TASKS_PER_DAG

 

 

 

 

 

+ Recent posts