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

Using current_runtime always spawns additional thread. #1736

Closed
luben opened this issue Dec 18, 2018 · 8 comments
Closed

Using current_runtime always spawns additional thread. #1736

luben opened this issue Dec 18, 2018 · 8 comments

Comments

@luben
Copy link
Contributor

luben commented Dec 18, 2018

Running the single_threaded example spawns additional thread (though it is supposed to show that it does not need more threads):

$ ps -eLf | grep 'target/release/examples'
luben     1520 15628  1520  0    2 20:38 pts/18   00:00:00 ./target/release/examples/single_threaded
luben     1520 15628  1521  0    2 20:38 pts/18   00:00:00 ./target/release/examples/single_threaded
luben     1554 24569  1554  0    1 20:38 pts/19   00:00:00 grep --color=auto target/release/examples

My understanding is that the new thread is created by: https://github.com/hyperium/hyper/blob/master/src/server/tcp.rs#L32 but I may be wrong.

I have tried to go lower level using hyper::server::conn but was not able to create a truly single-threaded server. Please advice.

@seanmonstar
Copy link
Member

Indeed, you are correct, I wrongly made use of Handle::current(), it should be Handle::default(). I just pushed a fix of this to master: 1d253b4

@carllerche
Copy link

Unfortunately, that API is a hazard that exists due to backwards compat... it should be improved in 0.2.

@seanmonstar
Copy link
Member

@carllerche any reason to not deprecate it?

@carllerche
Copy link

@seanmonstar It is still useful to get a handle to the current reactor and not a lazy handle... but it is by far the minority case.

So, the question is how to reduce the hazard while still being able to access the functionality.

@carllerche
Copy link

Well, and Handle::current can start the global reactor... which was deprecated a while ago...

@seanmonstar
Copy link
Member

Slap a #[deprecated] on Handle::current, and add Handle::current_or_background or something.

@carllerche
Copy link

I don't want anymore background ever :) I wonder if getting a handle to the current reactor should be a fn not on Handle.

reactor::current() or something.

@carllerche
Copy link

But yeah, I'd take a PR for deprecating Handle::current() at the very least... even w/o a replacement should be OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants