Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AIRFLOW-3885] ~10x speed-up of SchedulerJobTest suite #4730

Merged

Conversation

astahlman
Copy link
Contributor

@astahlman astahlman commented Feb 18, 2019

Make sure you have checked all steps below.

Jira

  • [ X ] My PR addresses the following Airflow Jira issues and references them in the PR title. For example, "[AIRFLOW-XXX] My Airflow PR"

Description

  • [ X ] Here are some details about my PR, including screenshots of any UI changes:

The SchedulerJobTest suite now takes ~90 seconds on my laptop (down from
~900 seconds == 15 minutes) on Jenkins.

There are a few optimizations here:

  1. Don't sleep() for 1 second every scheduling loop (in unit tests)
  2. Don't process the example DAGs
  3. Use subdir to process only the DAGs we need, for a couple of tests
    that actually run the scheduler
  4. Only load the DagBag once instead of before each test

I've also added a few tables to the list of tables that are cleaned up
in between test runs to make the tests re-entrant.

Tests

  • My PR adds the following unit tests OR does not need testing for this extremely good reason:

Commits

  • [ 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":
    1. Subject is separated from body by a blank line
    2. Subject is limited to 50 characters (not including Jira issue reference)
    3. Subject does not end with a period
    4. Subject uses the imperative mood ("add", not "adding")
    5. Body wraps at 72 characters
    6. Body explains "what" and "why", not "how"

Documentation

  • In case of new functionality, my PR adds documentation that describes how to use it.
    • When adding new operators/hooks/sensors, the autoclass documentation generation needs to be added.
    • All the public functions and the classes in the PR contain docstrings that explain what it does

Code Quality

  • [ X ] Passes flake8

The SchedulerJobTest suite now takes ~90 seconds on my laptop (down from
~900 seconds == 15 minutes) on Jenkins.

There are a few optimizations here:

1. Don't sleep() for 1 second every scheduling loop (in unit tests)
2. Don't process the example DAGs
3. Use `subdir` to process only the DAGs we need, for a couple of tests
   that actually run the scheduler
4. Only load the DagBag once instead of before each test

I've also added a few tables to the list of tables that are cleaned up
in between test runs to make the tests re-entrant.
@astahlman astahlman force-pushed the astahlman/airflow-3885-more-scheduler-tests branch from a481352 to 010ca8c Compare February 18, 2019 20:34
@codecov-io
Copy link

codecov-io commented Feb 18, 2019

Codecov Report

Merging #4730 into master will decrease coverage by 0.05%.
The diff coverage is 71.42%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #4730      +/-   ##
=========================================
- Coverage   74.65%   74.6%   -0.06%     
=========================================
  Files         430     430              
  Lines       27991   27995       +4     
=========================================
- Hits        20897   20885      -12     
- Misses       7094    7110      +16
Impacted Files Coverage Δ
airflow/utils/dag_processing.py 59.89% <100%> (+0.14%) ⬆️
airflow/jobs.py 76.57% <60%> (-0.96%) ⬇️
airflow/models/__init__.py 92.59% <0%> (-0.26%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 725bc2e...010ca8c. Read the comment docs.

@astahlman
Copy link
Contributor Author

Between this PR and #4726, we're shaving off ~9 minutes from the total CI time.

@astahlman astahlman changed the title [WIP] [AIRFLOW-3885] ~10x speed-up of SchedulerJobTest suite [AIRFLOW-3885] ~10x speed-up of SchedulerJobTest suite Feb 18, 2019
@astahlman
Copy link
Contributor Author

cc @feng-tao

@feng-tao
Copy link
Member

nice find @astahlman !

Copy link
Member

@XD-DENG XD-DENG left a comment

Choose a reason for hiding this comment

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

May you clarify a bit on your change in utils/dag_processing.py?

@@ -277,7 +277,7 @@ def get_dag(self, dag_id):


def list_py_file_paths(directory, safe_mode=True,
include_examples=conf.getboolean('core', 'LOAD_EXAMPLES')):
include_examples=None):
Copy link
Member

Choose a reason for hiding this comment

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

This change makes no difference to me.

Copy link
Member

Choose a reason for hiding this comment

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

Hi @feng-tao , understand this PR is merged and it does bring significant improvement (big thanks to @astahlman !).

But may you check my comment? It's a very minor point, but not really necessary to add a separate check here (Kindly let me know if I missed anything). Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was needed because of the way that Python handles default arguments: the default value is evaluated when the function is defined, not when it is called. Therefore, our mocked implementation of getboolean wouldn't get called here, and include_examples will be always be True.

This way, we call getboolean every time the function is evaluated, so our mock implementation does get used and getboolean('core', 'LOAD_EXAMPLES') evaluates to False.

Copy link
Member

Choose a reason for hiding this comment

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

Get it. Thanks for the clarification @astahlman

@feng-tao feng-tao merged commit c4b9d88 into apache:master Feb 19, 2019
antonimaciej pushed a commit to PolideaInternal/airflow that referenced this pull request Feb 26, 2019
The SchedulerJobTest suite now takes ~90 seconds on my laptop (down from
~900 seconds == 15 minutes) on Jenkins.

There are a few optimizations here:

1. Don't sleep() for 1 second every scheduling loop (in unit tests)
2. Don't process the example DAGs
3. Use `subdir` to process only the DAGs we need, for a couple of tests
   that actually run the scheduler
4. Only load the DagBag once instead of before each test

I've also added a few tables to the list of tables that are cleaned up
in between test runs to make the tests re-entrant.
ashb pushed a commit to ashb/airflow that referenced this pull request Mar 8, 2019
The SchedulerJobTest suite now takes ~90 seconds on my laptop (down from
~900 seconds == 15 minutes) on Jenkins.

There are a few optimizations here:

1. Don't sleep() for 1 second every scheduling loop (in unit tests)
2. Don't process the example DAGs
3. Use `subdir` to process only the DAGs we need, for a couple of tests
   that actually run the scheduler
4. Only load the DagBag once instead of before each test

I've also added a few tables to the list of tables that are cleaned up
in between test runs to make the tests re-entrant.
wmorris75 pushed a commit to modmed/incubator-airflow that referenced this pull request Jul 29, 2019
The SchedulerJobTest suite now takes ~90 seconds on my laptop (down from
~900 seconds == 15 minutes) on Jenkins.

There are a few optimizations here:

1. Don't sleep() for 1 second every scheduling loop (in unit tests)
2. Don't process the example DAGs
3. Use `subdir` to process only the DAGs we need, for a couple of tests
   that actually run the scheduler
4. Only load the DagBag once instead of before each test

I've also added a few tables to the list of tables that are cleaned up
in between test runs to make the tests re-entrant.
@eschachar eschachar deleted the astahlman/airflow-3885-more-scheduler-tests branch September 24, 2022 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants