Skip to content

fix: implement container-aware CPU detection - #1170

Open
jorsol wants to merge 1 commit into
zalando:triggerfrom
jorsol:cgroup-cpu-count
Open

jorsol wants to merge 1 commit into
zalando:triggerfrom
jorsol:cgroup-cpu-count

Conversation

@jorsol

@jorsol jorsol commented Jan 24, 2026

Copy link
Copy Markdown

Instead of returning the host's physical CPU count, this now checks Cgroup v1/v2 quotas and process affinity. This ensures the application scales based on available container resources rather than host hardware.

@zalando-robot

Copy link
Copy Markdown

Cannot start a pipeline due to:

No accountable user for this pipeline: no Zalando employee associated to this GitHub username

Click on pipeline status check Details link below for more information.

@jorsol

jorsol commented Feb 11, 2026

Copy link
Copy Markdown
Author

Any comment on this?

@hughcapet

Copy link
Copy Markdown
Collaborator

please fix the flake8 issues: https://github.com/zalando/spilo/actions/runs/24730351030/job/72342837925?pr=1170

try:
limit = len(os.sched_getaffinity(0))
except (AttributeError, NotImplementedError):
limit = os.cpu_count() or 1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you prefer to switch to os.cpu_count from the psutil.cpu_count()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither of these functions is smart enough to handle container limits (quotas) on their own; it's just a fallback when everything else fails.

Both will return the same value, so I prefer to use the built-in Python function.

Instead of returning the host's physical CPU count, this now checks
Cgroup v1/v2 quotas and process affinity. This ensures the application
scales based on available container resources rather than host hardware.
@jorsol
jorsol force-pushed the cgroup-cpu-count branch from 4bb0129 to 943ac9d Compare April 24, 2026 12:33
@jorsol

jorsol commented Apr 28, 2026

Copy link
Copy Markdown
Author

please fix the flake8 issues: https://github.com/zalando/spilo/actions/runs/24730351030/job/72342837925?pr=1170

This should be already fixed.

@jorsol
jorsol requested a review from hughcapet May 2, 2026 12:52
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.

3 participants