8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

19.4.7 提高复制性能19.4.7 Improving Replication Performance

随着连接到源的副本数量增加,负载虽然很小,但也会增加,因为每个副本都使用一个客户端连接到源。同时,由于每个副本必须接收源二进制日志的完整副本,源的网络负载也可能增加,从而造成瓶颈。As the number of replicas connecting to a source increases, the load, although minimal, also increases, as each replica uses a client connection to the source. Also, as each replica must receive a full copy of the source's binary log, the network load on the source may also increase and create a bottleneck.

如果您使用大量副本连接到一个源,并且该源也在忙于处理请求(例如,作为扩展解决方案的一部分),那么您可能希望提高复制过程的性能。If you are using a large number of replicas connected to one source, and that source is also busy processing requests (for example, as part of a scale-out solution), then you may want to improve the performance of the replication process.

提高复制过程性能的一种方法是创建更深层次的复制结构,使源只能复制到一个副本,而其余副本则连接到这个主副本,以满足各自的复制需求。此结构的示例如图 19.3,“使用额外的复制源来提高性能”所示。One way to improve the performance of the replication process is to create a deeper replication structure that enables the source to replicate to only one replica, and for the remaining replicas to connect to this primary replica for their individual replication requirements. A sample of this structure is shown in Figure 19.3, “Using an Additional Replication Source to Improve Performance”.

图 19.3 使用额外的复制源来提高性能Figure 19.3 Using an Additional Replication Source to Improve Performance

The server MySQL Source 1 replicates to the server MySQL Source 2, which in turn replicates to the servers MySQL Replica 1, MySQL Replica 2, and MySQL Replica 3.

为使其正常工作,您必须按以下方式配置 MySQL 实例:For this to work, you must configure the MySQL instances as follows:

  • 源 1 是主源,所有更改和更新都写入数据库。两台源服务器均启用了二进制日志,这是默认设置。Source 1 is the primary source where all changes and updates are written to the database. Binary logging is enabled on both source servers, which is the default.

  • 源 2 是服务器源 1 的副本,为复制结构中的其余副本提供复制功能。源 2 是唯一被允许连接源 1 的机器。源 2 已启用 --log-replica-updates 选项(默认)。启用此选项后,来自源 1 的复制指令也会写入源 2 的二进制日志,以便随后可以复制到真正的副本上。Source 2 is the replica to the server Source 1 that provides the replication functionality to the remainder of the replicas in the replication structure. Source 2 is the only machine permitted to connect to Source 1. Source 2 has the --log-replica-updates option enabled (the default). With this option, replication instructions from Source 1 are also written to Source 2's binary log so that they can then be replicated to the true replicas.

  • 副本 1、副本 2 和副本 3 作为源 2 的副本,复制来自源 2 的信息,而这些信息实际上是源 1 上记录的更新。Replica 1, Replica 2, and Replica 3 act as replicas to Source 2, and replicate the information from Source 2, which actually consists of the upgrades logged on Source 1.

上述方案减少了主源的客户端负载和网络接口负载,在作为直接数据库解决方案使用时,应能提高主源的整体性能。The above solution reduces the client load and the network interface load on the primary source, which should improve the overall performance of the primary source when used as a direct database solution.

如果你的副本在跟上源端的复制过程方面遇到困难,有多种可选方案:If your replicas are having trouble keeping up with the replication process on the source, there are a number of options available:

  • 如果可能,将中继日志和数据文件放在不同的物理驱动器上。为此,请设置 relay_log 系统变量以指定中继日志的位置。If possible, put the relay logs and the data files on different physical drives. To do this, set the relay_log system variable to specify the location of the relay log.

  • 如果二进制日志文件和中继日志文件的读取存在大量磁盘 I/O 活动问题,可以考虑增加 rpl_read_size 系统变量的值。该系统变量控制从日志文件读取的最小数据量,增加它可能会减少在操作系统尚未缓存文件数据时的文件读取和 I/O 停顿。请注意,每个从二进制日志和中继日志文件读取的线程都会分配一个与此值大小相同的缓冲区,包括源服务器上的转储线程和副本上的协调线程。因此,设置较大的值可能会影响服务器的内存消耗。If heavy disk I/O activity for reads of the binary log file and relay log files is an issue, consider increasing the value of the rpl_read_size system variable. This system variable controls the minimum amount of data read from the log files, and increasing it might reduce file reads and I/O stalls when the file data is not currently cached by the operating system. Note that a buffer the size of this value is allocated for each thread that reads from the binary log and relay log files, including dump threads on sources and coordinator threads on replicas. Setting a large value might therefore have an impact on memory consumption for servers.

  • 如果副本明显比源慢,您可能需要将复制不同数据库的责任分配给不同的副本。请参见 第 19.4.6 节,“将不同数据库复制到不同副本”。If the replicas are significantly slower than the source, you may want to divide up the responsibility for replicating different databases to different replicas. See Section 19.4.6, “Replicating Different Databases to Different Replicas”.

  • 如果您的源使用事务且您不关心副本上的事务支持,请在副本上使用 MyISAM 或其他非事务存储引擎。请参见 第 19.4.4 节,“在源和副本使用不同存储引擎的复制”。If your source makes use of transactions and you are not concerned about transaction support on your replicas, use MyISAM or another nontransactional engine on the replicas. See Section 19.4.4, “Using Replication with Different Source and Replica Storage Engines”.

  • 如果您的副本不充当源,并且您已经有一个潜在的解决方案来确保在发生故障时可以启用一个源,那么您可以禁用 log_replica_updates。这可以防止“愚蠢的”副本也将它们执行的事件记录到自己的二进制日志中。If your replicas are not acting as sources, and you have a potential solution in place to ensure that you can bring up a source in the event of failure, then you can disable log_replica_updates. This prevents “dumb” replicas from also logging events they have executed into their own binary log.