devgonvarun opened a new issue, #77381:
URL: https://github.com/apache/airflow/issues/77381
### 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 (one repository per team) 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:
1. 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.
The pod used about 0.3-0.4 of its 4 CPU cores in two samples, so it did
not look
resource-bound.
2. 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.
3. 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 = 600`
and 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. Extrapolating linearly, at about
85 bundles one
refresh pass would take as long as the refresh interval itself. The code has
a TODO at this
spot: "What if the cloning/refreshing took too long(longer than the dag
processor timeout)".
We have not reproduced this on a clean install. The steps describe our setup:
1. Configure a few dozen `GitDagBundle` entries pointing at different
repositories
(we have 42), with `[dag_processor] refresh_interval = 60`.
2. Run a standalone `airflow dag-processor`.
3. Watch the logs: one "Refreshing bundle ..." line per bundle, serially,
and no parse
results written until the last bundle is done.
4. 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
### Apache Airflow Provider(s)
_No response_
### 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 called
`importlib.invalidate_caches()` after `initialize()`. HTTPS access to
GitHub.
- `[dag_processor]` settings at the time of measurement: `refresh_interval =
60`,
`parsing_processes = 8`, and defaults for `min_file_process_interval`,
`file_parsing_sort_mode` and `bundle_refresh_check_interval`
### Docker Image customizations
_No response_
### 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](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]