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

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 17 InnoDB 存储引擎 / 17.8 InnoDB 配置 / 17.8.6 在 Linux 上使用异步 I/O
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

17.8.6 在 Linux 上使用异步 I/O17.8.6 Using Asynchronous I/O on Linux

InnoDB 在 Linux 上使用异步 I/O 子系统(本地 AIO)来执行数据文件页的预读和写入请求。此行为由 innodb_use_native_aio 配置选项控制,仅适用于 Linux 系统,且默认启用。在其他类 Unix 系统上,InnoDB 仅使用同步 I/O。历史上,InnoDB 仅在 Windows 系统上使用异步 I/O。在 Linux 上使用异步 I/O 子系统需要 libaio 库。InnoDB uses the asynchronous I/O subsystem (native AIO) on Linux to perform read-ahead and write requests for data file pages. This behavior is controlled by the innodb_use_native_aio configuration option, which applies to Linux systems only and is enabled by default. On other Unix-like systems, InnoDB uses synchronous I/O only. Historically, InnoDB only used asynchronous I/O on Windows systems. Using the asynchronous I/O subsystem on Linux requires the libaio library.

在同步 I/O 中,查询线程将 I/O 请求排入队列,InnoDB 后台线程按顺序处理这些排队请求,每个请求发出一个同步 I/O 调用。当 I/O 请求完成并且 I/O 调用返回时,处理该请求的 InnoDB 后台线程会调用 I/O 完成例程,并返回继续处理下一个请求。可以并行处理的请求数量为 n,其中 n 是 InnoDB 后台线程的数量。InnoDB 后台线程的数量由 innodb_read_io_threads 和 innodb_write_io_threads 控制。参见 第 17.8.5 节,“配置后台 InnoDB I/O 线程的数量”。With synchronous I/O, query threads queue I/O requests, and InnoDB background threads retrieve the queued requests one at a time, issuing a synchronous I/O call for each. When an I/O request is completed and the I/O call returns, the InnoDB background thread that is handling the request calls an I/O completion routine and returns to process the next request. The number of requests that can be processed in parallel is n, where n is the number of InnoDB background threads. The number of InnoDB background threads is controlled by innodb_read_io_threads and innodb_write_io_threads. See Section 17.8.5, “Configuring the Number of Background InnoDB I/O Threads”.

使用本地 AIO 时,查询线程直接向操作系统分发 I/O 请求,从而消除了后台线程数量所施加的限制。InnoDB 后台线程等待 I/O 事件以通知已完成的请求。当请求完成时,后台线程调用 I/O 完成例程并继续等待 I/O 事件。With native AIO, query threads dispatch I/O requests directly to the operating system, thereby removing the limit imposed by the number of background threads. InnoDB background threads wait for I/O events to signal completed requests. When a request is completed, a background thread calls an I/O completion routine and resumes waiting for I/O events.

本地 AIO 的优势在于可扩展性,适用于通常在 SHOW ENGINE INNODB STATUS 输出中显示许多待处理读取和写入的 I/O 密集型系统。使用本地 AIO 时并行处理的增加意味着 I/O 调度器类型或磁盘阵列控制器的属性对 I/O 性能的影响更大。The advantage of native AIO is scalability for heavily I/O-bound systems that typically show many pending reads and writes in SHOW ENGINE INNODB STATUS output. The increase in parallel processing when using native AIO means that the type of I/O scheduler or properties of the disk array controller have a greater influence on I/O performance.

对严重受 I/O 限制的系统而言,本地 AIO 的一个潜在缺点是无法控制一次向操作系统发送的 I/O 写请求数量。向操作系统发送过多用于并行处理的 I/O 写请求,在某些情况下可能会导致 I/O 读饥饿,这取决于 I/O 活动的量和系统的能力。A potential disadvantage of native AIO for heavily I/O-bound systems is lack of control over the number of I/O write requests dispatched to the operating system at once. Too many I/O write requests dispatched to the operating system for parallel processing could, in some cases, result in I/O read starvation, depending on the amount of I/O activity and system capabilities.

如果操作系统中异步 I/O 子系统的问题阻止 InnoDB 启动,您可以使用 innodb_use_native_aio=0 来启动服务器。如果 InnoDB 检测到潜在问题,例如 tmpdir 位置、tmpfs 文件系统以及 Linux 内核组合不支持在 tmpfs 上进行异步 I/O,该选项也可能在启动时自动禁用。If a problem with the asynchronous I/O subsystem in the OS prevents InnoDB from starting, you can start the server with innodb_use_native_aio=0. This option may also be disabled automatically during startup if InnoDB detects a potential problem such as a combination of tmpdir location, tmpfs file system, and Linux kernel that does not support asynchronous I/O on tmpfs.