Skip to content

daemon: don't repeatedly call NumCPU if not needed#49192

Merged
thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah:numcpu_once
Jan 2, 2025
Merged

daemon: don't repeatedly call NumCPU if not needed#49192
thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah:numcpu_once

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

sysinfo.NumCPU returns the number of CPUs which are currently online, which involves some syscalls and parsing on Windows.

Change the code to only retrieve this information when needed, and memoize the result to prevent calling this function multiple times.

Ideally, we'd obtain this information from daemon.RawSysInfo(), but that uses a sync.Once, which could return outdated information.

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

sysinfo.NumCPU returns the number of CPUs which are currently online,
which involves some syscalls and parsing on Windows.

Change the code to only retrieve this information when needed, and
memoize the result to prevent calling this function multiple times.

Ideally, we'd obtain this information from daemon.RawSysInfo(), but
that uses a sync.Once, which could return outdated information.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah thaJeztah added status/2-code-review area/daemon Core Engine kind/refactor PR's that refactor, or clean-up code labels Jan 1, 2025
@thaJeztah thaJeztah added this to the 28.0.0 milestone Jan 1, 2025
@thaJeztah thaJeztah self-assigned this Jan 1, 2025
@thaJeztah thaJeztah merged commit a948ee6 into moby:master Jan 2, 2025
@thaJeztah thaJeztah deleted the numcpu_once branch January 2, 2025 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/daemon Core Engine kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants