LabsThis feature is in Labs. Contact your account team to enable this feature.
How Cosmos Boost works
Airflow parses every Dag file repeatedly: the Dag processor parses each file again on an interval, and workers parse a Dag file again before they run one of its tasks. For a Dag built with Cosmos, each parse turns a dbt project into Airflow tasks, which includes reading the project, loading the manifest, and applying your select and exclude filters. For large dbt projects, this work can dominate parse time, delay task scheduling, and increase memory use. If a Dag file takes longer to import than thedagbag_import_timeout setting allows, Airflow reports a timeout import error for the file, and its Dags can fail to appear or update in the Airflow UI.
Cosmos Boost reduces this work on Astro. If an optimization can’t apply, for example because of an unsupported Cosmos version or a missing file, Cosmos Boost logs a warning and falls back to standard Cosmos parsing for that parse. The expected worst case is that a parse isn’t accelerated.
Results
In Deployments, Cosmos Boost parses dbt projects up to six times faster. Results vary by project and configuration. Projects benefit most when they do at least one of the following:- Contain hundreds or thousands of dbt models and load them from a manifest.
- Use complex select or exclude filters with the manifest load method.
- Use the dbt ls load method.
- Render the same dbt project in many
DbtTaskGroupinstances within one Dag. - Declare many
DbtDaginstances in a single Dag file. These projects can also benefit from the opt-in magic loop optimization.
Requirements
Set up Cosmos Boost
After your account team enables Cosmos Boost, complete the following steps:- Confirm that your Deployments meet the requirements.
-
Check your Astro CLI version:
If the version is earlier than 1.47.0, upgrade the Astro CLI to the latest version.
-
From the root of your Astro project, turn on the Cosmos Boost pre-deploy step:
With this setting, the Astro CLI prepares information about your dbt project at deploy time, so Airflow doesn’t need to compute it on every parse. To confirm the setting, run:
-
Deploy your project:
The pre-deploy step applies from this deploy onward.
Deploy with CI/CD
If you deploy with a CI/CD pipeline, turn on the Cosmos Boost pre-deploy step in the pipeline before the deploy step. For example, in GitHub Actions:Turn on the magic loop optimization
Before a worker runs a task, Airflow parses the whole Dag file that defines the task’s Dag. If the file declares severalDbtDag instances, for example in a loop over a list of dbt projects or schedules, the worker builds every one of them, which means one full dbt project parse for each, even though the task needs only one Dag. The magic loop optimization uses Airflow’s parsing context to build only the DbtDag that the task belongs to.
The optimization applies only to DbtDag instances, not DbtTaskGroup instances, and only to the parse that a worker runs before a task. The Dag processor still builds every Dag in full, so scheduling isn’t affected.
Why the magic loop optimization is off by default
The magic loop optimization relies on eachDbtDag in a Dag file being self-contained. Some Dag files share task definitions across several Dags, or add tasks that depend on another Dag in the same file. In those files, building only the Dag that the task belongs to isn’t enough: the code that reads another DbtDag fails, Airflow reports an import error for the whole file, and the task can’t start.
The setting applies to every Dag file in the Deployment, not to individual files. Turn it on only after you confirm that the Cosmos Dag files in the Deployment don’t depend on other Dags in the same file.
Prerequisites
- Cosmos Boost enabled for the Deployment.
- Astro Runtime 3.0-1 or later, which runs Airflow 3. On earlier versions, the setting has no effect and workers build every Dag in the file.
Steps
-
Check each Dag file that declares more than one
DbtDag. Look for module-level code that accesses the tasks or properties of eachDbtDagafter Cosmos creates it, for example code that adds a task and sets a dependency withget_task(). In the following example, the loop adds a task to everyDbtDagit creates. With the magic loop optimization on,get_task()fails for everyDbtDagother than the one the worker is parsing for: -
Update the code so that it still registers every Dag, but skips the extra setup for a
DbtDagthat the magic loop optimization skipped. A skippedDbtDaghas no tasks, and itsdbt_graphattribute isNone: - Deploy the updated Dag code.
-
In the Astro UI, set the following environment variable on the Deployment:
Turn off Cosmos Boost
To turn off the pre-deploy step, run the following commands from the root of your Astro project:astro dbt cleanup removes the files that earlier deploys added. Turning off the setting doesn’t remove them.
To turn off the magic loop optimization, delete the ASTRO_COSMOS_BOOST_PLUGIN_MAGIC_LOOP_ENABLED environment variable or set it to false.
To turn off Cosmos Boost for a Deployment, contact your Astronomer account team.