You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/08/24 22:34:02 UTC

[GitHub] [airflow] yesemsanthoshkumar opened a new pull request #10531: Move scheduler basics documentation to Airflow docs

yesemsanthoshkumar opened a new pull request #10531:
URL: https://github.com/apache/airflow/pull/10531


   Resolves #10185 
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   ---
   **^ Add meaningful description above**
   
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] mik-laj commented on a change in pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#discussion_r475980600



##########
File path: docs/scheduler.rst
##########
@@ -18,11 +18,41 @@
 Scheduler
 ==========
 
-The Airflow scheduler monitors all tasks and DAGs, then triggers the
-task instances once their dependencies are complete. Behind the scenes,
-the scheduler spins up a subprocess, which monitors and stays in sync with all
-DAGs in the specified DAG directory. Once per minute, by default, the scheduler
-collects DAG parsing results and checks whether any active tasks can be triggered.
+The scheduler is the core component in Airflow that is responsible for monitoring all tasks and DAGs and triggers the task instances once their dependencies are complete. And for this reason, it is imperative to learn about the working of the scheduler.
+
+Scheduling in airflow involves the 3 following components.
+
+1. ``DAGFileProcessor`` - Responsible for parsing the DAG definition in a file and creating the necessary DAG runs and TaskInstances
+
+2. ``DAGFileProcessorManager`` - Responsible for listing the files in the DagBag and creating new DAGFileProcessors when required
+
+3. ``SchedulerJob`` - Responsible for sending the TaskInstances to the executor
+
+Logic behind scheduling is as follows:
+
+1. Airflow kicks off DAGFileProcessorManager along with the SchedulerJob. The DAGFileProcessorManager enumerates all the files in the DAG directory.
+
+2. The DAGFileProcessorManager spawns child processes known as DAGFileProcessor which is responsible for creating the necessary DAG Runs and TaskInstances. When it determines that task instances should run, it updates their state to ``SCHEDULED``. The number of DAGFileProcessor to spawn is configurable via ``num_runs`` in ``airflow.cfg``. TODO: Check if the configuration is correct

Review comment:
       > The number of DAGFileProcessor to spawn is configurable via ``num_runs`` in ``airflow.cfg``. TODO: Check if the configuration is correct
   
   That's not true. num_run specifies the number of scheduler loop runs.  The maximum number of DAGFileProcesses is determined by the max_threads options in the scheduler section.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] potiuk commented on pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
potiuk commented on pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#issuecomment-679421818


   1. Absolutely.
   2. Flowchart is great. Ideally, we would just need some sources for that -> for example in Draw.io export format or maybe you would like to recreate the flowchart with mermaid ? (https://mermaid-js.github.io/mermaid-live-editor/) - we have now automated mermaid generation (see images/ci/ folder. -> just enough to drop a ".mermaid" file and the chart will be generated automatically during pre-commit.
   
   @mik-laj -> I think you know most details about scheduler - would you like to review this ? 


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] ryw commented on pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
ryw commented on pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#issuecomment-685717191


   @mik-laj is this PR ready for merging, then we can add more content per your doc link above?


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] yesemsanthoshkumar commented on a change in pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
yesemsanthoshkumar commented on a change in pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#discussion_r479822072



##########
File path: docs/scheduler.rst
##########
@@ -18,11 +18,41 @@
 Scheduler
 ==========
 
-The Airflow scheduler monitors all tasks and DAGs, then triggers the
-task instances once their dependencies are complete. Behind the scenes,
-the scheduler spins up a subprocess, which monitors and stays in sync with all
-DAGs in the specified DAG directory. Once per minute, by default, the scheduler
-collects DAG parsing results and checks whether any active tasks can be triggered.
+The scheduler is the core component in Airflow that is responsible for monitoring all tasks and DAGs and triggers the task instances once their dependencies are complete. And for this reason, it is imperative to learn about the working of the scheduler.
+
+Scheduling in airflow involves the 3 following components.
+
+1. ``DAGFileProcessor`` - Responsible for parsing the DAG definition in a file and creating the necessary DAG runs and TaskInstances
+
+2. ``DAGFileProcessorManager`` - Responsible for listing the files in the DagBag and creating new DAGFileProcessors when required
+
+3. ``SchedulerJob`` - Responsible for sending the TaskInstances to the executor

Review comment:
       AFAIK, the scheduerJob is responsible for sending TI from one state to another and run them. Would `Responsible for transitioning the task instances from one state to another and executing them via a configured executor` be a better explanation here? Please correct me if I'm wrong.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] potiuk commented on pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
potiuk commented on pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#issuecomment-751293346


   Hey @yesemsanthoshkumar  - can you rebase it and lets review/close it :)


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] mik-laj commented on a change in pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#discussion_r475977864



##########
File path: docs/scheduler.rst
##########
@@ -18,11 +18,41 @@
 Scheduler
 ==========
 
-The Airflow scheduler monitors all tasks and DAGs, then triggers the
-task instances once their dependencies are complete. Behind the scenes,
-the scheduler spins up a subprocess, which monitors and stays in sync with all
-DAGs in the specified DAG directory. Once per minute, by default, the scheduler
-collects DAG parsing results and checks whether any active tasks can be triggered.
+The scheduler is the core component in Airflow that is responsible for monitoring all tasks and DAGs and triggers the task instances once their dependencies are complete. And for this reason, it is imperative to learn about the working of the scheduler.
+
+Scheduling in airflow involves the 3 following components.
+
+1. ``DAGFileProcessor`` - Responsible for parsing the DAG definition in a file and creating the necessary DAG runs and TaskInstances
+
+2. ``DAGFileProcessorManager`` - Responsible for listing the files in the DagBag and creating new DAGFileProcessors when required
+
+3. ``SchedulerJob`` - Responsible for sending the TaskInstances to the executor

Review comment:
       In the Scheduler process, we also have an executor.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] yesemsanthoshkumar commented on a change in pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
yesemsanthoshkumar commented on a change in pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#discussion_r479822281



##########
File path: docs/scheduler.rst
##########
@@ -18,11 +18,41 @@
 Scheduler
 ==========
 
-The Airflow scheduler monitors all tasks and DAGs, then triggers the
-task instances once their dependencies are complete. Behind the scenes,
-the scheduler spins up a subprocess, which monitors and stays in sync with all
-DAGs in the specified DAG directory. Once per minute, by default, the scheduler
-collects DAG parsing results and checks whether any active tasks can be triggered.
+The scheduler is the core component in Airflow that is responsible for monitoring all tasks and DAGs and triggers the task instances once their dependencies are complete. And for this reason, it is imperative to learn about the working of the scheduler.
+
+Scheduling in airflow involves the 3 following components.
+
+1. ``DAGFileProcessor`` - Responsible for parsing the DAG definition in a file and creating the necessary DAG runs and TaskInstances
+
+2. ``DAGFileProcessorManager`` - Responsible for listing the files in the DagBag and creating new DAGFileProcessors when required
+
+3. ``SchedulerJob`` - Responsible for sending the TaskInstances to the executor
+
+Logic behind scheduling is as follows:
+
+1. Airflow kicks off DAGFileProcessorManager along with the SchedulerJob. The DAGFileProcessorManager enumerates all the files in the DAG directory.
+
+2. The DAGFileProcessorManager spawns child processes known as DAGFileProcessor which is responsible for creating the necessary DAG Runs and TaskInstances. When it determines that task instances should run, it updates their state to ``SCHEDULED``. The number of DAGFileProcessor to spawn is configurable via ``num_runs`` in ``airflow.cfg``. TODO: Check if the configuration is correct

Review comment:
       So num_runs is about how many iterations the scheduler go over the DagBag, after which the scheduler shutsdown gracefully?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] stale[bot] commented on pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
stale[bot] commented on pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#issuecomment-751239996


   This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] potiuk commented on pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
potiuk commented on pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#issuecomment-679871060


   Cool @yesemsanthoshkumar ! There is no real need to do mermaid, but I found it integrating well in the development workflow when you can generate such flows from the code and it should be super easy. I would love to hear your opinion if it is worth it once you try  - but I find it working really well with sequence and flow diagrams generated from code.
   
   New term `Diagramming as a code`  :D


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] yesemsanthoshkumar commented on pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
yesemsanthoshkumar commented on pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#issuecomment-679402694


   @potiuk Currently a WIP, I'd like you to answer the following questions.
   1. IMO, The [old documentation](https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=63407290) contains a mix of information suitable for end users and contributors. I've added some of its contents in the documentation for end users (Airflow docs). Rest of the information, should we move to a new section for scheduler inside CONTRIBUTING.rst?
   2. I've added a flow chart to better explain the flow of the scheduler. Please take a look and let me know if there are any enhancements needed? If the contents work even without that flow chart, I'm fine with that also.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] github-actions[bot] commented on pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#issuecomment-799013661


   This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] yesemsanthoshkumar commented on a change in pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
yesemsanthoshkumar commented on a change in pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#discussion_r484784787



##########
File path: docs/scheduler.rst
##########
@@ -18,11 +18,41 @@
 Scheduler
 ==========
 
-The Airflow scheduler monitors all tasks and DAGs, then triggers the
-task instances once their dependencies are complete. Behind the scenes,
-the scheduler spins up a subprocess, which monitors and stays in sync with all
-DAGs in the specified DAG directory. Once per minute, by default, the scheduler
-collects DAG parsing results and checks whether any active tasks can be triggered.
+The scheduler is the core component in Airflow that is responsible for monitoring all tasks and DAGs and triggers the task instances once their dependencies are complete. And for this reason, it is imperative to learn about the working of the scheduler.
+
+Scheduling in airflow involves the 3 following components.
+
+1. ``DAGFileProcessor`` - Responsible for parsing the DAG definition in a file and creating the necessary DAG runs and TaskInstances
+
+2. ``DAGFileProcessorManager`` - Responsible for listing the files in the DagBag and creating new DAGFileProcessors when required
+
+3. ``SchedulerJob`` - Responsible for sending the TaskInstances to the executor

Review comment:
       @mik-laj Updated the descriptions. Please take a look.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] mik-laj commented on a change in pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#discussion_r475983480



##########
File path: docs/scheduler.rst
##########
@@ -18,11 +18,41 @@
 Scheduler
 ==========
 
-The Airflow scheduler monitors all tasks and DAGs, then triggers the
-task instances once their dependencies are complete. Behind the scenes,
-the scheduler spins up a subprocess, which monitors and stays in sync with all
-DAGs in the specified DAG directory. Once per minute, by default, the scheduler
-collects DAG parsing results and checks whether any active tasks can be triggered.
+The scheduler is the core component in Airflow that is responsible for monitoring all tasks and DAGs and triggers the task instances once their dependencies are complete. And for this reason, it is imperative to learn about the working of the scheduler.
+
+Scheduling in airflow involves the 3 following components.
+
+1. ``DAGFileProcessor`` - Responsible for parsing the DAG definition in a file and creating the necessary DAG runs and TaskInstances
+
+2. ``DAGFileProcessorManager`` - Responsible for listing the files in the DagBag and creating new DAGFileProcessors when required
+
+3. ``SchedulerJob`` - Responsible for sending the TaskInstances to the executor
+
+Logic behind scheduling is as follows:
+
+1. Airflow kicks off DAGFileProcessorManager along with the SchedulerJob. The DAGFileProcessorManager enumerates all the files in the DAG directory.
+
+2. The DAGFileProcessorManager spawns child processes known as DAGFileProcessor which is responsible for creating the necessary DAG Runs and TaskInstances. When it determines that task instances should run, it updates their state to ``SCHEDULED``. The number of DAGFileProcessor to spawn is configurable via ``num_runs`` in ``airflow.cfg``. TODO: Check if the configuration is correct
+
+3. If any of the DAGFileProcessor have finished, another process is spawned to work on the next file in the series.
+
+4. The cycle is repeated for all the files in the DAG Bag. If the process to parse DAG file is still running when the file's turn comes up in the next cycle, the file is skipped and the next file in the series will be assigned for the new processor. This isolation provides a non-blocking DAG parsing functionality.
+
+To illustrate better,
+
+.. image:: img/scheduler_flow.png
+
+TODO: Do we add missing task instance states in the TaskInstance document
+
+If the task instance has a state of NONE it will be set to SCHEDULED if the scheduler determines that it needs to run.
+Tasks in the SCHEDULED state are sent to the executor, at which point it is put into the QUEUED state until it actually runs. TODO: Add links to TaskInstance in the documentation. The reason that the task instances are created in the ``SCHEDULED`` state, but then are set to the ``QUEUED`` state once it is sent to the executor, is to ensure that a task instance isn't repeatedly send to the executor if the executor is slow and a DAG definition file is processed multiple times before the executor has a chance to run the task. When the DAGFileProcessor examines a DAG for potential tasks to put into the ``SCHEDULED`` state, it skips those task instances in the ``QUEUED`` state.
+
+Since the scheduler can run indefinitely, it's necessary to periodically refresh the list of files in the DAG definition directory. The refresh interval is controlled with the ``dag_dir_list_interval`` configuration parameter. In cases where there are only a small number of DAG definition files, the loop could potentially process the DAG definition files many times a minute. To control the rate of DAG file processing, the ``min_file_process_interval`` can be set to a higher value. This parameter ensures that a DAG definition file is not processed more often than once every ``min_file_process_interval`` seconds.

Review comment:
       ```suggestion
   Since the scheduler can run indefinitely, it's necessary to periodically refresh the list of files in the DAG definition directory. The refresh interval is controlled with the ``dag_dir_list_interval`` option in ``[scheduler]`` section. In cases where there are only a small number of DAG definition files, the loop could potentially process the DAG definition files many times a minute. To control the rate of DAG file processing, the ``min_file_process_interval`` option in ``[scheduler]`` section can be set to a higher value. This parameter ensures that a DAG definition file is not processed more often than once every ``min_file_process_interval`` seconds.
   ```




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] yesemsanthoshkumar commented on pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
yesemsanthoshkumar commented on pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#issuecomment-691544412






----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] potiuk edited a comment on pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
potiuk edited a comment on pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#issuecomment-751293346


   Hey @yesemsanthoshkumar  - can you please rebase it and lets review/close it :)


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] github-actions[bot] closed pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
github-actions[bot] closed pull request #10531:
URL: https://github.com/apache/airflow/pull/10531


   


-- 
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:
users@infra.apache.org



[GitHub] [airflow] mik-laj commented on a change in pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#discussion_r475981438



##########
File path: docs/scheduler.rst
##########
@@ -18,11 +18,41 @@
 Scheduler
 ==========
 
-The Airflow scheduler monitors all tasks and DAGs, then triggers the
-task instances once their dependencies are complete. Behind the scenes,
-the scheduler spins up a subprocess, which monitors and stays in sync with all
-DAGs in the specified DAG directory. Once per minute, by default, the scheduler
-collects DAG parsing results and checks whether any active tasks can be triggered.
+The scheduler is the core component in Airflow that is responsible for monitoring all tasks and DAGs and triggers the task instances once their dependencies are complete. And for this reason, it is imperative to learn about the working of the scheduler.
+
+Scheduling in airflow involves the 3 following components.
+
+1. ``DAGFileProcessor`` - Responsible for parsing the DAG definition in a file and creating the necessary DAG runs and TaskInstances
+
+2. ``DAGFileProcessorManager`` - Responsible for listing the files in the DagBag and creating new DAGFileProcessors when required
+
+3. ``SchedulerJob`` - Responsible for sending the TaskInstances to the executor
+
+Logic behind scheduling is as follows:
+
+1. Airflow kicks off DAGFileProcessorManager along with the SchedulerJob. The DAGFileProcessorManager enumerates all the files in the DAG directory.
+
+2. The DAGFileProcessorManager spawns child processes known as DAGFileProcessor which is responsible for creating the necessary DAG Runs and TaskInstances. When it determines that task instances should run, it updates their state to ``SCHEDULED``. The number of DAGFileProcessor to spawn is configurable via ``num_runs`` in ``airflow.cfg``. TODO: Check if the configuration is correct
+
+3. If any of the DAGFileProcessor have finished, another process is spawned to work on the next file in the series.

Review comment:
       ```suggestion
   3. If any of the DAGFileProcessor have finished, another process is created to work on the next file in the series.
   ```
   Depending on the operating system, new processes can be spawn(MacOS) or fork(Linux).




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] yesemsanthoshkumar commented on pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
yesemsanthoshkumar commented on pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#issuecomment-679836453


   > 2. Flowchart is great. Ideally, we would just need some sources for that -> for example in Draw.io export format or maybe you would like to recreate the flowchart with mermaid ? (https://mermaid-js.github.io/mermaid-live-editor/) - we have now automated mermaid generation (see images/ci/ folder. -> just enough to drop a ".mermaid" file and the chart will be generated automatically during pre-commit.
   
   @potiuk I have a draw.io file. But yeah I'll recreate them in mermaid.
   
   > @yesemsanthoshkumar I would be happy to share information about the scheduler and even provide some internal documents about it so that we have detailed documentation about the Scheduler. Would you like us to do it in this PR or will we only focus on moving the content for now? I am asking because I do not know what capacity you have.
   
   @mik-laj Sure. I have bandwidth to pick this up. We'll just do it along with this PR.
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] yesemsanthoshkumar edited a comment on pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
yesemsanthoshkumar edited a comment on pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#issuecomment-691544412






----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] mik-laj commented on pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
mik-laj commented on pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#issuecomment-679946056


   Here is my docs about scheduler:  https://docs.google.com/document/d/1qLalzSE1gSML-ph5use1ztMYxNt2YeLB3vC_B7yiYMo/edit#heading=h.30ws72k3a6xu
   This could be the beginning for further work. 


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] yesemsanthoshkumar commented on a change in pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
yesemsanthoshkumar commented on a change in pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#discussion_r479822281



##########
File path: docs/scheduler.rst
##########
@@ -18,11 +18,41 @@
 Scheduler
 ==========
 
-The Airflow scheduler monitors all tasks and DAGs, then triggers the
-task instances once their dependencies are complete. Behind the scenes,
-the scheduler spins up a subprocess, which monitors and stays in sync with all
-DAGs in the specified DAG directory. Once per minute, by default, the scheduler
-collects DAG parsing results and checks whether any active tasks can be triggered.
+The scheduler is the core component in Airflow that is responsible for monitoring all tasks and DAGs and triggers the task instances once their dependencies are complete. And for this reason, it is imperative to learn about the working of the scheduler.
+
+Scheduling in airflow involves the 3 following components.
+
+1. ``DAGFileProcessor`` - Responsible for parsing the DAG definition in a file and creating the necessary DAG runs and TaskInstances
+
+2. ``DAGFileProcessorManager`` - Responsible for listing the files in the DagBag and creating new DAGFileProcessors when required
+
+3. ``SchedulerJob`` - Responsible for sending the TaskInstances to the executor
+
+Logic behind scheduling is as follows:
+
+1. Airflow kicks off DAGFileProcessorManager along with the SchedulerJob. The DAGFileProcessorManager enumerates all the files in the DAG directory.
+
+2. The DAGFileProcessorManager spawns child processes known as DAGFileProcessor which is responsible for creating the necessary DAG Runs and TaskInstances. When it determines that task instances should run, it updates their state to ``SCHEDULED``. The number of DAGFileProcessor to spawn is configurable via ``num_runs`` in ``airflow.cfg``. TODO: Check if the configuration is correct

Review comment:
       So num_runs is about how many iterations the scheduler go over the DagBag, after which the scheduler shut itself down gracefully?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] yesemsanthoshkumar commented on a change in pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
yesemsanthoshkumar commented on a change in pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#discussion_r487447010



##########
File path: CONTRIBUTING.rst
##########
@@ -645,6 +645,76 @@ snowflake                  slack
 
   .. END PACKAGE DEPENDENCIES HERE
 
+Contributing to the Scheduler
+=============================
+
+The scheduler is the core of Airflow and needs to be the most understood section. We believe this writeup will remove the mysticism around the scheduler section in the code so that it can be improved further by your contributions. Before diving into further details, we suggest you read up on the `scheduler <https://airflow.apache.org/docs/stable/scheduler.html>`_ section from the documentation.
+
+A DAG consists of Tasks and obviously you need those tasks to run. To do that we schedule the dag to make it into a DagRun. This means that a DagRun is an instantiation of a DAG in time. Then we need to process the tasks of the current active dagruns. We simply loop over the available tasks and see if they are runnable. If a task is runnable it will get sent to the executor.
+
+.. code-block:: python
+
+  def _do_dags(self, dagbag, dags, tis_out):
+      """
+      Iterates over the dags and schedules and processes them
+      """
+      for dag in dags:
+          self.logger.debug("Scheduling {}".format(dag.dag_id))
+          dag = dagbag.get_dag(dag.dag_id)
+          if not dag:
+              continue
+          try:
+              self.schedule_dag(dag)
+              self.process_dag(dag, tis_out)
+              self.manage_slas(dag)
+          except Exception as e:
+              self.logger.exception(e)
+
+Now it is a bit more messy at the moment. That is due to the fact that DagRuns are not yet first class citizens. In the past Airflow only had a notion of DagRun: it mentioned them in the code but they did not really exist, instead DAGs were instantiated into "Tasks in Time": TaskInstances. This creates architectural issues but also real life ones. Some of the issues in the current scheduler with "depend_on_past" stem from this, because a Task is not really able to answer "which task instance is the first in time?". It is also the reason why scheduler loops start to increase over time if DAGs get more complex (many tasks). The good news is work is underway to improve this.
+TODO: Add link to roadmap

Review comment:
       Which section on roadmap should I link this to?

##########
File path: CONTRIBUTING.rst
##########
@@ -645,6 +645,76 @@ snowflake                  slack
 
   .. END PACKAGE DEPENDENCIES HERE
 
+Contributing to the Scheduler
+=============================
+
+The scheduler is the core of Airflow and needs to be the most understood section. We believe this writeup will remove the mysticism around the scheduler section in the code so that it can be improved further by your contributions. Before diving into further details, we suggest you read up on the `scheduler <https://airflow.apache.org/docs/stable/scheduler.html>`_ section from the documentation.
+
+A DAG consists of Tasks and obviously you need those tasks to run. To do that we schedule the dag to make it into a DagRun. This means that a DagRun is an instantiation of a DAG in time. Then we need to process the tasks of the current active dagruns. We simply loop over the available tasks and see if they are runnable. If a task is runnable it will get sent to the executor.
+
+.. code-block:: python
+
+  def _do_dags(self, dagbag, dags, tis_out):
+      """
+      Iterates over the dags and schedules and processes them
+      """
+      for dag in dags:
+          self.logger.debug("Scheduling {}".format(dag.dag_id))
+          dag = dagbag.get_dag(dag.dag_id)
+          if not dag:
+              continue
+          try:
+              self.schedule_dag(dag)
+              self.process_dag(dag, tis_out)
+              self.manage_slas(dag)
+          except Exception as e:
+              self.logger.exception(e)
+
+Now it is a bit more messy at the moment. That is due to the fact that DagRuns are not yet first class citizens. In the past Airflow only had a notion of DagRun: it mentioned them in the code but they did not really exist, instead DAGs were instantiated into "Tasks in Time": TaskInstances. This creates architectural issues but also real life ones. Some of the issues in the current scheduler with "depend_on_past" stem from this, because a Task is not really able to answer "which task instance is the first in time?". It is also the reason why scheduler loops start to increase over time if DAGs get more complex (many tasks). The good news is work is underway to improve this.
+TODO: Add link to roadmap

Review comment:
       Which section on roadmap should I link this to?

##########
File path: CONTRIBUTING.rst
##########
@@ -645,6 +645,76 @@ snowflake                  slack
 
   .. END PACKAGE DEPENDENCIES HERE
 
+Contributing to the Scheduler
+=============================
+
+The scheduler is the core of Airflow and needs to be the most understood section. We believe this writeup will remove the mysticism around the scheduler section in the code so that it can be improved further by your contributions. Before diving into further details, we suggest you read up on the `scheduler <https://airflow.apache.org/docs/stable/scheduler.html>`_ section from the documentation.
+
+A DAG consists of Tasks and obviously you need those tasks to run. To do that we schedule the dag to make it into a DagRun. This means that a DagRun is an instantiation of a DAG in time. Then we need to process the tasks of the current active dagruns. We simply loop over the available tasks and see if they are runnable. If a task is runnable it will get sent to the executor.
+
+.. code-block:: python
+
+  def _do_dags(self, dagbag, dags, tis_out):
+      """
+      Iterates over the dags and schedules and processes them
+      """
+      for dag in dags:
+          self.logger.debug("Scheduling {}".format(dag.dag_id))
+          dag = dagbag.get_dag(dag.dag_id)
+          if not dag:
+              continue
+          try:
+              self.schedule_dag(dag)
+              self.process_dag(dag, tis_out)
+              self.manage_slas(dag)
+          except Exception as e:
+              self.logger.exception(e)
+
+Now it is a bit more messy at the moment. That is due to the fact that DagRuns are not yet first class citizens. In the past Airflow only had a notion of DagRun: it mentioned them in the code but they did not really exist, instead DAGs were instantiated into "Tasks in Time": TaskInstances. This creates architectural issues but also real life ones. Some of the issues in the current scheduler with "depend_on_past" stem from this, because a Task is not really able to answer "which task instance is the first in time?". It is also the reason why scheduler loops start to increase over time if DAGs get more complex (many tasks). The good news is work is underway to improve this.
+TODO: Add link to roadmap

Review comment:
       Which section on roadmap should I link this to? Currently linked this to 2.0 planning.

##########
File path: CONTRIBUTING.rst
##########
@@ -645,6 +645,76 @@ snowflake                  slack
 
   .. END PACKAGE DEPENDENCIES HERE
 
+Contributing to the Scheduler
+=============================
+
+The scheduler is the core of Airflow and needs to be the most understood section. We believe this writeup will remove the mysticism around the scheduler section in the code so that it can be improved further by your contributions. Before diving into further details, we suggest you read up on the `scheduler <https://airflow.apache.org/docs/stable/scheduler.html>`_ section from the documentation.
+
+A DAG consists of Tasks and obviously you need those tasks to run. To do that we schedule the dag to make it into a DagRun. This means that a DagRun is an instantiation of a DAG in time. Then we need to process the tasks of the current active dagruns. We simply loop over the available tasks and see if they are runnable. If a task is runnable it will get sent to the executor.
+
+.. code-block:: python
+
+  def _do_dags(self, dagbag, dags, tis_out):
+      """
+      Iterates over the dags and schedules and processes them
+      """
+      for dag in dags:
+          self.logger.debug("Scheduling {}".format(dag.dag_id))
+          dag = dagbag.get_dag(dag.dag_id)
+          if not dag:
+              continue
+          try:
+              self.schedule_dag(dag)
+              self.process_dag(dag, tis_out)
+              self.manage_slas(dag)
+          except Exception as e:
+              self.logger.exception(e)
+
+Now it is a bit more messy at the moment. That is due to the fact that DagRuns are not yet first class citizens. In the past Airflow only had a notion of DagRun: it mentioned them in the code but they did not really exist, instead DAGs were instantiated into "Tasks in Time": TaskInstances. This creates architectural issues but also real life ones. Some of the issues in the current scheduler with "depend_on_past" stem from this, because a Task is not really able to answer "which task instance is the first in time?". It is also the reason why scheduler loops start to increase over time if DAGs get more complex (many tasks). The good news is work is underway to improve this.
+TODO: Add link to roadmap

Review comment:
       Which section on roadmap should I link this to?

##########
File path: CONTRIBUTING.rst
##########
@@ -645,6 +645,76 @@ snowflake                  slack
 
   .. END PACKAGE DEPENDENCIES HERE
 
+Contributing to the Scheduler
+=============================
+
+The scheduler is the core of Airflow and needs to be the most understood section. We believe this writeup will remove the mysticism around the scheduler section in the code so that it can be improved further by your contributions. Before diving into further details, we suggest you read up on the `scheduler <https://airflow.apache.org/docs/stable/scheduler.html>`_ section from the documentation.
+
+A DAG consists of Tasks and obviously you need those tasks to run. To do that we schedule the dag to make it into a DagRun. This means that a DagRun is an instantiation of a DAG in time. Then we need to process the tasks of the current active dagruns. We simply loop over the available tasks and see if they are runnable. If a task is runnable it will get sent to the executor.
+
+.. code-block:: python
+
+  def _do_dags(self, dagbag, dags, tis_out):
+      """
+      Iterates over the dags and schedules and processes them
+      """
+      for dag in dags:
+          self.logger.debug("Scheduling {}".format(dag.dag_id))
+          dag = dagbag.get_dag(dag.dag_id)
+          if not dag:
+              continue
+          try:
+              self.schedule_dag(dag)
+              self.process_dag(dag, tis_out)
+              self.manage_slas(dag)
+          except Exception as e:
+              self.logger.exception(e)
+
+Now it is a bit more messy at the moment. That is due to the fact that DagRuns are not yet first class citizens. In the past Airflow only had a notion of DagRun: it mentioned them in the code but they did not really exist, instead DAGs were instantiated into "Tasks in Time": TaskInstances. This creates architectural issues but also real life ones. Some of the issues in the current scheduler with "depend_on_past" stem from this, because a Task is not really able to answer "which task instance is the first in time?". It is also the reason why scheduler loops start to increase over time if DAGs get more complex (many tasks). The good news is work is underway to improve this.
+TODO: Add link to roadmap

Review comment:
       Which section on roadmap should I link this to? Currently linked this to 2.0 planning.

##########
File path: CONTRIBUTING.rst
##########
@@ -645,6 +645,76 @@ snowflake                  slack
 
   .. END PACKAGE DEPENDENCIES HERE
 
+Contributing to the Scheduler
+=============================
+
+The scheduler is the core of Airflow and needs to be the most understood section. We believe this writeup will remove the mysticism around the scheduler section in the code so that it can be improved further by your contributions. Before diving into further details, we suggest you read up on the `scheduler <https://airflow.apache.org/docs/stable/scheduler.html>`_ section from the documentation.
+
+A DAG consists of Tasks and obviously you need those tasks to run. To do that we schedule the dag to make it into a DagRun. This means that a DagRun is an instantiation of a DAG in time. Then we need to process the tasks of the current active dagruns. We simply loop over the available tasks and see if they are runnable. If a task is runnable it will get sent to the executor.
+
+.. code-block:: python
+
+  def _do_dags(self, dagbag, dags, tis_out):
+      """
+      Iterates over the dags and schedules and processes them
+      """
+      for dag in dags:
+          self.logger.debug("Scheduling {}".format(dag.dag_id))
+          dag = dagbag.get_dag(dag.dag_id)
+          if not dag:
+              continue
+          try:
+              self.schedule_dag(dag)
+              self.process_dag(dag, tis_out)
+              self.manage_slas(dag)
+          except Exception as e:
+              self.logger.exception(e)
+
+Now it is a bit more messy at the moment. That is due to the fact that DagRuns are not yet first class citizens. In the past Airflow only had a notion of DagRun: it mentioned them in the code but they did not really exist, instead DAGs were instantiated into "Tasks in Time": TaskInstances. This creates architectural issues but also real life ones. Some of the issues in the current scheduler with "depend_on_past" stem from this, because a Task is not really able to answer "which task instance is the first in time?". It is also the reason why scheduler loops start to increase over time if DAGs get more complex (many tasks). The good news is work is underway to improve this.
+TODO: Add link to roadmap

Review comment:
       Which section on roadmap should I link this to?

##########
File path: CONTRIBUTING.rst
##########
@@ -645,6 +645,76 @@ snowflake                  slack
 
   .. END PACKAGE DEPENDENCIES HERE
 
+Contributing to the Scheduler
+=============================
+
+The scheduler is the core of Airflow and needs to be the most understood section. We believe this writeup will remove the mysticism around the scheduler section in the code so that it can be improved further by your contributions. Before diving into further details, we suggest you read up on the `scheduler <https://airflow.apache.org/docs/stable/scheduler.html>`_ section from the documentation.
+
+A DAG consists of Tasks and obviously you need those tasks to run. To do that we schedule the dag to make it into a DagRun. This means that a DagRun is an instantiation of a DAG in time. Then we need to process the tasks of the current active dagruns. We simply loop over the available tasks and see if they are runnable. If a task is runnable it will get sent to the executor.
+
+.. code-block:: python
+
+  def _do_dags(self, dagbag, dags, tis_out):
+      """
+      Iterates over the dags and schedules and processes them
+      """
+      for dag in dags:
+          self.logger.debug("Scheduling {}".format(dag.dag_id))
+          dag = dagbag.get_dag(dag.dag_id)
+          if not dag:
+              continue
+          try:
+              self.schedule_dag(dag)
+              self.process_dag(dag, tis_out)
+              self.manage_slas(dag)
+          except Exception as e:
+              self.logger.exception(e)
+
+Now it is a bit more messy at the moment. That is due to the fact that DagRuns are not yet first class citizens. In the past Airflow only had a notion of DagRun: it mentioned them in the code but they did not really exist, instead DAGs were instantiated into "Tasks in Time": TaskInstances. This creates architectural issues but also real life ones. Some of the issues in the current scheduler with "depend_on_past" stem from this, because a Task is not really able to answer "which task instance is the first in time?". It is also the reason why scheduler loops start to increase over time if DAGs get more complex (many tasks). The good news is work is underway to improve this.
+TODO: Add link to roadmap

Review comment:
       Which section on roadmap should I link this to? Currently linked this to 2.0 planning.

##########
File path: CONTRIBUTING.rst
##########
@@ -645,6 +645,76 @@ snowflake                  slack
 
   .. END PACKAGE DEPENDENCIES HERE
 
+Contributing to the Scheduler
+=============================
+
+The scheduler is the core of Airflow and needs to be the most understood section. We believe this writeup will remove the mysticism around the scheduler section in the code so that it can be improved further by your contributions. Before diving into further details, we suggest you read up on the `scheduler <https://airflow.apache.org/docs/stable/scheduler.html>`_ section from the documentation.
+
+A DAG consists of Tasks and obviously you need those tasks to run. To do that we schedule the dag to make it into a DagRun. This means that a DagRun is an instantiation of a DAG in time. Then we need to process the tasks of the current active dagruns. We simply loop over the available tasks and see if they are runnable. If a task is runnable it will get sent to the executor.
+
+.. code-block:: python
+
+  def _do_dags(self, dagbag, dags, tis_out):
+      """
+      Iterates over the dags and schedules and processes them
+      """
+      for dag in dags:
+          self.logger.debug("Scheduling {}".format(dag.dag_id))
+          dag = dagbag.get_dag(dag.dag_id)
+          if not dag:
+              continue
+          try:
+              self.schedule_dag(dag)
+              self.process_dag(dag, tis_out)
+              self.manage_slas(dag)
+          except Exception as e:
+              self.logger.exception(e)
+
+Now it is a bit more messy at the moment. That is due to the fact that DagRuns are not yet first class citizens. In the past Airflow only had a notion of DagRun: it mentioned them in the code but they did not really exist, instead DAGs were instantiated into "Tasks in Time": TaskInstances. This creates architectural issues but also real life ones. Some of the issues in the current scheduler with "depend_on_past" stem from this, because a Task is not really able to answer "which task instance is the first in time?". It is also the reason why scheduler loops start to increase over time if DAGs get more complex (many tasks). The good news is work is underway to improve this.
+TODO: Add link to roadmap

Review comment:
       Which section on roadmap should I link this to?

##########
File path: CONTRIBUTING.rst
##########
@@ -645,6 +645,76 @@ snowflake                  slack
 
   .. END PACKAGE DEPENDENCIES HERE
 
+Contributing to the Scheduler
+=============================
+
+The scheduler is the core of Airflow and needs to be the most understood section. We believe this writeup will remove the mysticism around the scheduler section in the code so that it can be improved further by your contributions. Before diving into further details, we suggest you read up on the `scheduler <https://airflow.apache.org/docs/stable/scheduler.html>`_ section from the documentation.
+
+A DAG consists of Tasks and obviously you need those tasks to run. To do that we schedule the dag to make it into a DagRun. This means that a DagRun is an instantiation of a DAG in time. Then we need to process the tasks of the current active dagruns. We simply loop over the available tasks and see if they are runnable. If a task is runnable it will get sent to the executor.
+
+.. code-block:: python
+
+  def _do_dags(self, dagbag, dags, tis_out):
+      """
+      Iterates over the dags and schedules and processes them
+      """
+      for dag in dags:
+          self.logger.debug("Scheduling {}".format(dag.dag_id))
+          dag = dagbag.get_dag(dag.dag_id)
+          if not dag:
+              continue
+          try:
+              self.schedule_dag(dag)
+              self.process_dag(dag, tis_out)
+              self.manage_slas(dag)
+          except Exception as e:
+              self.logger.exception(e)
+
+Now it is a bit more messy at the moment. That is due to the fact that DagRuns are not yet first class citizens. In the past Airflow only had a notion of DagRun: it mentioned them in the code but they did not really exist, instead DAGs were instantiated into "Tasks in Time": TaskInstances. This creates architectural issues but also real life ones. Some of the issues in the current scheduler with "depend_on_past" stem from this, because a Task is not really able to answer "which task instance is the first in time?". It is also the reason why scheduler loops start to increase over time if DAGs get more complex (many tasks). The good news is work is underway to improve this.
+TODO: Add link to roadmap

Review comment:
       Which section on roadmap should I link this to? Currently linked this to 2.0 planning.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] yesemsanthoshkumar commented on pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
yesemsanthoshkumar commented on pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#issuecomment-691544412






----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] mik-laj commented on pull request #10531: Move scheduler basics documentation to Airflow docs

Posted by GitBox <gi...@apache.org>.
mik-laj commented on pull request #10531:
URL: https://github.com/apache/airflow/pull/10531#issuecomment-679423694


   @yesemsanthoshkumar I would be happy to share information about the scheduler and even provide some internal documents about it so that we have detailed documentation about the Scheduler.  Would you like us to do it in this PR or will we only focus on moving the content for now? I am asking because I do not know what capacity you have.
   
   


----------------------------------------------------------------
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:
users@infra.apache.org