Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

actix::client first request extremely slow unless you put a static dns in hosts #599

Closed
aohan237 opened this issue Nov 21, 2018 · 13 comments · Fixed by #601
Closed

actix::client first request extremely slow unless you put a static dns in hosts #599

aohan237 opened this issue Nov 21, 2018 · 13 comments · Fixed by #601

Comments

@aohan237
Copy link

aohan237 commented Nov 21, 2018

it may be the dns issue. yes,if you put a static dns in hosts. it will be normal.

but other tools, such as curl will not have the problem. why?

url: https://cn.bing.com

curl is normal.but in actix::client ,is extremely slow

fn main() {
    let now = Instant::now();
    println!("{:?}", now);
    actix::run(
        || client::get("https://cn.bing.com")   // <- Create request builder
            .header("User-Agent", "Actix-web")
            .finish()
            .unwrap()
            .send()                               // <- Send http request
            .map_err(|_| ())
            .and_then(move |response| {                // <- server http response
                println!("Response: {:?}", response);
                println!("{:?}",Instant::now()- now);
                Ok(())
            })
    );
}

it will wait for about 5sec, until it get the first response.

@aohan237 aohan237 changed the title actix::client extremely slow unless you put a static dns in hosts actix::client first request extremely slow unless you put a static dns in hosts Nov 21, 2018
@aohan237
Copy link
Author

or actix has a inner dns loopup function,which use a different dns lookup server rather than a local dns server?

@ghost
Copy link

ghost commented Nov 21, 2018

I also noticed that https is much slower than http

@DoumanAsh
Copy link
Contributor

Actix uses trust-dns-resolver and on first lookup it is going to take a while to build its caches

@aohan237
Copy link
Author

can I disable it ,just use local dns?

@aohan237
Copy link
Author

it is very slow on first, what's the cause you decided to use that?

@DoumanAsh
Copy link
Contributor

Not at the moment, it would require changing the way actix-web uses connector to allow custom one.
https://actix.rs/actix-web/actix_web/client/struct.ClientConnector.html#method.resolver

I had some ideas for changing time, but I didn't have time to work on it.

it is very slow on first, what's the cause you decided to use that?

It is async

@DoumanAsh
Copy link
Contributor

@aohan237 my new PR will allow you to provide address of your own resolver, you'd need to implement own actor that could handle https://actix.rs/actix/actix/actors/resolver/struct.Connect.html

@fafhrd91
Copy link
Member

Actually, you should ask trust-dns author how to fix this problem

@DoumanAsh
Copy link
Contributor

I'm actually not sure if it possible to fix per se, you just need to build DNS cache before making requests, but rising issue on this problem would be good idea

@tuxzz
Copy link

tuxzz commented Dec 11, 2018

Yes it's really slow, takes about 1 minute for first request on my environment.

@damody
Copy link

damody commented Jan 17, 2019

still really slow now.

@tuxzz
Copy link

tuxzz commented Jan 18, 2019

@damody I have a workaround for my situation: Create request builder with IP address and add Host Http header when send request. It works perfect if you have only few domains to request and can ensure the IP address of requested domain won't change.

@damody
Copy link

damody commented Jan 18, 2019

@tuxzz thank you, I will try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants