reqwest
reqwest copied to clipboard
HTTP/2 Client Only Allows 200 Concurrent Requests?
Hi there,
I'm running an Axum-based server with HTTP/2 enabled and attempting to perform load testing using reqwest. My goal is to gauge the server's QPS (queries per second) capacity by concurrently firing off 100,000 requests from a single reqwest::Client, with a 30-second timeout set on the client side.
When the Axum handler simply returns the client's SocketAddr, I observe port reuse across a few thousand ports, which seems efficient.
However, when the handler involves an asynchronous 20-second sleep before returning the SocketAddr, the client rapidly exhausts over 28,000 ports, resulting in "error sending" for remaining requests. This behavior resembles HTTP/1.1, where new ports are sought when existing ones are blocked, leading to errors if the OS (Linux, in this case) cannot allocate fresh ports within the timeout.
To overcome this and potentially boost QPS, I switched to HTTP/2 requests by employing reqwest::ClientBuilder::http2_prior_knowledge(). This change indeed centralizes all requests to originate from a single port, and the server confirms receipt of HTTP/2 traffic.
The issue now lies in the fact that only 200 requests can be simultaneously sent out by the client; any additional requests beyond this threshold fail with a timeout error.
My question: How can I adjust the client-side code to maximize the number of concurrent requests to the server? I'm seeking a configuration or approach that would allow for a significantly higher degree of parallelism under HTTP/2.
Thank you in advance for any guidance or suggestions!
send 200 requests:
1 - prepared_time: 750.21µs
1 - received_time: 20.052651004s
1 - average_time: 20.048665899s
1 - counter.len: 1
1 - counter: {
"HTTP/2.0 127.0.0.1:63198": 200,
}
send 1000 requests:
1 - prepared_time: 4.79075ms
1 - received_time: 30.010249502s
1 - average_time: 20.012567259s
1 - counter.len: 2
1 - counter: {
"HTTP/2.0 127.0.0.1:62096": 200,
"error sending request for url (http://0.0.0.0:3000/)": 800,
}