buhuipao commented on a change in pull request #8259: [AIRFLOW-XXX] Optimize
airflow scheduler
URL: https://github.com/apache/airflow/pull/8259#discussion_r407307853
##########
File path: airflow/jobs.py
##########
@@ -1644,26 +1738,31 @@ def _execute_helper(self, processor_manager):
# If a task instance is up for retry but the corresponding DAG
run
# isn't running, mark the task instance as FAILED so we don't
try
# to re-run it.
- self._change_state_for_tis_without_dagrun(simple_dag_bag,
- [State.UP_FOR_RETRY],
- State.FAILED)
+ ret = self._change_state_for_tis_without_dagrun(simple_dag_bag,
+
[State.UP_FOR_RETRY],
+ State.FAILED)
+ if not ret:
+ continue
# If a task instance is scheduled or queued, but the
corresponding
# DAG run isn't running, set the state to NONE so we don't try
to
# re-run it.
- self._change_state_for_tis_without_dagrun(simple_dag_bag,
- [State.QUEUED,
- State.SCHEDULED],
- State.NONE)
-
+ ret = self._change_state_for_tis_without_dagrun(simple_dag_bag,
+ [State.QUEUED,
+
State.SCHEDULED],
+ State.NONE)
+ if not ret:
+ continue
self._execute_task_instances(simple_dag_bag,
(State.SCHEDULED,))
# Call heartbeats
self.log.info("Heartbeating the executor")
self.executor.heartbeat()
- # Process events from the executor
- self._process_executor_events(simple_dag_bag)
+ # Process all events from the executor
+ full_simple_dag_bag = SimpleDagBag(self.full_simple_dags.values())
+ self.executor_events =
self._process_executor_events(full_simple_dag_bag)
Review comment:
> Your change is targeted at Airflow 1.9, is that correct? Plus, please
describe your change.
**Background**: Our team has been using Airflow 1.9 for two years. We use it
as the scheduler of our deploy system, but when the number of dags we need to
schedule at the same time exceeds 300, the task scheduling delay of Dag is no
longer stable, sometimes More than 1 minute.
So I made improvements and fixes to the 1.9 version of Airflow. The detailed
improvement information is as follows (same as the [update
log](https://github.com/apache/airflow/pull/8259/files/edc04002ea6605b529088dc4d58e8631bec47577#diff-bb7ee25332d5fdca3ead2f545d72b359)):
1. Added a feedback event mechanism to the scheduler to make the task
scheduling delay stable at 3s;
2. Solved the problem of db deadlock caused by worker and scheduler updating
task_instance at the same time (this will cause the scheduler to exit
abnormally);
3. In order to improve the availability of the scheduler, I used distributed
locks to add a hot standby function to the scheduler.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services