Consider the following guidelines for optimizing redo logging:考虑优化重做日志记录的下列准则:
Make your redo log files big, even as big as the buffer pool. 让重做日志文件变大,甚至和缓冲池一样大。When 当InnoDB
has written the redo log files full, it must write the modified contents of the buffer pool to disk in a checkpoint. InnoDB
将重做日志文件写满后,它必须将缓冲池的修改内容写入检查点中的磁盘。Small redo log files cause many unnecessary disk writes. 小的重做日志文件会导致许多不必要的磁盘写入。Although historically big redo log files caused lengthy recovery times, recovery is now much faster and you can confidently use large redo log files.虽然历史上较大的重做日志文件会导致较长的恢复时间,但现在恢复速度要快得多,您可以放心地使用较大的重做日志文件。
The size and number of redo log files are configured using the 重做日志文件的大小和数量使用innodb_log_file_size
and innodb_log_files_in_group
configuration options. innodb_log_file_size
和innodb_log_files_in_group
配置选项进行配置。For information about modifying an existing redo log file configuration, see Changing the Number or Size of Redo Log Files.有关修改现有重做日志文件配置的信息,请参阅更改重做日志文件的数量或大小。
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. 因此,如果您有更新、插入或删除多行的事务,那么增大日志缓冲区可以节省磁盘I/O。Log buffer size is configured using the 日志缓冲区大小使用innodb_log_buffer_size
configuration option, which can be configured dynamically in MySQL 8.0.innodb_Log_buffer_size
配置选项进行配置,该选项可以在MySQL 8.0中动态配置。
Configure the 配置innodb_log_write_ahead_size
configuration option to avoid “read-on-write”. innodb_log_write_ahead_size
配置选项以避免“写时读”。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. innodb_log_write_ahead_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.由于重做日志的预写块大小与操作系统或文件系统缓存块大小不匹配,重做日志块未完全缓存到操作系统或文件系统时,会发生读写。
Valid values for innodb_log_write_ahead_size
are multiples of the InnoDB
log file block size (2n). innodb_log_write_ahead_size
的有效值是InnoDB
日志文件块大小(2n)的倍数。The minimum value is the 最小值是InnoDB
log file block size (512). InnoDB
日志文件块大小(512)。Write-ahead does not occur when the minimum value is specified. 当指定最小值时,不会发生提前写入。The maximum value is equal to the 最大值等于innodb_page_size
value. innodb_page_size
值。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
指定的值大于innodb_page_size
值,则innodb_log_write_ahead_size
设置将被截断为innodb_page_size
值。
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. innodb_log_write_ahead_size
值相对于操作系统或文件系统缓存块大小设置得太低会导致读写。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.fsync
性能产生轻微影响。
MySQL 8.0.11 introduced 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. MySQL 8.0.11引入了专用的日志编写器线程,用于将重做日志记录从日志缓冲区写入系统缓冲区,并将系统缓冲区刷新到重做日志文件。Previously, individual user threads were responsible those tasks. 以前,单独的用户线程负责这些任务。As of MySQL 8.0.22, you can enable or disable log writer threads using the 从MySQL 8.0.22开始,可以使用innodb_log_writer_threads
variable. innodb_log_writer_threads
变量启用或禁用日志编写器线程。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
: 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.默认值为400微秒。
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. :定义用户线程在等待刷新重做时不再旋转的最小CPU使用量。The value is expressed as a sum of CPU core usage. 该值表示为CPU核心使用量的总和。For example, The default value of 80 is 80% of a single CPU core. 例如,默认值80是单个CPU核心的80%。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.在具有多核处理器的系统上,值150表示一个CPU核心的使用率为100%,另一个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. :定义用户线程在等待刷新重做时不再旋转的最大CPU使用量。The value is expressed as a percentage of the combined total processing power of all CPU cores. 该值表示为所有CPU内核总处理能力的百分比。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.默认值为50%。例如,两个CPU核的100%使用率是一个有四个CPU核的服务器上CPU处理能力总和的50%。
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.例如,如果一台服务器有48个内核,但mysqld
进程只固定在4个CPU内核上,那么其他44个CPU内核将被忽略。