actix-web icon indicating copy to clipboard operation
actix-web copied to clipboard

[Windows] Web Client is unreasonably slow

Open kateabr opened this issue 3 years ago • 4 comments

Reproduce snippet:

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    let sys_time = std::time::SystemTime::now();
    let start_time = sys_time.elapsed().unwrap();

    let client = actix_web::client::Client::builder()
        .connector(actix_web::client::Connector::new()
            .timeout(Duration::from_secs(35))
            .finish())
        .timeout(Duration::from_secs(35))
        .finish();

    let response = client.get("https://google.com")
        .send()
        .await
        .unwrap()
        .body()
        .await
        .unwrap();
    let end_time = sys_time.elapsed().unwrap();
    let secs = end_time - start_time;
    println!("{}", secs.as_secs());
    return Ok(());
}

This code prints "20" on Windows, i.e. get request to Google takes 20 seconds.

Same code on Linux (WSL2) takes 0 seconds.

I don't have any clues what might be wrong, but perhaps it's related to DNS resolution?

Cargo.toml:

// ...

[dependencies]
actix-web = { version = "3", features = ["rustls"] }

kateabr avatar Jun 06 '21 19:06 kateabr

Can you try this code using the awc beta?

robjtede avatar Jun 06 '21 20:06 robjtede

Check with Wireshark for instance, if you connect on basis of HTTP/1.0 or HTTP/1.1. 1.0 is a performance hit, so forcing it to use HTTP/1.1 or even HTTP/2 should speed up. Wireshark helps a lot with debugging weird activity on your connectivity, filter connection on basis of port 80 or 443 (SSL), Wireshark let you read out the packets it send and receive as well, and could help determining where the issue could be.

Power2All avatar May 14 '23 11:05 Power2All

1.0 is a performance hit, so forcing it to use HTTP/1.1 or even HTTP/2 should speed up.

@Power2All how can we force 1.1? I've tried using the Upgrade header to request 1.1, but actix-web continues to use 1.0. I can't find any documentation in the actix-web docs about how to set the protocol. Additional context: I'm running locally on Windows 10.

klcantrell avatar Jun 04 '23 13:06 klcantrell

@Power2All how can we force 1.1?

Apache does return a HTTP/1.1 when a HTTP/1.0 or even HTTP/0.9 is received. This way you can force the usage of HTTP/1.1 The upgrade header only works on HTTP/1.1, HTTP/1.0 and lower doesn't have this function.

Power2All avatar Jun 09 '23 14:06 Power2All