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/02/22 15:04:11 UTC
[GitHub] [airflow] mik-laj opened a new pull request #7502:
[AIRFLOW-6881][depends on AIRFLOW-6869][WIP] Bulk fetch DAGRun for
create_dag_run
mik-laj opened a new pull request #7502: [AIRFLOW-6881][depends on AIRFLOW-6869][WIP] Bulk fetch DAGRun for create_dag_run
URL: https://github.com/apache/airflow/pull/7502
Another performance optimization.
When I have following DAG file
```
from datetime import timedelta
from airflow.models import DAG
from airflow.operators.bash_operator import BashOperator
from airflow.operators.dummy_operator import DummyOperator
from airflow.utils.dates import days_ago
args = {
'owner': 'airflow',
'start_date': days_ago(3),
}
def create_dag(dag_number):
dag = DAG(
dag_id=f'perf_50_dag_dummy_tasks_{dag_number}_of_50', default_args=args,
schedule_interval="@once",
dagrun_timeout=timedelta(minutes=60),
is_paused_upon_creation=False,
)
for j in range(1, 10):
DummyOperator(
task_id='task_{}_of_5'.format(j),
dag=dag
)
return dag
for i in range(1, 200):
globals()[f"dag_{i}"] = create_dag(i)
```
I ran the following code:
```
from airflow.jobs.scheduler_job import DagFileProcessor
processor = DagFileProcessor([], log)
processor.process_file(DAG_FILE, None, pickle_dags=False)
```
I got the following values.
**Before:**
Query count: 2589
Average time 7980.117 ms
**After:**
Query count: 2390
Average time: 7261.959 ms
**Diff:**
Query count: -199 (-7%)
Average time: -719 ms (-9%)
Thanks for support to @evgenyshulman from Databand!
---
Issue link: WILL BE INSERTED BY [boring-cyborg](https://github.com/kaxil/boring-cyborg)
Make sure to mark the boxes below before creating PR: [x]
- [ ] Description above provides context of the change
- [ ] Commit message/PR title starts with `[AIRFLOW-NNNN]`. AIRFLOW-NNNN = JIRA ID<sup>*</sup>
- [ ] Unit tests coverage for changes (not needed for documentation changes)
- [ ] Commits follow "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)"
- [ ] Relevant documentation is updated including usage instructions.
- [ ] I will engage committers as explained in [Contribution Workflow Example](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#contribution-workflow-example).
<sup>*</sup> For document-only changes commit message can start with `[AIRFLOW-XXXX]`.
---
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).
Read the [Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines) for more information.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [airflow] saguziel commented on a change in pull request #7502:
[AIRFLOW-6881][depends on AIRFLOW-6869][WIP] Bulk fetch DAGRun for
create_dag_run
Posted by GitBox <gi...@apache.org>.
saguziel commented on a change in pull request #7502: [AIRFLOW-6881][depends on AIRFLOW-6869][WIP] Bulk fetch DAGRun for create_dag_run
URL: https://github.com/apache/airflow/pull/7502#discussion_r383542743
##########
File path: airflow/jobs/scheduler_job.py
##########
@@ -699,23 +734,30 @@ def _process_dags(self, dagbag, dags, tis_out):
self.log.info("Not processing DAG %s since it's paused", dag.dag_id)
continue
- self.log.info("Processing %s", dag.dag_id)
+ dag_id = dag.dag_id
+ self.log.info("Processing %s", dag_id)
+ dag_runs_for_dag = dag_runs_by_dag_id[dag_id] if dag_id in dag_runs_by_dag_id else []
Review comment:
maybe just dag_runs_by_dag_id.get(dag_id, [])
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [airflow] mik-laj commented on a change in pull request #7502:
[AIRFLOW-6881][depends on AIRFLOW-6869][WIP] Bulk fetch DAGRun for
create_dag_run
Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #7502: [AIRFLOW-6881][depends on AIRFLOW-6869][WIP] Bulk fetch DAGRun for create_dag_run
URL: https://github.com/apache/airflow/pull/7502#discussion_r384358607
##########
File path: airflow/jobs/scheduler_job.py
##########
@@ -498,19 +499,26 @@ def update_import_errors(session, dagbag):
session.commit()
@provide_session
- def create_dag_run(self, dag, session=None):
+ def create_dag_run(self, dag, dag_runs=None, session=None):
"""
This method checks whether a new DagRun needs to be created
for a DAG based on scheduling interval.
Returns DagRun if one is scheduled. Otherwise returns None.
"""
if dag.schedule_interval and conf.getboolean('scheduler', 'USE_JOB_SCHEDULE'):
- active_runs = DagRun.find(
- dag_id=dag.dag_id,
- state=State.RUNNING,
- external_trigger=False,
- session=session
- )
+ if dag_runs is None:
Review comment:
I did this to facilitate testing of this method both in unit tests and in performance tests.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [airflow] mik-laj commented on issue #7502: [AIRFLOW-6881][depends
on AIRFLOW-6869][WIP] Bulk fetch DAGRun for create_dag_run
Posted by GitBox <gi...@apache.org>.
mik-laj commented on issue #7502: [AIRFLOW-6881][depends on AIRFLOW-6869][WIP] Bulk fetch DAGRun for create_dag_run
URL: https://github.com/apache/airflow/pull/7502#issuecomment-589994462
@tooptoop4 The number of tasks does not affect this, but I will also check this case and give values ..
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [airflow] ashb commented on a change in pull request #7502:
[AIRFLOW-6881][depends on AIRFLOW-6869][WIP] Bulk fetch DAGRun for
create_dag_run
Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #7502: [AIRFLOW-6881][depends on AIRFLOW-6869][WIP] Bulk fetch DAGRun for create_dag_run
URL: https://github.com/apache/airflow/pull/7502#discussion_r384356431
##########
File path: airflow/jobs/scheduler_job.py
##########
@@ -498,19 +499,26 @@ def update_import_errors(session, dagbag):
session.commit()
@provide_session
- def create_dag_run(self, dag, session=None):
+ def create_dag_run(self, dag, dag_runs=None, session=None):
"""
This method checks whether a new DagRun needs to be created
for a DAG based on scheduling interval.
Returns DagRun if one is scheduled. Otherwise returns None.
"""
if dag.schedule_interval and conf.getboolean('scheduler', 'USE_JOB_SCHEDULE'):
- active_runs = DagRun.find(
- dag_id=dag.dag_id,
- state=State.RUNNING,
- external_trigger=False,
- session=session
- )
+ if dag_runs is None:
Review comment:
Actually why do we need this branch? This is a method on DagFileProcessor, so not really user facing.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [airflow] codecov-io commented on issue #7502:
[AIRFLOW-6881][depends on AIRFLOW-6869][WIP] Bulk fetch DAGRun for
create_dag_run
Posted by GitBox <gi...@apache.org>.
codecov-io commented on issue #7502: [AIRFLOW-6881][depends on AIRFLOW-6869][WIP] Bulk fetch DAGRun for create_dag_run
URL: https://github.com/apache/airflow/pull/7502#issuecomment-589968164
# [Codecov](https://codecov.io/gh/apache/airflow/pull/7502?src=pr&el=h1) Report
> Merging [#7502](https://codecov.io/gh/apache/airflow/pull/7502?src=pr&el=desc) into [master](https://codecov.io/gh/apache/airflow/commit/4e0e2f0da39626c1bc8026a33c2080a6b11f2c41?src=pr&el=desc) will **decrease** coverage by `0.42%`.
> The diff coverage is `97.14%`.
[](https://codecov.io/gh/apache/airflow/pull/7502?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #7502 +/- ##
==========================================
- Coverage 86.79% 86.36% -0.43%
==========================================
Files 887 891 +4
Lines 41976 42112 +136
==========================================
- Hits 36432 36372 -60
- Misses 5544 5740 +196
```
| [Impacted Files](https://codecov.io/gh/apache/airflow/pull/7502?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [airflow/jobs/scheduler\_job.py](https://codecov.io/gh/apache/airflow/pull/7502/diff?src=pr&el=tree#diff-YWlyZmxvdy9qb2JzL3NjaGVkdWxlcl9qb2IucHk=) | `90% <100%> (-0.25%)` | :arrow_down: |
| [airflow/models/dagrun.py](https://codecov.io/gh/apache/airflow/pull/7502/diff?src=pr&el=tree#diff-YWlyZmxvdy9tb2RlbHMvZGFncnVuLnB5) | `96.2% <83.33%> (-0.37%)` | :arrow_down: |
| [...w/providers/apache/hive/operators/mysql\_to\_hive.py](https://codecov.io/gh/apache/airflow/pull/7502/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvYXBhY2hlL2hpdmUvb3BlcmF0b3JzL215c3FsX3RvX2hpdmUucHk=) | `35.84% <0%> (-64.16%)` | :arrow_down: |
| [airflow/operators/generic\_transfer.py](https://codecov.io/gh/apache/airflow/pull/7502/diff?src=pr&el=tree#diff-YWlyZmxvdy9vcGVyYXRvcnMvZ2VuZXJpY190cmFuc2Zlci5weQ==) | `100% <0%> (ø)` | :arrow_up: |
| [airflow/kubernetes/volume\_mount.py](https://codecov.io/gh/apache/airflow/pull/7502/diff?src=pr&el=tree#diff-YWlyZmxvdy9rdWJlcm5ldGVzL3ZvbHVtZV9tb3VudC5weQ==) | `44.44% <0%> (-55.56%)` | :arrow_down: |
| [airflow/providers/postgres/operators/postgres.py](https://codecov.io/gh/apache/airflow/pull/7502/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvcG9zdGdyZXMvb3BlcmF0b3JzL3Bvc3RncmVzLnB5) | `100% <0%> (ø)` | :arrow_up: |
| [airflow/kubernetes/volume.py](https://codecov.io/gh/apache/airflow/pull/7502/diff?src=pr&el=tree#diff-YWlyZmxvdy9rdWJlcm5ldGVzL3ZvbHVtZS5weQ==) | `52.94% <0%> (-47.06%)` | :arrow_down: |
| [airflow/security/kerberos.py](https://codecov.io/gh/apache/airflow/pull/7502/diff?src=pr&el=tree#diff-YWlyZmxvdy9zZWN1cml0eS9rZXJiZXJvcy5weQ==) | `30.43% <0%> (-45.66%)` | :arrow_down: |
| [airflow/kubernetes/pod\_launcher.py](https://codecov.io/gh/apache/airflow/pull/7502/diff?src=pr&el=tree#diff-YWlyZmxvdy9rdWJlcm5ldGVzL3BvZF9sYXVuY2hlci5weQ==) | `47.18% <0%> (-45.08%)` | :arrow_down: |
| [airflow/providers/mysql/operators/mysql.py](https://codecov.io/gh/apache/airflow/pull/7502/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvbXlzcWwvb3BlcmF0b3JzL215c3FsLnB5) | `55% <0%> (-45%)` | :arrow_down: |
| ... and [39 more](https://codecov.io/gh/apache/airflow/pull/7502/diff?src=pr&el=tree-more) | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/airflow/pull/7502?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/airflow/pull/7502?src=pr&el=footer). Last update [4e0e2f0...59bb24d](https://codecov.io/gh/apache/airflow/pull/7502?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [airflow] mik-laj merged pull request #7502: [AIRFLOW-6881] Bulk
fetch DAGRun for create_dag_run
Posted by GitBox <gi...@apache.org>.
mik-laj merged pull request #7502: [AIRFLOW-6881] Bulk fetch DAGRun for create_dag_run
URL: https://github.com/apache/airflow/pull/7502
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [airflow] Fokko commented on a change in pull request #7502:
[AIRFLOW-6881][depends on AIRFLOW-6869][WIP] Bulk fetch DAGRun for
create_dag_run
Posted by GitBox <gi...@apache.org>.
Fokko commented on a change in pull request #7502: [AIRFLOW-6881][depends on AIRFLOW-6869][WIP] Bulk fetch DAGRun for create_dag_run
URL: https://github.com/apache/airflow/pull/7502#discussion_r383708424
##########
File path: airflow/models/dagrun.py
##########
@@ -125,14 +125,16 @@ def refresh_from_db(self, session=None):
@staticmethod
@provide_session
- def find(dag_id=None, run_id=None, execution_date=None,
+ def find(dag_id=None, dag_ids=None, run_id=None, execution_date=None,
Review comment:
Can we add type annotations as well? :)
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [airflow] mik-laj edited a comment on issue #7502:
[AIRFLOW-6881][depends on AIRFLOW-6869][WIP] Bulk fetch DAGRun for
create_dag_run
Posted by GitBox <gi...@apache.org>.
mik-laj edited a comment on issue #7502: [AIRFLOW-6881][depends on AIRFLOW-6869][WIP] Bulk fetch DAGRun for create_dag_run
URL: https://github.com/apache/airflow/pull/7502#issuecomment-589997296
```python
from datetime import timedelta
from airflow.models import DAG
from airflow.operators.dummy_operator import DummyOperator
from airflow.utils.dates import days_ago
args = {
'owner': 'airflow',
'start_date': days_ago(3),
}
def create_dag(dag_number):
dag = DAG(
dag_id=f'perf_50_dag_dummy_tasks_{dag_number}_of_50', default_args=args,
schedule_interval="@once",
dagrun_timeout=timedelta(minutes=60),
is_paused_upon_creation=False,
)
for j in range(1, 100):
DummyOperator(
task_id='task_{}_of_5'.format(j),
dag=dag
)
return dag
for i in range(1, 20):
globals()[f"dag_{i}"] = create_dag(i)
```
Before:
Query count: 249
Retry took 1333.755 ms
After:
Query count: 230
Retry took 1267.842 ms
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [airflow] mik-laj commented on a change in pull request #7502:
[AIRFLOW-6881][depends on AIRFLOW-6869][WIP] Bulk fetch DAGRun for
create_dag_run
Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #7502: [AIRFLOW-6881][depends on AIRFLOW-6869][WIP] Bulk fetch DAGRun for create_dag_run
URL: https://github.com/apache/airflow/pull/7502#discussion_r384360159
##########
File path: airflow/models/dagrun.py
##########
@@ -125,14 +125,16 @@ def refresh_from_db(self, session=None):
@staticmethod
@provide_session
- def find(dag_id=None, run_id=None, execution_date=None,
+ def find(dag_id=None, dag_ids=None, run_id=None, execution_date=None,
Review comment:
I will combine dag_id and dag_ids parameter.
Here are only primitive types, so I'll add types annotations.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [airflow] Fokko commented on a change in pull request #7502:
[AIRFLOW-6881][depends on AIRFLOW-6869][WIP] Bulk fetch DAGRun for
create_dag_run
Posted by GitBox <gi...@apache.org>.
Fokko commented on a change in pull request #7502: [AIRFLOW-6881][depends on AIRFLOW-6869][WIP] Bulk fetch DAGRun for create_dag_run
URL: https://github.com/apache/airflow/pull/7502#discussion_r383708347
##########
File path: airflow/models/dagrun.py
##########
@@ -125,14 +125,16 @@ def refresh_from_db(self, session=None):
@staticmethod
@provide_session
- def find(dag_id=None, run_id=None, execution_date=None,
+ def find(dag_id=None, dag_ids=None, run_id=None, execution_date=None,
Review comment:
Similar to the comment of @kaxil and @ashb earlier, I think we should combine the `dag_id` and `dag_ids` 👍
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [airflow] mik-laj commented on a change in pull request #7502:
[AIRFLOW-6881][depends on AIRFLOW-6869][DONT-MERGE] Bulk fetch DAGRun for
create_dag_run
Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #7502: [AIRFLOW-6881][depends on AIRFLOW-6869][DONT-MERGE] Bulk fetch DAGRun for create_dag_run
URL: https://github.com/apache/airflow/pull/7502#discussion_r385619228
##########
File path: airflow/jobs/scheduler_job.py
##########
@@ -699,23 +734,30 @@ def _process_dags(self, dagbag, dags, tis_out):
self.log.info("Not processing DAG %s since it's paused", dag.dag_id)
continue
- self.log.info("Processing %s", dag.dag_id)
+ dag_id = dag.dag_id
+ self.log.info("Processing %s", dag_id)
+ dag_runs_for_dag = dag_runs_by_dag_id[dag_id] if dag_id in dag_runs_by_dag_id else []
Review comment:
Done
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [airflow] tooptoop4 commented on issue #7502:
[AIRFLOW-6881][depends on AIRFLOW-6869][WIP] Bulk fetch DAGRun for
create_dag_run
Posted by GitBox <gi...@apache.org>.
tooptoop4 commented on issue #7502: [AIRFLOW-6881][depends on AIRFLOW-6869][WIP] Bulk fetch DAGRun for create_dag_run
URL: https://github.com/apache/airflow/pull/7502#issuecomment-589992285
can u get perf timings before/after for dags with 500 tasks in them? with these types of changes there could be regression with different dag shapes
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [airflow] mik-laj commented on issue #7502: [AIRFLOW-6881][depends
on AIRFLOW-6869][WIP] Bulk fetch DAGRun for create_dag_run
Posted by GitBox <gi...@apache.org>.
mik-laj commented on issue #7502: [AIRFLOW-6881][depends on AIRFLOW-6869][WIP] Bulk fetch DAGRun for create_dag_run
URL: https://github.com/apache/airflow/pull/7502#issuecomment-589997296
```
from datetime import timedelta
from airflow.models import DAG
from airflow.operators.dummy_operator import DummyOperator
from airflow.utils.dates import days_ago
args = {
'owner': 'airflow',
'start_date': days_ago(3),
}
def create_dag(dag_number):
dag = DAG(
dag_id=f'perf_50_dag_dummy_tasks_{dag_number}_of_50', default_args=args,
schedule_interval="@once",
dagrun_timeout=timedelta(minutes=60),
is_paused_upon_creation=False,
)
for j in range(1, 100):
DummyOperator(
task_id='task_{}_of_5'.format(j),
dag=dag
)
return dag
for i in range(1, 20):
globals()[f"dag_{i}"] = create_dag(i)
```
Before:
Query count: 249
Retry took 1333.755 ms
After:
Query count: 230
Retry took 1267.842 ms
----------------------------------------------------------------
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
With regards,
Apache Git Services