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:
@@ -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");
|
||||
}
|
||||
|
||||
@@ -51,7 +51,6 @@ fn echo(mut req: Request, mut res: Response) {
|
||||
|
||||
fn main() {
|
||||
let server = Server::http(Ipv4Addr(127, 0, 0, 1), 1337);
|
||||
let mut listening = server.listen(echo).unwrap();
|
||||
let _guard = server.listen(echo).unwrap();
|
||||
println!("Listening on http://127.0.0.1:1337");
|
||||
listening.await();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user