Fix LocalExecutor memory spike by applying gc.freeze - #58365
Merged
Conversation
wjddn279
requested review from
XD-DENG,
ashb,
hussein-awala,
o-nikolas and
pierrejeambrun
as code owners
November 16, 2025 12:37
potiuk
reviewed
Nov 16, 2025
potiuk
approved these changes
Nov 16, 2025
potiuk
left a comment
Member
There was a problem hiding this comment.
LGTM. but there is the comment on the immediate ramping up of remaining workers, and definitely we need more than one pair of eyes to take a look.
Member
|
I also marked it as backportable to 3-1-test. That would be a fantastic bugfix for 3.1.4 Local Executor memory usage. |
wjddn279
force-pushed
the
fix-local-executor-cow-issue
branch
from
November 17, 2025 01:39
c530aee to
e3188f9
Compare
jason810496
self-requested a review
November 17, 2025 06:05
Closed
2 tasks
Contributor
|
wjddn279
force-pushed
the
fix-local-executor-cow-issue
branch
from
November 18, 2025 11:22
0728297 to
e3188f9
Compare
ashb
reviewed
Nov 18, 2025
ashb
reviewed
Nov 18, 2025
wjddn279
force-pushed
the
fix-local-executor-cow-issue
branch
3 times, most recently
from
November 24, 2025 02:04
9f32807 to
83d1381
Compare
wjddn279
force-pushed
the
fix-local-executor-cow-issue
branch
from
November 24, 2025 08:56
435be23 to
88b1153
Compare
ashb
reviewed
Nov 25, 2025
ashb
reviewed
Nov 25, 2025
ashb
reviewed
Nov 25, 2025
Contributor
Author
|
@ashb I’ve incorporated the feedback! |
Member
|
@ashb - any comment? I would love to merge this one today in preparation for upcoming 3.1.4 |
Member
|
I merged for 3.1.4, We can always iterate in the future and the results of tests sounds very plausible . Thanks @wjddn279 and we can I think work on other memory optimisations after that. |
github-actions Bot
pushed a commit
that referenced
this pull request
Dec 2, 2025
) * fix local executor issue caused by cow * fix test * fix test * remove gc utils * fix test to prevent timeout * fix tests * fix tests * fix tests (cherry picked from commit baec49a) Co-authored-by: Jeongwoo Do <48639483+wjddn279@users.noreply.github.com>
Contributor
RoyLee1224
pushed a commit
to RoyLee1224/airflow
that referenced
this pull request
Dec 3, 2025
* fix local executor issue caused by cow * fix test * fix test * remove gc utils * fix test to prevent timeout * fix tests * fix tests * fix tests
78 tasks
Contributor
Author
|
#protm self nominating |
itayweb
pushed a commit
to itayweb/airflow
that referenced
this pull request
Dec 6, 2025
* fix local executor issue caused by cow * fix test * fix test * remove gc utils * fix test to prevent timeout * fix tests * fix tests * fix tests
Subham-KRLX
pushed a commit
to Subham-KRLX/airflow
that referenced
this pull request
Mar 4, 2026
* fix local executor issue caused by cow * fix test * fix test * remove gc utils * fix test to prevent timeout * fix tests * fix tests * fix tests
2 tasks
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
related: #58143
Body
As discussed (not confirmed yet), this resolves the issue of sudden memory usage spikes in worker processes when using LocalExecutor. Memory increases due to unnecessary copying of read-only shared memory through COW caused by gc. By applying gc.freeze and moving existing objects to the permanent generation, we prevent COW from occurring.
When using fork mode, we create many worker processes at once to minimize gc.freeze and unfreeze calls. When using spawn mode, we maintain the existing approach to ensure stability.
Benchmark
memory usage
Comparison of per-process memory usage in LocalExecutor before and after applying this PR. Measured in the same environment running 500 tasks per minute for 12 hours.
gc.freeze / unfreeze performance (elapsed time)
We measured the elapsed time of gc.freeze and gc.unfreeze for each scheduler loop iteration. Most operations took microseconds, confirming virtually no impact. The actual operation is a very lightweight process that simply marks objects in the current generation as permanent generation without any memory copying.https://github.com/python/cpython/pull/3705/files
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.