Skip to content

allow completely single-threaded NIO programs #1499

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

Merged
merged 2 commits into from
May 11, 2020

Conversation

weissi
Copy link
Member

@weissi weissi commented May 1, 2020

Motivation:

Usually, you spawn a new MultiThreadedEventLoopGroup to run NIO
programs. But if you're a very simple command line utility, that may not
be necessary, so why not just re-use the main thread?

Modifications:

Allow taking over threads and making them EventLoops.

Result:

Fewer threads if you want.

@weissi weissi requested review from Lukasa and glbrntt May 1, 2020 15:19
Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Generally seems good, one question and one piece of feedback.

@Lukasa Lukasa added the 🆕 semver/minor Adds new public API. label May 1, 2020
@Lukasa Lukasa added this to the 2.17.0 milestone May 1, 2020
@weissi weissi force-pushed the jw-single-threaded-nio branch from 89b5271 to bca1a32 Compare May 1, 2020 17:20
@weissi
Copy link
Member Author

weissi commented May 1, 2020

@glbrntt / @Lukasa I agree that it's weird to call this on MultiThreadedEventLoopGroup but I didn't find a better place. I'm happy adding a new NIOTakeOverEventLoop namespace and nest it under there?

I felt it's not really worth adding a new top-level namespace for a function that'll be as rarely used as this one so I put it into MTELG and thought we can always (deprecate) move it elsewhere in the future. But 100% open to moving it.

@Davidde94
Copy link
Contributor

@swift-server-bot test this please

@tomerd
Copy link
Member

tomerd commented May 1, 2020

this is great @weissi, can be very useful in one of our projects. thanks!

Motivation:

Usually, you spawn a new MultiThreadedEventLoopGroup to run NIO
programs. But if you're a very simple command line utility, that may not
be necessary, so why not just re-use the main thread?

Modifications:

Allow taking over threads and making them EventLoops.

Result:

Fewer threads if you want.
@weissi weissi force-pushed the jw-single-threaded-nio branch from 19ed719 to a3b0d29 Compare May 4, 2020 14:00
Copy link
Contributor

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Ok great, let's ship this.

@Lukasa Lukasa merged commit 5821c53 into apple:master May 11, 2020
pull bot pushed a commit to scope-demo/swift-nio that referenced this pull request May 11, 2020
Motivation:

Usually, you spawn a new MultiThreadedEventLoopGroup to run NIO
programs. But if you're a very simple command line utility, that may not
be necessary, so why not just re-use the main thread?

Modifications:

Allow taking over threads and making them EventLoops.

Result:

Fewer threads if you want.

Co-authored-by: Cory Benfield <lukasa@apple.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants