简体   繁体   English

通过 MySQL JDBC 驱动程序进行负载平衡 (Connector/J)

[英]Load balancing via MySQL JDBC driver (Connector/J)

I have been exploring MySQL JDBC driver and understand that it is able to do load balancing with this url ("jdbc:mysql:loadbalance://").我一直在探索 MySQL JDBC 驱动程序并了解它能够使用此 url ("jdbc:mysql:loadbalance://") 进行负载平衡。

I looked into the documentation and it seems that only random and best response time methods are used for load balancing (link: http://dev.mysql.com/doc/refman/5.0/es/connector-j-reference-configuration-properties.html syntax is loadBalanceStrategy).我查看了文档,似乎只有随机和最佳响应时间方法用于负载平衡(链接: http : //dev.mysql.com/doc/refman/5.0/es/connector-j-reference-configuration- properties.html语法是 loadBalanceStrategy)。

Questions问题

  1. Is there a way to configure roundrobin as the load balancing strategy for the JDBC driver?有没有办法将 roundrobin 配置为 JDBC 驱动程序的负载平衡策略? I understand that other load balancing methods may be better but I am trying to use the round-robin method for my experiments.我知道其他负载平衡方法可能更好,但我正在尝试使用循环方法进行实验。
  2. Is it a good idea to implement load balancing (I am open to whichever load balancing strategy) for MySQL ndb cluster (Multimaster with synchronous replication)?为 MySQL ndb 集群(具有同步复制的多主控)实现负载平衡(我对任何负载平衡策略持开放态度)是个好主意吗? By the way, I have only 2 machines acting as masters and both are able to receive writes and reads.顺便说一下,我只有 2 台机器充当主站,并且都能够接收写入和读取。 Although MySQL mentioned the use of the JDBC driver with ndb cluster (refer to quote 1 below), I was wondering if using load balancing for a multimaster ndb cluster would actually worsen the performance (refer to quote 2)?尽管 MySQL 提到在 ndb 集群中使用 JDBC 驱动程序(请参阅下面的引用 1),但我想知道对多主 ndb 集群使用负载平衡是否实际上会降低性能(请参阅引用 2)?
  1. Quoted from https://dev.mysql.com/doc/refman/5.1/en/mysql-cluster-basics.html - "MySQL clients using a MySQL Cluster as a data source can be modified to take advantage of the ability to connect with multiple MySQL servers to achieve load balancing and failover. For example, Java clients using Connector/J 5.0.6 and later can use jdbc:mysql:loadbalance:// URLs (improved in Connector/J 5.1.7) to achieve load balancing transparently; for more information about using Connector/J with MySQL Cluster, see Using Connector/J with MySQL Cluster."引自https://dev.mysql.com/doc/refman/5.1/en/mysql-cluster-basics.html - “可以修改使用 MySQL 集群作为数据源的 MySQL 客户端以利用连接能力与多个MySQL服务器实现负载均衡和故障转移,例如使用Connector/J 5.0.6及更高版本的Java客户端可以使用jdbc:mysql:loadbalance:// URLs(在Connector/J 5.1.7中改进)来实现负载均衡透明地;有关将 Connector/J 与 MySQL Cluster 一起使用的更多信息,请参阅将 Connector/J 与 MySQL Cluster 一起使用。”

  2. Quoted from https://dba.stackexchange.com/questions/11789/load-balanced-mysql-cluster-without-load-balancer - "replication delay on production servers might be up to a full second - I have tested this in a remote colocation and in our datacenter and for like 99% of the time it's 0, but sometimes mysql shows 1s. On massive traffic I had many collisions due to client application making two requests resulting in two queries, insert and select. For some cases, the row just wasn't there yet, so We used hash of the userID and it fixed the problem"引自https://dba.stackexchange.com/questions/11789/load-balanced-mysql-cluster-without-load-balancer - “生产服务器上的复制延迟可能长达一整秒 - 我已经在一个远程托管和在我们的数据中心,大约 99% 的时间是 0,但有时 mysql 显示 1s。在大量流量中,由于客户端应用程序发出两个请求导致两个查询,插入和选择,我发生了很多冲突。在某些情况下,该行还没有出现,所以我们使用了用户 ID 的哈希值并解决了问题”

In response to Howard's reply, these are some of the things I have done prior to posting this question - I have tried to use roundRobinLoadBalance as part of the JDBC connection string (URL) but an error occurred stating that it was not supported.作为对 Howard 的回复的回应,这些是我在发布此问题之前所做的一些事情 - 我曾尝试使用 roundRobinLoadBalance 作为 JDBC 连接字符串 (URL) 的一部分,但发生错误,指出它不受支持。 A search on the internet also shows that other people also face problem with trying to use roundRobinLoadBalance.互联网上的搜索也显示其他人在尝试使用 roundRobinLoadBalance 时也面临问题。 Hence I was trying to see if there is another way to do it.因此,我试图看看是否有另一种方法可以做到。

Q1) Is there a way to configure roundrobin as the load balancing strategy? Q1)有没有办法将roundrobin配置为负载均衡策略?

Round-roubin's load balancing algorithm gives each server an equal load. Round-roubin 的负载均衡算法给每个服务器一个相等的负载。 When all servers' performances are the same then it makes sense to use it.当所有服务器的性能都相同时,使用它是有意义的。

Weighted round-robin on the other hand allows load balancing configuration for each server.另一方面,加权循环允许每个服务器的负载平衡配置。 This makes sense when you have servers with different performances.当您拥有不同性能的服务器时,这很有意义。

For example for Glassfish read: Weighted Round Robin例如 Glassfish 阅读: Weighted Round Robin

Q2) Is it a good idea to implement load balancing (I am open to whichever load balancing strategy) for MySQL ndb cluster (Multimaster with synchronous replication)? Q2) 为 MySQL ndb 集群 (Multimaster with synchronous replication) 实施负载均衡(我对任何负载均衡策略持开放态度)是个好主意吗? By the way, I have only 2 machines acting as masters and both are able to receive writes and reads.顺便说一下,我只有 2 台机器充当主站,并且都能够接收写入和读取。 Although MySQL mentioned the use of the JDBC driver with ndb cluster (refer to quote 1 below), I was wondering if using load balancing for a multimaster ndb cluster would actually worsen the performance (refer to quote 2)?尽管 MySQL 提到在 ndb 集群中使用 JDBC 驱动程序(请参阅下面的引用 1),但我想知道对多主 ndb 集群使用负载平衡是否实际上会降低性能(请参阅引用 2)?

If the two servers are identical in performance, there is no need to configure the load balancing.如果两台服务器性能相同,则无需配置负载均衡。 It will distrbute the load to each node equally.它将负载平均分配到每个节点。

In round-robin, load-balancing will utilize each server equally.在循环中,负载平衡将平等地利用每个服务器。

If one server is faster and more powerful than the other, you might want to use the weighted round-robin to configure more load on the faster server.如果一台服务器比另一台更快、更强大,您可能希望使用加权循环在更快的服务器上配置更多负载。

References :参考资料

http://docs.oracle.com/cd/E26576_01/doc.312/e24934/http-load-balancing.htm http://msdn.microsoft.com/en-us/library/ff648960.aspx http://docs.oracle.com/cd/E26576_01/doc.312/e24934/http-load-balancing.htm http://msdn.microsoft.com/en-us/library/ff648960.aspx

我认为您可以尝试自己实现com.mysql.jdbc.BalanceStrategy。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM