actix / actix-web

Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.
https://actix.rs
Apache License 2.0
21.41k stars 1.66k forks source link

[Windows] Web Client is unreasonably slow #2256

Open kateabr opened 3 years ago

kateabr commented 3 years ago

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"] }
robjtede commented 3 years ago

Can you try this code using the awc beta?

Power2All commented 1 year ago

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.

klcantrell commented 1 year ago

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.

Power2All commented 1 year ago

@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.