Skip to content

add gc.freeze to minimize memory usage in celery worker - #62212

Merged
potiuk merged 1 commit into
apache:mainfrom
wjddn279:add-gc-freeze-to-minimize-memory-usage
Mar 12, 2026
Merged

add gc.freeze to minimize memory usage in celery worker#62212
potiuk merged 1 commit into
apache:mainfrom
wjddn279:add-gc-freeze-to-minimize-memory-usage

Conversation

@wjddn279

@wjddn279 wjddn279 commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

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.freeze was 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)

image

TO-BE (apply with gc.freeze)

image
Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

@wjddn279

Copy link
Copy Markdown
Contributor Author

@hussein-awala @dheerajturaga

hello, code owners of celery workers...
Can I get some reviews about this?

@potiuk
potiuk merged commit 85d1d1f into apache:main Mar 12, 2026
86 checks passed
@potiuk

potiuk commented Mar 12, 2026

Copy link
Copy Markdown
Member

Sorry missed it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants