add gc.freeze to minimize memory usage in celery worker - #62212
Merged
potiuk merged 1 commit intoMar 12, 2026
Conversation
wjddn279
requested review from
dheerajturaga and
hussein-awala
as code owners
February 20, 2026 10:34
Contributor
Author
|
hello, code owners of celery workers... |
potiuk
approved these changes
Mar 12, 2026
Member
|
Sorry missed it! |
PascalEgn
pushed a commit
to PascalEgn/airflow
that referenced
this pull request
Mar 12, 2026
Pyasma
pushed a commit
to Pyasma/airflow
that referenced
this pull request
Mar 13, 2026
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.
discuss: https://lists.apache.org/thread/33hdp3hm705mzgrltv7o3468wvwbjsr3
related: #60505, #60505
Body
In a Celery worker, the Celery Main Process runs by default, and 16 ForkPoolWorkers are created as sub-processes of that process (based on default settings).
It operates based on COW (Copy-On-Write), which is the default memory behavior of fork, and through this, heavy modules (numpy, k8s) are pre-loaded. However, it was observed that as soon as ForkPoolWorkers are created, they have a higher PSS than the Main Process, confirming that memory increased due to COW.
As with other PRs,
gc.freezewas applied, and it was confirmed that memory usage per process was reduced to less than half.Benchmark
This test is a memory snapshot of celery worker container taken after 10 hours have elapsed when 100 tasks per minute were executed every minute, deploying with Docker
AS-IS (docker image 3.1.7)
TO-BE (apply with gc.freeze)
Was generative AI tooling used to co-author this PR?
{pr_number}.significant.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.