Easily measure and compare your Airflow DAGs' parse time.
Project description
Airflow Dag Parse Benchmarking
Stop creating bad DAGs!
Use this tool to measure and compare the parse time of your DAGs, identify bottlenecks, and optimize your Airflow environment for better performance.
Contents
How It Works
Retrieving parse metrics from an Airflow cluster is straightforward, but measuring the effectiveness of code optimizations can be tedious. Each code change requires redeploying the Python file to your cloud provider, waiting for the DAG to be parsed, and then extracting a new report — a slow and time-consuming process.
This tool simplifies the process of measuring and comparing DAG parse times. It uses the same parse method as Airflow (from the Airflow repository) to measure the time taken to parse your DAGs locally, storing results for future comparisons.
Installation
It's recommended to use a virtualenv to avoid library conflicts. Once set up, you can install the package by running the following command:
pip install airflow-parse-bench
Install your Airflow dependencies
The command above installs only the essential library dependencies (Airflow and Airflow providers). You’ll need to manually install any additional libraries that your DAGs depend on.
For example, if a DAG uses boto3 to interact with AWS, ensure that boto3 is installed in your environment. Otherwise, you'll encounter parse errors.
Configure your Airflow Variables
If your DAGs use Airflow Variables, you must define them locally as well. Use placeholder values, as the actual values aren't required for parsing purposes.
To setup Airflow Variables locally, you can use the following command:
airflow variables set MY_VARIABLE 'ANY TEST VALUE'
Without this, you'll encounter an error like:
error: 'Variable MY_VARIABLE does not exist'
Usage
To measure the parse time of a single Python file, just run:
airflow-parse-bench --path your_path/dag_test.py
The output will look like this:
The result table includes the following columns:
-
Filename: The name of the Python module containing the DAG. This unique name is the key to store DAG information.
-
Current Parse Time: The time (in seconds) taken to parse the DAG.
-
Previous Parse Time: The parse time from the previous run.
-
Difference: The difference between the current and previous parse times.
-
Best Parse Time: The best parse time recorded for the DAG.
You can also measure the parse time for all Python files in a directory by running:
airflow-parse-bench --path your_path/your_dag_folder
This time, the output table will display parse times for all Python files in the folder:
Additional Options
The library supports some additional arguments to customize the results. To see all available options, run:
airflow-parse-bench --help
It will display the following options:
- --path: The path to the Python file or directory containing the DAGs.
- --order: The order in which the results are displayed. You can choose between 'asc' (ascending) or 'desc' (descending).
- --num-iterations: The number of times to parse each DAG. The parse time will be averaged across iterations.
- --skip-unchanged: Skip DAGs that haven't changed since the last run.
- --reset-db: Clear all stored data in the local database, starting a fresh execution.
Note: If a Python file has parsing errors or contains no valid DAGs, it will be excluded from the results table, and an error message will be displayed.
Roadmap
This project is still in its early stages, and there are many improvements planned for the future. Some of the features we're considering include:
- Cloud DAG Parsing: Automatically download and parse DAGs from cloud providers like AWS S3 or Google Cloud Storage.
- Parallel Parsing: Speed up processing by parsing multiple DAGs simultaneously.
- Support .airflowignore: Ignore files and directories specified in the
.airflowignorefile.
If you’d like to suggest a feature or report a bug, please open a new issue!
Contributing
This project is open to contributions! If you want to collaborate to improve the tool, please follow these steps:
- Open a new issue to discuss the feature or bug you want to address.
- Once approved, fork the repository and create a new branch.
- Implement the changes.
- Create a pull request with a detailed description of the changes.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file airflow-parse-bench-1.0.1.tar.gz.
File metadata
- Download URL: airflow-parse-bench-1.0.1.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56f06bfc24dcf2f08fbe06d8abe4bb8cf4d797847245705ccf1320f42682b374
|
|
| MD5 |
f3c3bede9c910bfadad7e02fa6a04edd
|
|
| BLAKE2b-256 |
f4b95dd5a5bd42c4140481e39f8f467df12296214b85234d9cc8433ac8a676ba
|
File details
Details for the file airflow_parse_bench-1.0.1-py3-none-any.whl.
File metadata
- Download URL: airflow_parse_bench-1.0.1-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1efd8144ad2688b83bfcdd88199c7d2a38df3d9527bd8749ff063a523cda833f
|
|
| MD5 |
49a5a1b6dc4a8498cc1dd39a60e8c2ec
|
|
| BLAKE2b-256 |
ef81ba060849bdc42d77dcf6f7c2a586272af8f539a483520c9101135ea13f29
|