天天看點

innodb_flush_method

innodb_flush_method這個參數控制着innodb資料檔案及redo log的打開、刷寫模式

 fdatasync模式:寫資料時,write這一步并不需要真正寫到磁盤才算完成(可能寫入到作業系統buffer中就會傳回完成),真正完成是flush操作,buffer交給作業系統去flush,并且檔案的中繼資料資訊也都需要更新到磁盤。

O_DSYNC模式:寫日志操作是在write這步完成,而資料檔案的寫入是在flush這步通過fsync完成

O_DIRECT模式:資料檔案的寫入操作是直接從mysql innodb buffer到磁盤的,并不用通過作業系統的緩沖,而真正的完成也是在flush這步,日志還是要經過OS緩沖

官方解釋:

 Defines the method used to flush data to InnoDB data files and log files, which can affect I/O throughput.

If innodb_flush_method is set to NULL on a Unix-like system, the fsync option is used by default. If innodb_flush_method is set to NULL on Windows, the async_unbuffered option is used by default.

The innodb_flush_method options for Unix-like systems include:

    fsync: InnoDB uses the fsync() system call to flush both the data and log files. fsync is the default setting.

    O_DSYNC: InnoDB uses O_SYNC to open and flush the log files, and fsync() to flush the data files. InnoDB does not use O_DSYNC directly because there have been problems with it on many varieties of Unix.

    littlesync: This option is used for internal performance testing and is currently unsupported. Use at your own risk.

    nosync: This option is used for internal performance testing and is currently unsupported. Use at your own risk.

    O_DIRECT: InnoDB uses O_DIRECT (or directio() on Solaris) to open the data files, and uses fsync() to flush both the data and log files. This option is available on some GNU/Linux versions, FreeBSD, and Solaris.

    O_DIRECT_NO_FSYNC: InnoDB uses O_DIRECT during flushing I/O, but skips the fsync() system call afterward. This setting is suitable for some types of file systems but not others. For example, it is not suitable for XFS. If you are not sure whether the file system you use requires an fsync(), for example to preserve all file metadata, use O_DIRECT instead.

The innodb_flush_method options for Windows systems include:

    async_unbuffered: InnoDB uses Windows asynchronous I/O and non-buffered I/O. async_unbuffered is the default setting on Windows systems.

    normal: InnoDB uses simulated asynchronous I/O and buffered I/O.

    unbuffered: InnoDB uses simulated asynchronous I/O and non-buffered I/O.

How each setting affects performance depends on hardware configuration and workload. Benchmark your particular configuration to decide which setting to use,or whether to keep the default setting. Examine the Innodb_data_fsyncs status variable to see the overall number of fsync() calls for each setting.The mix of read and write operations in your workload can affect how a setting performs. For example, on a system with a hardware RAID controller and battery-backed write cache, O_DIRECT can help to avoid double buffering between the InnoDB buffer pool and the operating system file system cache. On some systems where InnoDB data and log files are located on a SAN, the default value or O_DSYNC might be faster for a read-heavy workload with mostly SELECT statements. Always test this parameter with hardware and workload that reflect your production environment. For general I/O tuning advice

繼續閱讀