Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-12833] processInfo.activeProcessorCount ignores CFS quotas #4545

Closed
swift-ci opened this issue May 18, 2020 · 4 comments
Closed

[SR-12833] processInfo.activeProcessorCount ignores CFS quotas #4545

swift-ci opened this issue May 18, 2020 · 4 comments
Assignees
Labels

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-12833
Radar rdar://problem/63343024
Original Reporter gdelorme (JIRA User)
Type Task
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Foundation, Package Manager
Labels Task
Assignee @spevans
Priority Medium

md5: 7a02398558abf3211afb071c5406cdbb

Issue Description:

`ProcessInfo.processInfo.activeProcessorCount` supports cpusets (https://bugs.swift.org/browse/SR-10611) but ignores CFS quotas. CFS quota is the most common use case since it's the feature used when starting docker containers with the `--cpus` option and the default behavior in Kubernetes (cpusets usage is an option to enable on the admin side in the kubelet configuration so unreachable for common users).
This may lead to Swift code (including Swift Package Manager, and thus the building of Swift code) being terminated unexpectedly because it's trying to parallelize too aggressively.

Steps to reproduce:

```
$ docker run -it --rm --privileged --cpus=2 swift:5.2 swift
Welcome to Swift version 5.2.3 (swift-5.2.3-RELEASE).
Type :help for assistance.
1> import Foundation; ProcessInfo.processInfo.activeProcessorCount
$R0: Int = 4
```

For reference, we implemented that feature in SwiftNIO at apple/swift-nio#1518

@weissi
Copy link
Member

weissi commented May 18, 2020

This also affects SwiftPM. CC @neonichu/@abertelrud

@weissi
Copy link
Member

weissi commented May 18, 2020

@swift-ci create

@swift-ci
Copy link
Contributor Author

Comment by Gautier Delorme (JIRA)

@neonichu @abertelrud since I made the fix in SwiftNIO let me know if it would make sense for me to open a PR in Foundation.

@spevans
Copy link

spevans commented Nov 29, 2020

apple/swift-corelibs-foundation#2931 is a port of the swift-nio PR into swift-corelibs-foundation.

Tested on a local docker instance:

$ docker run -it --rm --privileged --cpus=1 swift-main-test /main-test/usr/bin/swift
Welcome to Swift version 5.3-dev (LLVM d6fb8423828a5e4, Swift 638d5e7be2d38c7).
Type :help for assistance.
  1>  import Foundation; ProcessInfo.processInfo.activeProcessorCount
$R0: Int = 1

$ docker run -it --rm --privileged --cpus=2 swift-main-test /main-test/usr/bin/swift
Welcome to Swift version 5.3-dev (LLVM d6fb8423828a5e4, Swift 638d5e7be2d38c7).
Type :help for assistance.
  1>  import Foundation; ProcessInfo.processInfo.activeProcessorCount
$R0: Int = 2
  
$ docker run -it --rm --privileged --cpus=5 swift-main-test /main-test/usr/bin/swift
Welcome to Swift version 5.3-dev (LLVM d6fb8423828a5e4, Swift 638d5e7be2d38c7).
Type :help for assistance.
  1>  import Foundation; ProcessInfo.processInfo.activeProcessorCount
$R0: Int = 5 

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants