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

[BUG] Client creation takes 7-10ms #199

Closed
mooreniemi opened this issue Oct 28, 2023 · 3 comments
Closed

[BUG] Client creation takes 7-10ms #199

mooreniemi opened this issue Oct 28, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@mooreniemi
Copy link

What is the bug?

I am following the default tutorial documentation and measured the elapsed time in creating the client. I observe it taking 7-10ms, sometimes slightly more. When search requests (my query workload) are only 20ms - 50ms, and the default implementation of the connection pool is one connection (see #197) which may encourage implementations of creating multiple clients, well, this overhead is significant.

How can one reproduce the bug?

Follow the default tutorial for creating a client and measure the elapsed time (now to elapsed below) to create the client.

    let now = Instant::now();
    let conn_pool = SingleNodeConnectionPool::new(url?);
    let mut headers = headers::HeaderMap::new();
    headers.insert(headers::ACCEPT_ENCODING, "gzip".parse().unwrap());
    let transport = TransportBuilder::new(conn_pool)
        .auth(aws_config.clone().try_into()?)
        .disable_proxy()
        .headers(headers)
        .service_name(service_name)
        .timeout(Duration::from_millis(500))
        .build()?;
    let client = OpenSearch::new(transport);
    let elapsed = now.elapsed();
    println!("creating client elapsed: {:.2?}", elapsed,);

I see, eg.:

creating client elapsed: 9.98ms

What is the expected behavior?

I would expect client initialization to be well below 1ms.

What is your host/environment?

AL2.

@mooreniemi mooreniemi added bug Something isn't working untriaged labels Oct 28, 2023
@mooreniemi
Copy link
Author

A suspicion, it may be due to blocking call for DNS that uses getadderinfo:

https://github.com/hyperium/hyper-util/blob/1ed4c2ccdb23f576eb7024555f08b376b9d5c9eb/src/client/connect/dns.rs#L121

https://docs.rs/hyper/latest/src/hyper/client/connect/dns.rs.html#121

I've seen that take 10-13ms before in Tokio console. Not yet confirmed in this scenario.

@Xtansia Xtansia removed the untriaged label Oct 29, 2023
@Xtansia
Copy link
Collaborator

Xtansia commented Oct 29, 2023

@mooreniemi As I've just responded in #197, you should only be creating and re-using a single client instance, not per-request. In that context I don't believe 7-10ms is particularly bad. If there's obvious superfluous work being done wasting time, then happy to look into improvements, however very little happens in the construction other than building a reqwest::Client which I'd imagine is where most of the time goes. So may mostly be outside our control.

@mooreniemi
Copy link
Author

Makes sense, and I am inclined to agree this is reqwest's fault. Closing as low priority.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants