气流平行度

Airflow parallelism

本地执行器在调度任务时生成新进程。它创建的进程数是否有限制。我需要改变它。我需要知道调度程序的 "max_threads" 和 "parallelism" 在 airflow.cfg 中?

调度程序的 max_threads 是并行化调度程序的进程数。 max_threads 不能超过 cpu 计数。 LocalExecutor的parallelism是LocalExecutor应该运行的并发任务数。调度程序和 LocalExecutor 都使用 python 的多处理库来实现并行性。

并行性: 不是一个非常具有描述性的名称。描述说它为 airflow 安装设置了最大任务实例,这有点模棱两可——如果我有两个主机 运行 airflow workers,我会在两个主机上安装 airflow,所以应该是两个安装,但基于上下文 'per installation' 这里的意思是 'per Airflow state database'。我将其命名为 max_active_tasks.

dag_concurrency: 尽管名称基于评论,但这实际上是任务并发,而且是每个工作人员。我将其命名为 max_active_tasks_for_worker(per_worker 表明它是工作人员的全局设置,但我认为您可以为此设置不同值的工作人员)。

max_active_runs_per_dag:这个还不错,但由于它似乎只是匹配的 DAG kwarg 的默认值,所以最好将其反映在名称,类似于 default_max_active_runs_for_dags 那么让我们继续讨论 DAG kwargs:

concurrency:再一次,有一个像这样的通用名称,再加上并发在其他地方用于不同的东西这一事实使得这非常混乱。我称之为 max_active_tasks.

max_active_runs:这首我觉得不错。

来源:https://issues.apache.org/jira/browse/AIRFLOW-57


max_threads 让用户可以控制 cpu 的使用。它指定调度程序并行度。

现在是 2019 年,更多更新的文档已经发布。简而言之:

AIRFLOW__CORE__PARALLELISM 是可以 运行 同时跨越所有 Airflow(所有 dag 上的所有任务)

的最大任务实例数

AIRFLOW__CORE__DAG_CONCURRENCY 是单个特定 DAG

允许同时 运行 的最大任务实例数

这些文档对其进行了更详细的描述:

根据https://www.astronomer.io/guides/airflow-scaling-workers/

parallelism is the max number of task instances that can run concurrently on airflow. This means that across all running DAGs, no more than 32 tasks will run at one time.

dag_concurrency is the number of task instances allowed to run concurrently within a specific dag. In other words, you could have 2 DAGs running 16 tasks each in parallel, but a single DAG with 50 tasks would also only run 16 tasks - not 32

并且,根据 https://airflow.apache.org/faq.html#how-to-reduce-airflow-dag-scheduling-latency-in-production

max_threads: Scheduler will spawn multiple threads in parallel to schedule dags. This is controlled by max_threads with default value of 2. User should increase this value to a larger value(e.g numbers of cpus where scheduler runs - 1) in production.

不过这最后一段似乎不应该占用太多时间,因为它只是 "scheduling" 部分。不是实际的 运行ning 部分。因此,我们认为没有必要对 max_threads 进行太多调整,但 AIRFLOW__CORE__PARALLELISMAIRFLOW__CORE__DAG_CONCURRENCY 确实影响了我们。