-
Notifications
You must be signed in to change notification settings - Fork 652
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
thread configuration (names & QoS on Darwin) #2943
base: main
Are you sure you want to change the base?
Conversation
f5b6b19
to
82af47f
Compare
82af47f
to
aa82870
Compare
### Motivation: On Darwin, QoS (quality of service) of threads plays an important role, especially on Apple Silicon machines with P-cores and E-cores. If you spawn raw threads (like NIOPosix) and use a mechanism that doesn't support QoS propagation (like reading/writing to networks -- like NIOPosix does), it's recommended to default to the main thread's QoS. Otherwise you'll always be at the default QoS for "legacy" threads which means bad latencies, especially on Apple Silicon machines. In a follow-up PR #2943 we're adding better configurability for thread configuration. ### Modifications: Default to main thread QoS on Darwin. ### Result: Better latencies for applications with higher QoS classes.
@@ -70,7 +70,7 @@ public final class MultiThreadedEventLoopGroup: EventLoopGroup { | |||
private let index = ManagedAtomic<Int>(0) | |||
private var eventLoops: [SelectableEventLoop] | |||
private let shutdownLock: NIOLock = NIOLock() | |||
private let threadNamePrefix: String | |||
private let threadNamePrefix: String? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still used?
@@ -108,7 +108,8 @@ public final class MultiThreadedEventLoopGroup: EventLoopGroup { | |||
} | |||
|
|||
private static func setupThreadAndEventLoop( | |||
name: String, | |||
name: String?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come name is optional now?
#endif | ||
|
||
public struct NIOThreadConfiguration: Sendable { | ||
public var threadNamePrefix: Optional<String> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you document how this is used and the recommendations for its value? I know from looking at some examples that "-" is necessary for the various groupings and also that the prefix should be reasonably short.
Can you document what nil
means in this context too?
Motivation:
For the longest time, NIO only had internal APIs to choose the thread names and on Darwin, there was no way to assign the NIO threads certain QoS classes. That meant that on Darwin (e.g. macOS) you would always get poor latencies with NIOPosix, particularly on Apple Silicon machines where NIO might sometimes be restricted to the E-cores.
Modifications:
NIOThreadConfiguration
which lets you configure a thread name prefix & QoS on DarwinResult: