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
Collect server latencies and implement "prefer faster hosts" when creating connections #3178
Comments
A wrapper driver would be able to reconnect. I like the idea |
Is this addressing an actual issue that has been observed to occur? Does this issue occur frequently? Is this expected to be put into a separate optional module/jar or is this expected to be part of the core driver? |
The actual issue is that a single misbehaving replica might cause noticeable issues when creating connections. The most pronounced case is primary switchover.
The driver would attempt each replica in sequence until it detects the primary host. It might take 6*10 = 60 sec. Currently the driver caches "ok, we know this was primary" information, and it enables us to connect to the primary faster. However, we do not cache "ok, we know this host times out, let's try the other hosts to see if they are any better". So I thought we could lower the priority for the servers that are known to have issues (e.g. connect timeouts) |
Is there no topology information? Most systems provide some topology somewhere ? |
The issue is that the current implementation does not handle the case well, and it does not specify "please do not use it, use something else instead". So the users end up with half-workable systems :-/ |
I'm not using that scenario where the driver itself is doing master failover / looping trying to find the next master. Master failover is either via DNS or its AWS RDS. Hmmm. |
This is actually one of the topics I want to bring up in Vancouver at the postgresql dev conference is to find a way to put topology data in the server. Presumably it would be a hook of some kind to accommodate various technologies. Patroni being one, but RDS has a few, I presume Azure and Google have theirs. |
Random thoughts ...
An option might be to start an ExecutorService with 6 threads, test each replica in parallel? (something along the lines of testing the likely candidates in parallel)
Yeah, looks like for the Aurora case, in order to speed up master failover it can connect to a replica instance, read the updated topology to find the new master defined there, then connect/point to new master. Seems like it would be really nice if there could be some standardisation on the topology (common pg views that drivers can read etc). |
Well not every situation is the same. Will be hard to standardize. The aws wrapper drivers uses plugins to deal with this. |
Fair point. Imagine the app starting with a connection pool of 50 connections. A side note: the default mode is |
This is a really good topic as there's only so much you can do without some server changes. And a couple small changes would go a long way.
This is why I like stuff like this being disconnected from the driver itself. Determining which node to connect could be done once by a higher level pool and then it would re-use that information for the entire set of N connections in the pool. Having it done by every JDBC connection on its own gets both the thundering herd situation you're describing and potentially inconsistency between how each connection makes it's determination. This is a pretty complicated topic and I think we should focus on providing the building blocks to build solutions atop it. |
Describe the issue
Currently, pgjdbc connects to hosts in sequential order, however, it becomes suboptimal if one of the hosts experiences issues.
For instance, if connect to
host1
takes 20 seconds, and connect tohost2
takes 0.2 sec.The driver could account for that and prefer connecting to
host2
.Sample implementation:
Cons:
Connection rebalance:
false
formisValid
Unfortunately, "treat idle connection as expired after some time" will not be fully transparent to the application as the application might use
custom_variable_classes
for connection-level variables which would be lost on disconnect. However, we should be fine to (optionally) disconnect when the connection is returned to the connection pool.The text was updated successfully, but these errors were encountered: