InnoDB 在可能的情况下使用异步磁盘 I/O,通过创建多个线程来处理 I/O 操作,同时允许其他数据库操作在 I/O 操作仍在进行时继续进行。在 Linux 和 Windows 平台上,InnoDB 使用可用的操作系统和库函数来执行“本机”异步 I/O。在其他平台上,InnoDB 仍然使用 I/O 线程,但这些线程可能实际上会等待 I/O 请求完成;这种技术被称为“模拟”异步 I/O。InnoDB uses asynchronous disk I/O where
possible, by creating a number of threads to handle I/O
operations, while permitting other database operations to proceed
while the I/O is still in progress. On Linux and Windows
platforms, InnoDB uses the available OS and
library functions to perform “native” asynchronous
I/O. On other platforms, InnoDB still uses I/O
threads, but the threads may actually wait for I/O requests to
complete; this technique is known as “simulated”
asynchronous I/O.
如果 InnoDB 能确定数据很可能很快会被需要,它会执行预读取操作,将这些数据带入缓冲池,以便在内存中可用。对于连续数据,发起几次大规模读取请求比发起多次零散的小请求更高效。InnoDB 有两种预读取启发式方法:If InnoDB can determine there is a high
probability that data might be needed soon, it performs
read-ahead operations to bring that data into the buffer pool so
that it is available in memory. Making a few large read requests
for contiguous data can be more efficient than making several
small, spread-out requests. There are two read-ahead heuristics
in InnoDB:
在顺序预读取中,如果
InnoDB注意到对表空间中某段的访问模式是顺序的,它会提前向 I/O 系统提交一批数据库页的读取请求。In sequential read-ahead, ifInnoDBnotices that the access pattern to a segment in the tablespace is sequential, it posts in advance a batch of reads of database pages to the I/O system.在随机预读取中,如果
InnoDB注意到表空间中的某些区域似乎正在被完全读入缓冲池,它会向 I/O 系统提交剩余的读取请求。In random read-ahead, ifInnoDBnotices that some area in a tablespace seems to be in the process of being fully read into the buffer pool, it posts the remaining reads to the I/O system.
有关配置预读启发式的信息,请参见 第 17.8.3.4 节,“配置 InnoDB 缓冲池预取(预读)”。For information about configuring read-ahead heuristics, see Section 17.8.3.4, “Configuring InnoDB Buffer Pool Prefetching (Read-Ahead)”.
InnoDB 使用一种新颖的文件刷新技术,涉及称为 双写缓冲区 的结构,该结构在大多数情况下默认启用 (innodb_doublewrite=ON)。它在意外退出或断电后增加了恢复的安全性,并通过减少 fsync() 操作的需求,提高了大多数 Unix 系统的性能。InnoDB uses a novel file flush technique
involving a structure called the
doublewrite
buffer, which is enabled by default in most cases
(innodb_doublewrite=ON). It
adds safety to recovery following an unexpected exit or power
outage, and improves performance on most varieties of Unix by
reducing the need for fsync() operations.
在将页面写入数据文件之前,InnoDB 会先将它们写入一个称为双写缓冲区的存储区域。只有在写入并刷新到双写缓冲区完成之后,InnoDB 才会将页面写入数据文件中的正确位置。如果在页面写入过程中操作系统、存储子系统或意外的 mysqld 进程退出(导致 碎片页面 情况),InnoDB 可以在恢复过程中从双写缓冲区找到页面的正常副本。Before writing pages to a data file, InnoDB
first writes them to a storage area called the doublewrite
buffer. Only after the write and the flush to the doublewrite
buffer has completed does InnoDB write the
pages to their proper positions in the data file. If there is an
operating system, storage subsystem, or unexpected
mysqld process exit in the middle of a page
write (causing a torn page
condition), InnoDB can later find a good copy
of the page from the doublewrite buffer during recovery.
有关 doublewrite 缓冲区的更多信息,请参见 第 17.6.4 节,“Doublewrite 缓冲区”。For more information about the doublewrite buffer, see Section 17.6.4, “Doublewrite Buffer”.