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

Slow connecting to database #2325

Open
mu-arch opened this issue Jan 31, 2023 · 6 comments
Open

Slow connecting to database #2325

mu-arch opened this issue Jan 31, 2023 · 6 comments
Labels

Comments

@mu-arch
Copy link

mu-arch commented Jan 31, 2023

Bug Description

A issue I've experienced lately is that SQLx takes exactly 4.6 seconds to establish connections to my database in debug mode and 500ms on release mode. On my laptop it can take over 10 seconds in debug mode. It's getting blocked doing some type of heavy compute to establish the connection, a single thread is pinned at 100% during this time.

I have used other tools to connect to my database and they do it instantly. In the past SQLx did not exhibit this behavior. I am not sure when it started, or if it is due to some mis-configuration on my end. I have not tried SQLx with other databases than the one I normally use, but I have setup MVP test programs that all exhibit the same behavior.

Minimal Reproduction

let conn_options = PgConnectOptions::new()
        .host("remote.domain.com")
        .username("my_user")
        .password("password")
        .port(26257)
        .database("mydb")
        .application_name("myapp");

    let pool = PgPoolOptions::new()
        .max_connections(200)
        .min_connections(1)
        .idle_timeout(Some(Duration::from_secs(60 * 5)))
        .max_lifetime(Some(Duration::from_secs(60 * 30)))
        .test_before_acquire(false)
        .connect_with(conn_options).await?;

Info

  • SQLx version: 6.2
  • SQLx features enabled: "runtime-tokio-rustls", "postgres", "offline", "uuid", "chrono"
  • Database server and version: CockroachDB v22.2.3
  • Operating system: Debian
  • rustc --version: rustc 1.66.1
@mu-arch mu-arch added the bug label Jan 31, 2023
@mu-arch
Copy link
Author

mu-arch commented Feb 3, 2023

Adding more info, I did tests on version 5.7 of SQLx back when I was sure this used to work fine, but it still has the slow behavior. Since the same thing happens on my laptop it must be the database somehow.

My next step will be trying to get logging out of SQLx or using a tracer to find what it's doing while blocked.

@sj-robert
Copy link

We're seeing this too on postgres, with connections taking around 200ms to be established.

@abonander
Copy link
Collaborator

0.7.4 has a couple of changes meant to improve connection times: #3050 #3055

@sj-robert
Copy link

Nice, we'll test and report back; hopefully this week.

@gitmalong
Copy link

gitmalong commented Aug 4, 2024

Nice, we'll test and report back; hopefully this week.

This issue is still open and meanwhile sqlx 0.8 arrived. Do you mind to report back @sj-robert @mu-arch ?

@sj-robert
Copy link

We're in the middle of vacation periods here, and I'm leaving the office for two weeks on friday, but if I can find the time before then I'll run a test :)

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

No branches or pull requests

4 participants