延迟写

传统的UNIX实现在内核中设有缓冲区高速缓存或页面高速缓存,大多数磁盘I/O都通过缓冲进行。当将数据写入文件时,内核通常先将该数据复制到其中一个缓冲区中,如果该缓冲区尚未写满,则并不将其排入输出队列,而是等待其写满或者当内核需要重用该缓冲区以便存放其他磁盘块数据时,再将该缓冲排入输出队列,然后待其到达队首时,才进行实际的I/O操作。这种输出方式被称为延迟写(delayed write)(Bach [1986]第3章详细讨论了缓冲区高速缓存)。

"延迟写"减少了磁盘读写次数,但是却降低了文件内容的更新速度,使得欲写到文件中的数据在一段时间内并没有写到磁盘上。当系统发生故障时,这种延迟可能造成文件更新内容的丢失。为了保证磁盘上实际文件系统与缓冲区高速缓存中内容的一致性,UNIX系统提供了sync、fsync和fdatasync三个函数。
sync函数只是将所有修改过的块缓冲区排入写队列,无需等待写磁盘操作便返回。系统守护进程(update)会周期性(30秒)调用sync函数来刷新内存缓冲区。

fsync函数只对由文件描述符filedes指定的单一文件起作用,需要等待写磁盘操作结束后才返回,确保修改过的数据被写入到磁盘。fsync不但更新数据,还更新指定文件元数据(如修改时间和访问时间)。

fdatasync函数与fsync函数类似,但fdatasync函数只更新数据,而不更新指定文件的属性。

由于fsync函数除需要更新数据外,还需要更新文件元数据(metadata,包括文件大小/访问时间/修改时间等),因此fsync函数需要两次写,而fdatasync函数值需要一次写。

Unfortunately fsync() will alwaysalways initialize two write operations: one for the newly written data and another one in order to update the modification time stored in the inode. 
If the modification time is not a part of the transaction concept fdatasync() can be used to avoid unnecessary inode disk write operations.

参数innodb_flush_method

参数innodb_flush_method有在Unix上有6个可选值:fsync/O_DSYNC/littlesync/nosync/O_DIRECT/O_DIRECT_NO_FSYNC,由于littlesync/nosync风险较高,常用的下面4种:

fsync:默认值,使用fsync()系统调用来刷新数据文件和日志文件

O_DSYNC:使用O_SYNC打开和刷新日志文件,使用fsync()刷新数据文件。(在很多UNIX版本上直接使用O_DSYNC会存在问题)

O_DIRECT:使用O_DIRECT打开数据文件,使用fsync()来刷新数据文件和日志文件。(O_DIRECT在大部分UNIX系统上可用)

O_DIRECT_NO_FSYNC:在Flush IO操作时使用O_DIRECT,但在每次write操作时跳过fsync()系统调用。(O_DIRECT_NO_FSYNC在MySQL 5.6.6版本引入,但不适合XFS和EXT4文件系统)

生产环境中使用innodb_flush_method=O_DIRECT

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 after each write operation.

This setting is not suitable for file systems such as XFS and EXT4, which require an fsync() system call to synchronize file system metadata changes. If you are not sure whether your file system requires an fsync() system call to synchronize file system metadata changes, use O_DIRECT instead.

On storage devices with cache, data loss is possible if data files and redo log files reside on different storage devices, and a crash occurs before data file writes are flushed from the device cache. If you use or intend to use different storage devices for redo logs and data files, use O_DIRECT instead.

如果使用带缓存的RAID控制器,推荐使用O_DIRECT来避免操作系统和存储系统两次缓存。

如果使用SAN存储来存放数据文件和日志文件,对于读负载较高的存储系统,使用fsync()或O_DSYNC可能更快。

摘抄连接:

https://www.cnblogs.com/gomysql/p/3595806.html

https://www.cnblogs.com/bhlsheji/p/5222271.html

https://dev.mysql.com/doc/refman/5.6/en/innodb-parameters.html

MySQL Config--参数innodb_flush_method的更多相关文章

  1. mysql服务器参数

    mysql服务器参数: 配置是从上往下读取,同一个参数项,后边的配置项会覆盖前边的配置项 mysql获取配置信息路径: 命令行参数    mysqld_safe  --datadir=/data/sq ...

  2. mysql核心参数优化

    MySQL数据库服务器配置CPU的优化内存的优化IO的优化连接的优化数据一致性的优化 1.描述back_log参数的作用? back_log = 500 要求 MySQL 能有的连接数量.当主要MyS ...

  3. 【查阅】mysql配置文件/参数文件重要参数笔录(my.cnf)

    持续更新,积累自己对参数的理解 [1]my.cnf参数 [client]port = 3306socket = /mysql/data/3306/mysql.sockdefault-character ...

  4. Mysql性能参数优化

    1.Max_connections (1)简介 Mysql的最大连接数,如果服务器的并发请求量比较大,可以调高这个值,当然这是要建立在机器能够支撑的情况下,因为如果连接数越来越多,mysql会为每个连 ...

  5. 1201MySQL配置文件mysql.ini参数详解

    转自http://www.cnblogs.com/feichexia/archive/2012/11/27/mysqlconf.html my.ini(Linux系统下是my.cnf),当mysql服 ...

  6. (转)MySQL配置文件mysql.ini参数详解、MySQL性能优化

    本文转自:http://www.cr173.com/html/18331_1.html my.ini(Linux系统下是my.cnf),当mysql服务器启动时它会读取这个文件,设置相关的运行环境参数 ...

  7. MySQL配置文件mysql.ini参数详解、MySQL性能优化

    my.ini(Linux系统下是my.cnf),当mysql服务器启动时它会读取这个文件,设置相关的运行环境参数. my.ini分为两块:Client Section和Server Section.  ...

  8. MySQL配置文件mysql.ini参数详解

    my.ini(Linux系统下是my.cnf),当mysql服务器启动时它会读取这个文件,设置相关的运行环境参数. my.ini分为两块:Client Section和Server Section. ...

  9. 在Linux最大打开文件数限制下 MySQL 对参数的调整

    http://www.actionsky.com/docs/archives/78  2016年4月7日  周文雅 目录 1 起因 2 说明 3 MySQL调整参数的方式 3.1 计算 request ...

随机推荐

  1. Layui 模板引擎中的 日期格式化

    原文:https://www.jianshu.com/p/948a474b5ed7 原文:https://blog.csdn.net/DCFANS/article/details/92064112 模 ...

  2. 洛谷P5021 赛道修建

    题目 首先考虑二分,然后发现最小长度越大的话,赛道就越少.所以可以用最终的赛道个数来判断长度是否合理.问题转化为给定一个长度,问最多有多少条互不重叠路径比这个给定长度大. 考虑贪心,毕竟贪心也是二分c ...

  3. HTML5 - websocket的应用 之 简易聊天室

    需要知识点: 前端知识 jq操作dom nodejs socket.io 关于websocket api的知识点,见上篇章<HTML5-Websocket>. 聊天室思路/原理: A和B聊 ...

  4. Salesforce 开发整理(五)代码开发最佳实践

    在Salesforce项目实施过程中,对项目代码的维护可以说占据极大的精力,无论是因为项目的迭代,还是需求的变更,甚至是项目组成员的变动,都不可避免的需要维护之前的老代码,而事实上,几乎没有任何一个项 ...

  5. debian/ubuntu安装mssql

    添加源: debian源:deb [arch=amd64] https://packages.microsoft.com/debian/10/prod buster main ubuntu源:deb ...

  6. 配置keepalived支持nginx高可用

    实验环境 序号 主机名 IP地址 1 nginx1 192.168.204.11 2 nginx2 192.168.204.12 安装nginx 安装nginx yum install -y epel ...

  7. Golang微服务实践

    背景 在之前的文章<漫谈微服务>我已经简单的介绍过微服务,微服务特性是轻量级跨平台和跨语言的服务,也列举了比较了集中微服务通信的手段的利弊,本文将通过RPC通信的方式实现一个增删查Redi ...

  8. 2、word插入目录、图/表

    一.word插入目录 依次对每个标题在“段落”中进行大纲级别选择. 光标定位于目录生成的页面,再“引用”->“目录”->选择“自动目录1/2”,则可自动生成目录.若目录有所更改,则可选择“ ...

  9. [转帖]分布式锁-redLock And Redisson

    分布式锁-redLock And Redisson 2019-03-01 16:51:48 淹不死的水 阅读数 372更多 分类专栏: 分布式锁   版权声明:本文为博主原创文章,遵循CC 4.0 B ...

  10. 微信企业微信调试JS神器vConsole

    在js页面上放以下代码 <script src='https://cdn.bootcss.com/vConsole/3.3.2/vconsole.min.js'></script&g ...