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

Connect to several hosts concurrently to reduce connect lantency #3197

Open
vlsi opened this issue Apr 9, 2024 · 1 comment
Open

Connect to several hosts concurrently to reduce connect lantency #3197

vlsi opened this issue Apr 9, 2024 · 1 comment

Comments

@vlsi
Copy link
Member

vlsi commented Apr 9, 2024

Currently, pgjdbc attempts hosts in order (e.g. in strict order or in shuffle order). It does not work well in case there is one host that does not respond.

It would probably make sense to try concurrent connections if the given host did not respond within a configured time.

For instance, consider we have db1,db2,db3 in connection URL.

  • Try connecting to db1
  • If db1 did not respond within 500ms, start concurrent connections to db2 and db3
  • Return the first workable connection to the end user, and close the others
@sehrope
Copy link
Member

sehrope commented Apr 9, 2024

The SQL Server driver does something similar to this to open sockets in parallel to all resolving IPs for the database host: https://github.com/microsoft/mssql-jdbc/blob/c073e78cd18153b305c29533fe53b02200edf796/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java#L2470-L2602

For the record, I think it's needlessly complicated, non-deterministic, and it's had more than one bug in the past so let's tread carefully. If we do add something like this, is should be opt in as defaulting to creating threadpools or parallel connection is generally a bad idea.

Also, without opt-in, anybody upgrading with multiple resolved hosts would suddenly see connection errors on their server logs for all the "slow" connections as they'd be closed after socket creation but before the full login handshake (and waiting for the handshake to avoid that error is bad for other reasons).

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

No branches or pull requests

2 participants