Skip to content

Conversation

@glbrntt
Copy link
Contributor

@glbrntt glbrntt commented Nov 6, 2024

Motivation:

The thread performance checker warns that a threads with QoS are waiting on threads in the NIOThreadPool. We can avoid these warnings by using a condition variable instead.

Modifications:

  • Replace the usage of a semaphore and lock in NIOThreadPool with a condition lock.
  • The condition value indicates whether the threads have work to do (where work is processing work items or exiting their run loop).

Result:

Motivation:

The thread performance checker warns that a threads with QoS are waiting
on threads in the NIOThreadPool. We can avoid these warnings by using a
condition variable instead.

Modifications:

- Replace the usage of a semaphore and lock in NIOThreadPool with a
  condition lock.
- The condition value indicates whether the threads have work to do
  (where work is processing work items or exiting their run loop).

Result:

Fewer warnings
@glbrntt glbrntt added the 🔨 semver/patch No public API change. label Nov 6, 2024
@glbrntt glbrntt requested a review from Lukasa November 7, 2024 13:37

case .shuttingDown, .stopped:
return []
return (unlockWith: .hasWork, result: [])
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this state right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. I don't think we need to unlock with a value here, if we're already shutting down then we've already signalled there's work for the threads to do, we don't need to do that again.


case .shuttingDown, .stopped:
return body
workState = .hasWork
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question here. It might be useful to write out the strategy for the lock value in a comment above it, which will make it easier to audit.

@glbrntt glbrntt requested a review from Lukasa November 11, 2024 16:11
@Lukasa Lukasa merged commit af0e612 into apple:main Nov 19, 2024
41 of 42 checks passed
@glbrntt glbrntt deleted the nio-thread-pool-warnings branch November 19, 2024 11:41
Lukasa pushed a commit to Lukasa/swift-nio that referenced this pull request Nov 22, 2024
Motivation:

The thread performance checker warns that a threads with QoS are waiting
on threads in the NIOThreadPool. We can avoid these warnings by using a
condition variable instead.

Modifications:

- Replace the usage of a semaphore and lock in NIOThreadPool with a
condition lock.
- The condition value indicates whether the threads have work to do
(where work is processing work items or exiting their run loop).

Result:

- Fewer warnings
- Resolves apple#2960

(cherry picked from commit af0e612)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NIOFileSystem operations thread warnings

2 participants