{"action":"created","issue":{"url":"https://api.github.com/repos/apache/incubator-airflow/issues/3873","repository_url":"https://api.github.com/repos/apache/incubator-airflow","labels_url":"https://api.github.com/repos/apache/incubator-airflow/issues/3873/labels{/name}","comments_url":"https://api.github.com/repos/apache/incubator-airflow/issues/3873/comments","events_url":"https://api.github.com/repos/apache/incubator-airflow/issues/3873/events","html_url":"https://github.com/apache/incubator-airflow/pull/3873","id":358481747,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE0MjA3NzMw","number":3873,"title":"[Airflow-2760] Decouple DAG parsing loop from scheduler loop","user":{"login":"yrqls21","id":7818710,"node_id":"MDQ6VXNlcjc4MTg3MTA=","avatar_url":"https://avatars1.githubusercontent.com/u/7818710?v=4","gravatar_id":"","url":"https://api.github.com/users/yrqls21","html_url":"https://github.com/yrqls21","followers_url":"https://api.github.com/users/yrqls21/followers","following_url":"https://api.github.com/users/yrqls21/following{/other_user}","gists_url":"https://api.github.com/users/yrqls21/gists{/gist_id}","starred_url":"https://api.github.com/users/yrqls21/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yrqls21/subscriptions","organizations_url":"https://api.github.com/users/yrqls21/orgs","repos_url":"https://api.github.com/users/yrqls21/repos","events_url":"https://api.github.com/users/yrqls21/events{/privacy}","received_events_url":"https://api.github.com/users/yrqls21/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-09-10T06:15:14Z","updated_at":"2018-09-12T19:13:42Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/apache/incubator-airflow/pulls/3873","html_url":"https://github.com/apache/incubator-airflow/pull/3873","diff_url":"https://github.com/apache/incubator-airflow/pull/3873.diff","patch_url":"https://github.com/apache/incubator-airflow/pull/3873.patch"},"body":"### Jira\r\n\r\n- [x] My PR addresses the following [Airflow Jira](https://issues.apache.org/jira/browse/AIRFLOW-2760) issues and references them in the PR title.\r\n  - https://issues.apache.org/jira/browse/AIRFLOW-2760\r\n\r\n### Description\r\n\r\n- [x] Here are some details about my PR, including screenshots of any UI changes:\r\n\r\nBefore this change, scheduler loop is responsible for spinning up new DAG file processors after it harvested the results of DAG parsing. And thus the speed of new DAG file processor getting spinned up is bounded by the scheduler loop speed. Like this:\r\n![6](https://user-images.githubusercontent.com/7818710/45280044-c6946a00-b487-11e8-8938-50136533e6db.jpg)\r\n\r\nAfter the change, scheduler loop will only not longer be responsible for spinning up new DAG file processors and the DAGFileProcessorManager will be responsible for it instead. DAG parsing will be much faster and not longer bounded by scheduler loop speed. And thus scheduler will be able to schedule more tasks. Like this:\r\n![8](https://user-images.githubusercontent.com/7818710/45280071-dd3ac100-b487-11e8-916b-c5789140f5a5.jpg)\r\n\r\nSummary of big behavior changes:\r\n\r\n1. Scheduler loop and DAG parsing loop are decoupled and run in two different processes.\r\n2. DAG parsing manager logging will go into a separate file.\r\n3. Zombie tasks will be calculate by DAG parsing manager and send to DAG parsing processor to kill. This is to reduce DB CPU load( identified to produce 80% of CPU load during stress test, CPU usage went down from 80%+ to ~40% after this change).\r\n\r\n### Tests\r\n\r\n- [x] My PR adds the following unit tests __OR__ does not need testing for this extremely good reason:\r\ntest_dag_processing.py:TestDagFileProcessorAgent\r\njobs.py:SchedulerJobTest.test_no_orphan_process_will_be_left\r\nplan to add zombie detecting test in test_dag_processing.py\r\nThe change is more about doing same thing in different way and thus didn't add a lot unit tests. But I'm still think about proper unit tests to add, and suggestion on what unit tests to add would be greatly appreciated.\r\n\r\nTested in our stress testing cluster with 4k files and 30k running tasks and scheduling delay has been kept within 5 mins( except when we need to scheduling huge amount of tasks at the time, which is going to be dealt with later) for 1+ month and our production cluster has been running with the change for 1+ week.\r\n\r\nBefore( #running tasks are lower because DB was stressed out and refusing connections, which caused tasks to fail):\r\n\r\nThe scheduling delay is generated by a monitoring task that is running on the cluster with 5m interval. It will compare the current timestamp against the expected scheduling timestamp(execution_date + 5m) and send the time diff in min as one data point on the metric graph, e.g. monitoring task with execution_date 2018-01-01T00:00:00 started at 2018-01-01T00:06:00 will put a 1m scheduling delay data point onto the metric graph.\r\n![screen shot 2018-07-31 at 12 23 52 pm](https://user-images.githubusercontent.com/7818710/45280411-16276580-b489-11e8-827e-8f3d2655983f.png)\r\n\r\n\r\nAfter:\r\n![screen shot 2018-07-30 at 5 17 10 pm](https://user-images.githubusercontent.com/7818710/45280415-1aec1980-b489-11e8-9005-fec70db4a3d6.png)\r\n\r\n### Commits\r\n\r\n- [x] My commits all reference Jira issues in their subject lines, and I have squashed multiple commits if they address the same issue. In addition, my commits follow the guidelines from \"[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)\":\r\n  1. Subject is separated from body by a blank line\r\n  1. Subject is limited to 50 characters (not including Jira issue reference)\r\n  1. Subject does not end with a period\r\n  1. Subject uses the imperative mood (\"add\", not \"adding\")\r\n  1. Body wraps at 72 characters\r\n  1. Body explains \"what\" and \"why\", not \"how\"\r\n\r\n### Documentation\r\n\r\n- [x] In case of new functionality, my PR adds documentation that describes how to use it.\r\n  - When adding new operators/hooks/sensors, the autoclass documentation generation needs to be added.\r\n\r\n### Code Quality\r\n\r\n- [x] Passes `git diff upstream/master -u -- \"*.py\" | flake8 --diff`\r\n"},"comment":{"url":"https://api.github.com/repos/apache/incubator-airflow/issues/comments/420764932","html_url":"https://github.com/apache/incubator-airflow/pull/3873#issuecomment-420764932","issue_url":"https://api.github.com/repos/apache/incubator-airflow/issues/3873","id":420764932,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMDc2NDkzMg==","user":{"login":"feng-tao","id":3223098,"node_id":"MDQ6VXNlcjMyMjMwOTg=","avatar_url":"https://avatars3.githubusercontent.com/u/3223098?v=4","gravatar_id":"","url":"https://api.github.com/users/feng-tao","html_url":"https://github.com/feng-tao","followers_url":"https://api.github.com/users/feng-tao/followers","following_url":"https://api.github.com/users/feng-tao/following{/other_user}","gists_url":"https://api.github.com/users/feng-tao/gists{/gist_id}","starred_url":"https://api.github.com/users/feng-tao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/feng-tao/subscriptions","organizations_url":"https://api.github.com/users/feng-tao/orgs","repos_url":"https://api.github.com/users/feng-tao/repos","events_url":"https://api.github.com/users/feng-tao/events{/privacy}","received_events_url":"https://api.github.com/users/feng-tao/received_events","type":"User","site_admin":false},"created_at":"2018-09-12T19:13:42Z","updated_at":"2018-09-12T19:13:42Z","author_association":"CONTRIBUTOR","body":"will take a look later this week."}}
{"actor":{"display_login":"feng-tao"}}