Hi all, just wondering if anyone's familiar with hyper's connection pooling for client requests.
I can't seem to find any docs on it?
EDIT: So it looks like it's actually enabled by default, but I'm not sure how to go about configuring it for a pool of more than 1.
ogeon
2
Looks like there's Client::with_pool_config, which may be useful.
skade
3
Note the documentation. The number of threads is per host, 1 is definitely a reasonable default here and it shouldn't be tuned too high.
Hmm, so it looks like it's basically all wired up out of the box. Maybe I'll just add a keep alive header to a request and see what happens.
EDIT: Ok so it worked. Kudos to hyper
. Adding a keep_alive
header to a request did just work. In a test benchmark:
//With keep_alive
took mean 369578ns
//Without keep_alive
took mean 874433ns
Thanks for the help 
1 Like
Istvan
5
I am wondering how do you do that? Would you mind sharing the code with keep_alive enabled?
Sure, you can specify keep_alive
using the Connection
header:
let client = hyper::Client::new();
let response = client
.get("http://some-host:8080")
.header(hyper::header::Connection::keep_alive())
.send();
2 Likes
No problem
Also make sure you use the same hyper::Client
instance to ensure those connections stay open across requests.
1 Like
@KodrAus Can you paste your code where you pass + reuse a hyper::Client with keep-alives enables between functions?
1 Like