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

refactor(server): remove unneeded Send + Sync #1275

Merged
merged 1 commit into from
Sep 22, 2017

Conversation

spinda
Copy link
Contributor

@spinda spinda commented Jul 26, 2017

Http and Server placed Send + Sync bounds on NewService implementations which
were not actually required given tokio's event loop model. Remove them to reduce
limitations on end users of hyper.

Http and Server placed Send + Sync bounds on NewService implementations which
were not actually required given tokio's event loop model. Remove them to reduce
limitations on end users of hyper.
@spinda
Copy link
Contributor Author

spinda commented Jul 26, 2017

Motivating scenario: I have a Service whose call method makes use of a RefCell, since the self parameter of call is forced to be an immutable reference and I need to mutate some shared state according to requests processed. RefCell does not have Send + Sync, however, so without this change I'd have to use something more costly like Arc, when internally hyper only executes call on the same thread as run anyway.

@seanmonstar
Copy link
Member

Hey there, thanks for the PR!

The bounds there were actually on purpose, even though it may seem unnecessary at the moment. The goal has been that eventually the TcpServer in tokio-proto would be able to do all the hyper's Server can, and would use that. To do so, since the TcpServer can start listening on multiple threads, to prepare for the move, the Send + Sync bounds exist.

You can use a Service without those bounds if you manage a Core yourself, instead of using Http::bind.

@spinda
Copy link
Contributor Author

spinda commented Jul 27, 2017

Ah, I see. Would it make sense to have an explicitly single-threaded version of bind without these bounds, to implement the boilerplate of managing a Core directly? (which could for the moment call into the current path for bind under the hood, since it's not yet multithreaded)

@seanmonstar
Copy link
Member

Possibly. I'm not sure what sort of API that would look like though.

@spinda
Copy link
Contributor Author

spinda commented Jul 28, 2017

Perhaps keep Server single-threaded, drop the bounds from it, and introduce a ParallelServer with Send + Sync equivalent to the current Server type? Then a bind_parallel method on Http which produces a ParallelServer.

@seanmonstar
Copy link
Member

Sorry it took so long, I wasn't sure that this should be done, but I'm now in favor. Anyone wanting to use the multi-threaded server can do it themselves or use TcpServer. No need to have restrictions for people who don't want it.

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants