feat(server): Rewrite the accept loop into a custom thread pool.

This is a modified and specialized thread pool meant for
managing an acceptor in a multi-threaded way. A single handler
is provided which will be invoked on each stream.

Unlike the old thread pool, this returns a join guard which
will block until the acceptor closes, enabling friendly behavior
for the listening guard.

The task pool itself is also faster as it only pays for message passing
if sub-threads panic. In the optimistic case where there are few panics,
this saves using channels for any other communication.

This improves performance by around 15%, all the way to 105k req/sec
on my machine, which usually gets about 90k.

BREAKING_CHANGE: server::Listening::await is removed.
This commit is contained in:
Jonathan Reem
2015-02-13 23:08:13 -08:00
parent f554c09e12
commit 3528fb9b01
5 changed files with 158 additions and 80 deletions

View File

@@ -13,6 +13,7 @@ fn hello(_: Request, res: Response) {
}
fn main() {
hyper::Server::http(Ipv4Addr(127, 0, 0, 1), 3000).listen(hello).unwrap();
let _listening = hyper::Server::http(Ipv4Addr(127, 0, 0, 1), 3000)
.listen(hello).unwrap();
println!("Listening on http://127.0.0.1:3000");
}