DAG processor: serial bundle refresh blocks the parsing loop
Under which category would you file this issue?
Airflow Core
Apache Airflow version
3.3.2
What happened and how to reproduce it?
DagFileProcessorManager._run_parsing_loop() calls _refresh_dag_bundles() inline, and that
method refreshes every bundle serially (for bundle in self._dag_bundles: ... bundle.refresh()).
For GitDagBundle each refresh fetches from the remote and resets the checkout, so the time
spent grows linearly with the number of bundles. The loop is single-threaded, so while the
refresh runs the manager does not start new parsing processes or collect results.
Our deployment has 42 Git bundles with 714 DAG files in total. Measured from the DAG processor logs:
- One refresh pass over the 42 bundles takes 29-30s, which is about 0.7s per bundle.
- With
refresh_interval = 60, the loop alternates between about 30s of refreshing and about 30s of parsing, so roughly half of the loop time is spent in_refresh_dag_bundles(). - In the windows we examined second by second, no "Bulk-writing dags to db" lines were logged during a refresh pass. They resumed as soon as the pass ended.
Summarised timeline of two consecutive cycles (UTC):
13:53:45 - 13:54:15 "Refreshing bundle <name>" lines only, no parse results written
13:54:17 - 13:54:48 parse results written (several per second)
13:54:48 - 13:55:19 "Refreshing bundle <name>" lines only, no parse results written
13:55:20 - 13:55:49 parse results written
Consequences we observed:
- Parsing throughput is roughly halved. With
parsing_processes = 8, each file was re-parsed only about every 10.5 minutes, although many files parse in a few seconds. - Some reported parse durations are inflated. Files that normally parse in 1-3s were sometimes reported with 31.6-34.8s, which is about the length of one refresh pass. We suspect this is because the duration is computed when the result is collected, or because of the IPC wait described in #65369. We have not confirmed which.
- A second identical DAG processor replica did not reduce the blocking. In a later
measurement over 12 minutes (with
parsing_processes = 16,min_file_process_interval = 600and two replicas), each replica still spent 43-48% of its time refreshing, and about a quarter of the bundle refreshes happened within 20s of the other replica refreshing the same bundle.
The cost scales with the number of bundles. The code has a TODO at this spot: "What if the cloning/refreshing took too long(longer than the dag processor timeout)".
The steps describe our setup:
- Configure a few dozen
GitDagBundleentries pointing at different repositories (we have 42), with[dag_processor] refresh_interval = 60. - Run a standalone
airflow dag-processor. - Watch the logs: one "Refreshing bundle ..." line per bundle, serially, and no parse results written until the last bundle is done.
- Compare the length of the refresh pass with the refresh interval.
What you think should happen instead?
Refreshing bundles should not stop the manager from dispatching parsing processes, servicing them and collecting their results.
The slow part of a refresh is network I/O on the bundle's own directory, which is already protected by the bundle lock. Only the follow-up bookkeeping (recording the new version, rescanning files, updating the file queue) needs to run in the manager loop. Possible directions:
- run the fetches in a separate process, and let the loop only apply the result, or
- refresh bundles in parallel instead of one after another, or
- at least keep servicing and collecting parser results between individual bundle refreshes.
Operating System
Linux on Kubernetes
Deployment
Official Apache Airflow Helm Chart
Versions of Apache Airflow Providers
apache-airflow-providers-git==1.0.1
Official Helm Chart version
1.21.0
Kubernetes Version
No response
Helm Chart configuration
- Helm chart 1.21.0, KubernetesExecutor, standalone DAG processor (1 replica, 4 CPU / 3Gi limits)
- 42 bundles using a thin subclass of
GitDagBundle. At the time of measurement it only set default kwargs (repo_url,tracking_ref,submodules=False,git_conn_id) and calledimportlib.invalidate_caches()afterinitialize(). HTTPS access to GitHub. [dag_processor]settings at the time of measurement:refresh_interval = 60,parsing_processes = 8, and defaults formin_file_process_interval,file_parsing_sort_modeandbundle_refresh_check_interval
Anything else?
Related:
- #65369 describes one consequence of the same blocking (parser children waiting for IPC
replies during
_refresh_dag_bundles()). The two PRs for it, #65370 and #72008, were closed without being merged. - #56446 proposes skipping re-parses for files whose bundle version did not change.
A related observation, possibly a separate issue: when a bundle's version changes, the manager only re-sorts the files still in the queue and adds new files to the front. A file that changed in the new commit but was already parsed in the current pass is not re-queued, so it waits until the queue drains. In our case commits were detected within 10-20s, but changes took 5-10 minutes to appear in the UI.
Workarounds we use today: a much higher min_file_process_interval so the queue is usually
empty, and more parsing processes. We are also considering restricting each DAG processor
to a subset of the bundles.
Are you willing to submit PR?
- [ ] Yes I am willing to submit a PR!
Code of Conduct
- [x] I agree to follow this project's Code of Conduct