文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 10 优化 / 10.5 InnoDB 表的优化 / 10.5.4 优化 InnoDB 重做日志记录
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

10.5.4 优化 InnoDB 重做日志记录10.5.4 Optimizing InnoDB Redo Logging

请考虑以下优化重做日志记录的准则:Consider the following guidelines for optimizing redo logging:

  • 增加重做日志文件的大小。当InnoDB已将重做日志文件写满时,它必须在检查点中将缓冲池的修改内容写入磁盘。小重做日志文件会导致许多不必要的磁盘写入。Increase the size of your redo log files. When InnoDB has written redo log files full, it must write the modified contents of the buffer pool to disk in a checkpoint. Small redo log files cause many unnecessary disk writes.

    重做日志文件大小由 innodb_redo_log_capacity 决定。 InnoDB 尝试维护 32 个相同大小的重做日志文件,每个文件等于 1/32 * innodb_redo_log_capacity。因此,更改 innodb_redo_log_capacity 设置会更改重做日志文件的大小。The redo log file size is determined by innodb_redo_log_capacity. InnoDB tries to maintain 32 redo log files of the same size, with each file equal to 1/32 * innodb_redo_log_capacity. Therefore, changing the innodb_redo_log_capacity setting changes the size of the redo log files.

    有关修改重做日志文件配置的信息,请参阅第 17.6.5 节“重做日志”。For information about modifying your redo log file configuration, see Section 17.6.5, “Redo Log”.

  • 考虑增加日志缓冲区的大小。大型日志缓冲区允许大型事务运行,而无需在事务提交之前将日志写入磁盘。因此,如果您有更新、插入或删除许多行的事务,则增大日志缓冲区可以节省磁盘 I/O。日志缓冲区大小使用 innodb_log_buffer_size 配置选项进行配置,该选项可以动态配置。Consider increasing the size of the log buffer. A large log buffer enables large transactions to run without a need to write the log to disk before the transactions commit. Thus, if you have transactions that update, insert, or delete many rows, making the log buffer larger saves disk I/O. Log buffer size is configured using the innodb_log_buffer_size configuration option, which can be dynamically configured.

  • 配置 innodb_log_write_ahead_size 配置选项以避免“写时读”。该选项定义重做日志的预写块大小。设置 innodb_log_write_ahead_size 以匹配操作系统或文件系统缓存块大小。当重做日志块由于重做日志的预写块大小与操作系统或文件系统缓存块大小不匹配而未完全缓存到操作系统或文件系统时,就会发生写时读。Configure the innodb_log_write_ahead_size configuration option to avoid “read-on-write”. This option defines the write-ahead block size for the redo log. Set innodb_log_write_ahead_size to match the operating system or file system cache block size. Read-on-write occurs when redo log blocks are not entirely cached to the operating system or file system due to a mismatch between write-ahead block size for the redo log and operating system or file system cache block size.

    innodb_log_write_ahead_size 的有效值为 InnoDB 日志文件块大小 (2n) 的倍数。最小值是 InnoDB 日志文件块大小 (512)。当指定最小值时,不会发生预写。最大值等于 innodb_page_size 值。如果您为 innodb_log_write_ahead_size 指定的值大于 innodb_page_size 值,innodb_log_write_ahead_size 设置被截断为 innodb_page_size 值。Valid values for innodb_log_write_ahead_size are multiples of the InnoDB log file block size (2n). The minimum value is the InnoDB log file block size (512). Write-ahead does not occur when the minimum value is specified. The maximum value is equal to the innodb_page_size value. If you specify a value for innodb_log_write_ahead_size that is larger than the innodb_page_size value, the innodb_log_write_ahead_size setting is truncated to the innodb_page_size value.

    设置innodb_log_write_ahead_size值过低相对于操作系统或文件系统缓存块大小会导致写时读取。值设置过高可能会对日志文件写入的fsync性能产生轻微影响,因为会一次写入多个块。Setting the innodb_log_write_ahead_size value too low in relation to the operating system or file system cache block size results in read-on-write. Setting the value too high may have a slight impact on fsync performance for log file writes due to several blocks being written at once.

  • MySQL 提供专用的日志写入线程,用于将重做日志记录从日志缓冲区写入到系统缓冲区,并将系统缓冲区刷新到重做日志文件。您可以使用 innodb_log_writer_threads 变量启用或禁用日志编写器线程。专用日志写入线程可以提高高并发系统上的性能,但对于低并发系统,禁用专用日志写入线程可以提供更好的性能。MySQL provides dedicated log writer threads for writing redo log records from the log buffer to the system buffers and flushing the system buffers to the redo log files. You can enable or disable log writer threads using the innodb_log_writer_threads variable. Dedicated log writer threads can improve performance on high-concurrency systems, but for low-concurrency systems, disabling dedicated log writer threads provides better performance.

  • 优化等待刷新重做的用户线程对自旋延迟的使用。旋转延迟有助于减少延迟。在低并发期间,减少延迟可能不太重要,而在这些期间避免使用旋转延迟可能会减少能耗。在高并发期间,您可能希望避免在旋转延迟上消耗处理能力,以便将其用于其他工作。以下系统变量允许设置定义旋转延迟使用边界的高水位线值和低水位线值。Optimize the use of spin delay by user threads waiting for flushed redo. Spin delay helps reduce latency. During periods of low concurrency, reducing latency may be less of a priority, and avoiding the use of spin delay during these periods may reduce energy consumption. During periods of high concurrency, you may want to avoid expending processing power on spin delay so that it can be used for other work. The following system variables permit setting high and low watermark values that define boundaries for the use of spin delay.

    • innodb_log_wait_for_flush_spin_hwm:定义最大平均日志刷新时间,超过该时间用户线程在等待刷新重做时不再旋转。默认值为 400 微秒。innodb_log_wait_for_flush_spin_hwm: Defines the maximum average log flush time beyond which user threads no longer spin while waiting for flushed redo. The default value is 400 microseconds.

    • innodb_log_spin_cpu_abs_lwm:定义最小 CPU 使用量,低于该值用户线程在等待刷新重做时不再旋转。该值表示为 CPU 核心使用率的总和。例如,默认值 80 表示单个 CPU 核心的 80%。在具有多核处理器的系统上,值 150 表示一个 CPU 核心的 100% 使用率加上第二个 CPU 核心的 50% 使用率。innodb_log_spin_cpu_abs_lwm: Defines the minimum amount of CPU usage below which user threads no longer spin while waiting for flushed redo. The value is expressed as a sum of CPU core usage. For example, The default value of 80 is 80% of a single CPU core. On a system with a multi-core processor, a value of 150 represents 100% usage of one CPU core plus 50% usage of a second CPU core.

    • innodb_log_spin_cpu_pct_hwm:定义最大 CPU 使用量,超过此值用户线程在等待刷新重做时不再旋转。该值以所有 CPU 内核总处理能力的百分比表示。默认值为 50%。例如,两个 CPU 核心的 100% 使用率是具有四个 CPU 核心的服务器上总 CPU 处理能力的 50%。innodb_log_spin_cpu_pct_hwm: Defines the maximum amount of CPU usage above which user threads no longer spin while waiting for flushed redo. The value is expressed as a percentage of the combined total processing power of all CPU cores. The default value is 50%. For example, 100% usage of two CPU cores is 50% of the combined CPU processing power on a server with four CPU cores.

      innodb_log_spin_cpu_pct_hwm 配置选项尊重处理器亲和性。例如,如果服务器有 48 个核心,但 mysqld 进程仅固定到 4 个 CPU 核心,则其他 44 个 CPU 核心将被忽略。The innodb_log_spin_cpu_pct_hwm configuration option respects processor affinity. For example, if a server has 48 cores but the mysqld process is pinned to only four CPU cores, the other 44 CPU cores are ignored.