Load Balancing Connector
Load Balancing Connector
Connector/J has long provided an effective means to distribute read/write load across multiple
MySQL server instances for Cluster or source-source replication deployments. You can
dynamically configure load-balanced connections, with no service outage. In-process
transactions are not lost, and no application exceptions are generated if any application is trying
to use that particular server instance.
The load balancing is configured at the initial setup stage of the server connection by the
following connection URL, which has a similar format as the general JDBC URL for MySQL
connection, but a specialized scheme:
jdbc:mysql:loadbalance://[host1][:port],[host2][:port][,[host3][:port]]...[/
[database]] »
[?propertyName1=propertyValue1[&propertyName2=propertyValue2]...]
There are two configuration properties associated with this functionality:
Add host.
Remove host.
The JMX
interface, com.mysql.cj.jdbc.jmx.LoadBalanceConnectionGroupManagerMBean, has the
following methods:
int getActiveHostCount(String group);
int getTotalHostCount(String group);
long getTotalLogicalConnectionCount(String group);
long getActiveLogicalConnectionCount(String group);
long getActivePhysicalConnectionCount(String group);
long getTotalPhysicalConnectionCount(String group);
long getTotalTransactionCount(String group);
void removeHost(String group, String host) throws SQLException;
void stopNewConnectionsToHost(String group, String host) throws
SQLException;
void addHost(String group, String host, boolean forExisting);
String getActiveHostsList(String group);
String getRegisteredConnectionGroups();
The getRegisteredConnectionGroups() method returns the names of all connection groups
defined in that class loader.
You can test this setup with the following code: