Skip to content

UI - N+1 Calls in the Tasks Tab #59598

@nclaeys

Description

@nclaeys

Apache Airflow version

Other Airflow 3 version (please specify below)

If "Other Airflow 3 version" selected, which one?

3.1.3

What happened?

When browsing the Airflow UI and looking at the tasks tab, it triggers n+1 queries for every task in your dag. If your dag has 200+ tasks, it does 200+ queries which should not be the case. The first 30 might succeed but afterwards the calls fail due to a sqlalchemy timeout.

problematic UI path: <airflowBaseUrl>/airflow/dags/<some-dag>/tasks

UI:
Image

Logs of the api-server where only 1 user is using it:

api-server.log

What you think should happen instead?

Visualizing and working with dags that have many tasks should work. The UI should not do a call for every task in the dag as that can never scale. Redesign of parts of the UI might be needed.

I saw in the issues that work has been done to fix n+1 queries (#57561), but it seems this path has been missed.

How to reproduce

Create a dag with 200 tasks in it and make sure there are a couple of dagruns (5 or so).
Go to the dag (gridview) and then click on tasks tab on the right panel. See previous screenshot.
Check the logs and you will see that 200 calls are triggered to fetch task instances for every task in the dag.

The 200 calls done against the backend look as follows:
<airflowBaseUrl>/airflow/api/v2/dags/<some-dag>/dagRuns/~/taskInstances?task_id=<some-task>&limit=14&order_by=-run_after

Operating System

ubuntu

Versions of Apache Airflow Providers

apache-airflow==3.1.3
apache-airflow-core==3.1.3
apache-airflow-providers-cncf-kubernetes==10.6.0
apache-airflow-providers-common-compat==1.9.0
apache-airflow-providers-common-io==1.6.5
apache-airflow-providers-common-sql==1.29.0
apache-airflow-providers-openlineage==2.9.0
apache-airflow-providers-postgres==6.4.1
apache-airflow-providers-smtp==2.3.2
apache-airflow-providers-standard==1.9.2
apache-airflow-task-sdk==1.1.3

Deployment

Other Docker-based deployment

Deployment details

We deploy airflow on kubernetes similarly to the officical Airflow helm chart but than using our own operator.

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions