Skip to content

AIP-61 - Scheduler job: main loop and event processing for multi executors - #40017

Merged
o-nikolas merged 1 commit into
apache:mainfrom
aws-mwaa:onikolas/aip-61/main_scheduler_loop_not_per_exec
Jul 10, 2024
Merged

o-nikolas merged 1 commit into
apache:mainfrom
aws-mwaa:onikolas/aip-61/main_scheduler_loop_not_per_exec

Conversation

@o-nikolas

Copy link
Copy Markdown
Contributor

This change delivers the main portion of hybrid executors to the Airflow scheduler. Each loop the query for TIs from the DB may contain TIs tagged with any executor (or no specific executor, which means run on the default executor). We now sort those TIs by executor after the query and queue tasks for the executors which have space to take on more TIs.

We now also heartbeat all executors and process their events each scheduler loop.

This is a second version of these changes which are fairly concise in source code diff. Most of the PR is testing changes/additions.

Benchmarking

Here is some benchmarking to show performance of the scheduler with the changes.
Please refer to the orange (90th quantile) and yellow/green (50th quantile) plots, blue is the 99th quantile which leads to very spikey data.

Important plots include the bottom two (which are the critical sections of the main loop), as well as the loop duration as a whole.

Baseline from main

baseline_1

baseline_2

Hybrid Scheduler

hybrid_1

hybrid_2

Method:

This data was collected while running the below DAG. Leveraging the standard Airflow metrics along with some metric math (for example the scheduler loop time minus the executor heartbeat time, middle-left plot), using statsd and grafana within the same breeze environment for all data collection.

More samples were taken than just the runs included above, but a representative selection was chosen.

DAG code:

from datetime import datetime
from airflow.models import DAG
from airflow.operators.bash import BashOperator
from airflow.operators.empty import EmptyOperator

initial_scale = 4
max_scale = 5
scaling_factor = 2
dag_id = "for_loop_tasks_80"
with DAG(
    dag_id=dag_id,
    catchup=False,
    schedule_interval="@once",
    start_date=datetime(2023, 1, 1),
    max_active_runs=1,
) as dag:
    start = EmptyOperator(task_id="start")
    end = EmptyOperator(task_id="end")
    for i in range(80):
        task = BashOperator(task_id=f"task_{i}", bash_command="date")
        start >> task >> end

^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

Comment thread airflow/jobs/scheduler_job_runner.py Resolved
@uranusjr

uranusjr commented Jun 3, 2024

Copy link
Copy Markdown
Member

Do we still need slots_available after this? We should remove or deprecate it if not.

@o-nikolas

Copy link
Copy Markdown
Contributor Author

Do we still need slots_available after this? We should remove or deprecate it if not.

Nope! We still use this field in places, even after these changes. So no need to deprecate :)

Comment thread airflow/jobs/scheduler_job_runner.py Resolved
Comment thread airflow/jobs/scheduler_job_runner.py Resolved
@o-nikolas

Copy link
Copy Markdown
Contributor Author

@potiuk @uranusjr any time to have a/another look? @dstandish maybe?

Comment thread airflow/jobs/scheduler_job_runner.py Resolved
Comment thread airflow/jobs/scheduler_job_runner.py Resolved
Comment thread airflow/jobs/scheduler_job_runner.py Resolved
Comment thread airflow/jobs/scheduler_job_runner.py Resolved
@o-nikolas o-nikolas added full tests needed We need to run full set of tests for this PR to merge upgrade to newer dependencies If set, upgrade to newer dependencies is forced labels Jun 20, 2024
Comment thread airflow/jobs/scheduler_job_runner.py Resolved
Comment thread airflow/jobs/scheduler_job_runner.py Resolved
Comment thread airflow/jobs/scheduler_job_runner.py Resolved
Comment thread airflow/jobs/scheduler_job_runner.py Resolved
Comment thread airflow/jobs/scheduler_job_runner.py Resolved
@o-nikolas o-nikolas removed the full tests needed We need to run full set of tests for this PR to merge label Jun 21, 2024
@o-nikolas o-nikolas removed the upgrade to newer dependencies If set, upgrade to newer dependencies is forced label Jun 21, 2024
Comment thread airflow/jobs/scheduler_job_runner.py Resolved
Comment thread airflow/jobs/scheduler_job_runner.py Resolved
Comment thread airflow/jobs/scheduler_job_runner.py Resolved
Comment thread airflow/jobs/scheduler_job_runner.py Resolved
Comment thread airflow/jobs/scheduler_job_runner.py Resolved
@o-nikolas
o-nikolas force-pushed the onikolas/aip-61/main_scheduler_loop_not_per_exec branch from 4d81258 to 8ac8b2d Compare June 28, 2024 19:24
@dstandish

Copy link
Copy Markdown
Contributor

ship it @o-nikolas

@kaxil kaxil added this to the Airflow 2.10.0 milestone Jun 29, 2024
@o-nikolas
o-nikolas force-pushed the onikolas/aip-61/main_scheduler_loop_not_per_exec branch from 75e7e3a to d5031a4 Compare July 2, 2024 17:55

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice discussions and conclusions. Ship it indeed!

@kaxil

kaxil commented Jul 9, 2024 •

Copy link
Copy Markdown
Member

@o-nikolas Can you merge this one? -- looks like we are good to go

@o-nikolas

Copy link
Copy Markdown
Contributor Author

Can you merge this one? -- looks like we are good to go

@kaxil Yupp, I plan to merge both PRs tomorrow morning!

This change delivers the main portion of hybrid executors to the Airflow
scheduler. Each loop the query for TIs from the DB may contain TIs
tagged with a particular executor. We now filter those after the query
by which executors have space to take on more TIs and then sort them
into buckets per executor and send them to each executor to be executed.
We now also heartbeat all executors and process their events each
scheduler loop.
@o-nikolas
o-nikolas force-pushed the onikolas/aip-61/main_scheduler_loop_not_per_exec branch from 794802f to f60ee23 Compare July 10, 2024 17:23
@o-nikolas
o-nikolas merged commit 8e2b198 into apache:main Jul 10, 2024
@o-nikolas
o-nikolas deleted the onikolas/aip-61/main_scheduler_loop_not_per_exec branch July 10, 2024 18:06
@utkarsharma2 utkarsharma2 added the type:new-feature Changelog: New Features label Jul 12, 2024
romsharon98 pushed a commit to romsharon98/airflow that referenced this pull request Jul 26, 2024
…ache#40017)

This change delivers the main portion of hybrid executors to the Airflow
scheduler. Each loop the query for TIs from the DB may contain TIs
tagged with a particular executor. We now filter those after the query
by which executors have space to take on more TIs and then sort them
into buckets per executor and send them to the appropriate executor to be
executed. We now also heartbeat all executors and process their events
each scheduler loop.
@ephraimbuddy ephraimbuddy added changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) and removed type:new-feature Changelog: New Features labels Aug 9, 2024
RyuSA added a commit to RyuSA/khi that referenced this pull request Apr 10, 2025
RyuSA added a commit to GoogleCloudPlatform/khi that referenced this pull request Apr 10, 2025
* Suppress verbose error output

This reduces unnecessary standard output.

* fix scheduler log parser missing "TaskInstance Finished ... executor=FOO, ..."

apache/airflow#40017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Executors-core LocalExecutor & SequentialExecutor area:hybrid-executors AIP-61 area:scheduler changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants