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

Behavior of Server connection string option #226

Closed
bgrainger opened this issue Apr 5, 2017 · 10 comments
Closed

Behavior of Server connection string option #226

bgrainger opened this issue Apr 5, 2017 · 10 comments
Milestone

Comments

@bgrainger
Copy link
Member

bgrainger commented Apr 5, 2017

What strategy should the connector use when the Server connection string option contains multiple comma-delimited host names?

  • Ordered: always try the first, fall back to the second, then the third
  • Random: pick one at random
  • Round-robin: use a global synchronized index (that wraps around) and cycle through them in order

The behaviour doesn't seem to be specified in the MySQL documentation, nor described in our docs. I believe we currently do "Ordered". Do we want to provide a guarantee; if so, which behavior is most appropriate?

(I haven't checked the Connector/NET source code to see what it might have done back when it supported comma-delimited host names.)

Related to #225

CC @caleblloyd

@caleblloyd
Copy link
Contributor

caleblloyd commented Apr 6, 2017

I think that if we were going to pick one, "Ordered" is the best implementation.

Master-Slave replication is the most common that I've seen, and when the Master breaks, the Slave is typically promoted to Master, and old Master gets rebuilt as the new Slave. "Ordered" handles this setup.

I can see some benefits to the "Round-robin" implementation if using Active-Active replication, but I believe that is a lot less common.

If we were going to introduce more options, a connection string option that defaults to "Ordered" makes the most sense to me.

@bgrainger
Copy link
Member Author

bgrainger commented Aug 29, 2017

The setup I've most commonly seen is the one given in #318: a single primary and a pool of readonly secondary servers. In that case, you have a "write" connection string and a "read" connection string (and the application picks the connection string to use based on the operations it plans to perform). This lets you "scale out" reads, assuming you have a read-heavy workload and don't need immediate read-after-write (there may be a replication delay).

In this case, round-robin between the secondaries would be the more useful default. However, we could solve everyone's use case by adding another connection string option.

@bgrainger
Copy link
Member Author

bgrainger commented Aug 29, 2017

Possible algorithms could include "ordered", "round-robin", and "leastconn" (cf. HAProxy balance).

@bgrainger bgrainger added this to the 1.0 milestone Oct 22, 2017
bgrainger added a commit to bgrainger/MySqlConnector that referenced this issue Nov 5, 2017
bgrainger added a commit to bgrainger/MySqlConnector that referenced this issue Nov 6, 2017
bgrainger added a commit to bgrainger/MySqlConnector that referenced this issue Nov 7, 2017
bgrainger added a commit that referenced this issue Nov 7, 2017
Implement server load balancing. Fixes #226
@bgrainger
Copy link
Member Author

bgrainger commented Nov 14, 2017

Implemented in 0.31.0.

@kostebudinoski
Copy link

kostebudinoski commented Apr 16, 2020

Is there any way I can tell the load balancer to kick out a server from the cluster in case it is not responsive or unable to connect to the host? This would be great addition if it's not possible at the moment.

I see a possibility in the ILoadBalancer.LoadBalance method to return response of some custom cluster node objects (string that represents the host + boolean that tells if the node is available) + some system timer that checks if there are nodes back to normal and adds them back to the load balancer.

@caleblloyd
Copy link
Contributor

caleblloyd commented Apr 16, 2020

@kostebudinoski you may want to check out MySQL Router for HA functionality

https://dev.mysql.com/doc/mysql-router/8.0/en/

@kostebudinoski
Copy link

kostebudinoski commented Apr 16, 2020

Thanks for your suggestion @caleblloyd, however I don't believe MySQL Router would help me here. We have some custom logic that balances just some db calls across the cluster and some are sent only to the master. Also, their licensing is hard to understand for community edition and don't want to add another dependency to the MySQL Router.

I think MySqlConnector, since it already provides load balancing feature, should also handle connection failures to the server and kick out hosts (for period of time) that are unable to connect to the host after X retries. Shouldn't be that much work.

@kostebudinoski
Copy link

kostebudinoski commented Apr 20, 2020

@bgrainger

@bgrainger
Copy link
Member Author

bgrainger commented Apr 20, 2020

Is there any way I can tell the load balancer to kick out a server from the cluster in case it is not responsive or unable to connect to the host? This would be great addition if it's not possible at the moment.

This is not currently possible but I moved your suggestion to a new issue for discussion.

@kostebudinoski
Copy link

kostebudinoski commented Apr 21, 2020

Thanks!

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

No branches or pull requests

3 participants