关于innodb_flush_log_at_trx_commit、innodb_flush_method、innodb_log_block_size和fsync()、O_DIRECT、iops、云盘的关系与总结
想着整理关于innodb_flush_log_at_trx_commit、innodb_flush_method、innodb_log_block_size和fsync()、O_DIRECT、iops的关系,纯属这两天处理http://www.cnblogs.com/zhjh256/p/6519032.html帖子的问题,顺便整理下,以备下次不用各处重新汇总。
innodb_flush_log_at_trx_commit用于控制commit的时候log_buffer同步到磁盘的行为,跟oracle中commit_logging、commit_wait参数的作用大同小异吧。不管如何最后都会触发写入disk的行为。这就涉及到innodb_log_block_size和innodb_flush_method了,innodb_log_block_size用于设置innodb log的逻辑大小,默认512,SSD或者ext4下可以选择4096(主要是ext4 fs bs改成4096的原因),具体差别到底多大,没特别仔细测试,反正往上各种答案都有,不过大体差别在15%以内。innodb_flush_method用于InnoDB 控制刷新数据文件和日志文件的行为,根据是否SSD、RAID、SAN或者云盘,不同的配置是会影响IO吞吐量的。取值如下:
- fdatasync(默认,oracle mysql默认为
fsync): use fsync() to flush both the data and log files. - O_SYNC: use O_SYNC to open and flush the log files; use fsync() to flush the data files.
- O_DIRECT: use O_DIRECT to open the data files and fsync() system call to flush both the data and log files.
- O_DIRECT_NO_FSYNC: use O_DIRECT to open the data files but don’t use fsync() system call to flush both the data and log files. This option isn’t suitable for XFS file system.
- ALL_O_DIRECT: use O_DIRECT to open both data and log files, and use fsync() to flush the data files but not the log files. This option is recommended when InnoDB log files are big (more than 8GB), otherwise there might be even a performance degradation. Note: When using this option on ext4 filesystem variable innodb_log_block_size should be set to 4096 (default log-block-size in ext4) in order to avoid the unaligned AIO/DIO warnings.
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, see Section 8.5.8, “Optimizing InnoDB Disk I/O”.
再看下fsync()/fdatasync(),它是linux提供的系统调用。
fsync() transfers ("flushes") all modified in-core data of (i.e.,
modified buffer cache pages for) the file referred to by the file
descriptor fd to the disk device (or other permanent storage device)
so that all changed information can be retrieved even after the
system crashed or was rebooted. This includes writing through or
flushing a disk cache if present. The call blocks until the device
reports that the transfer has completed. It also flushes metadata
information associated with the file。
没什么特别需要解释的,主要是刷新更改数据的缓存到磁盘或者磁盘驱动器自带的缓存。
最后的重点是O_DIRECT和O_SYNC选项。这些选项主要是系统调用open()(http://man7.org/linux/man-pages/man2/open.2.html)时使用的选项。
O_DIRECT:读写文件时尽量最小化的使用缓存,绕过操作系统的缓存,常用于具有自己缓存的应用比如数据库,所以特别适用于具有自身缓存的存储。
O_SYNC:write()+fsync()。
所以,应该来说对于SAN/云盘来讲,可能还是ALL_O_DIRECT会合适些。 iops,就非DSS系统来说,主要还是关注4k/8/16k为主的顺序写为主,随机io意义不大,因为绝大部分数据都cache在sga/buffer pool中,所以主要还是redo的写入占据绝大部分,checkpoint占据小部分random io。该值要依赖于innodb_flush_log_at_trx_commit、innodb_flush_method、innodb_log_block_size(因为mysql的innodb_log和binlog是分开的,所以还涉及到sync_binlog的值),不同的组合会有不同的tps,因此最差情况下可能是低于dd/iometer/orion测试出来iops的1/2。
除此之外,还有一个无法控制的因素,即使innodb_flush_log_at_trx_commit=1,innodb_flush_method=O_DIRECT,也不意味着一次commit就是一次fsync,因为os可以决定多个同时commit合并到一个fsync,所以这一点而言,只能是极端情况下每commit/fsync,当然按照这么估计也是合理的。
具体多少范围合理,一定程度上还是依赖于经验。
最后,就要说到在云盘了,云盘技术上来说就是SAN的机制,所以对于写入很频繁、但是有没有采用SSD盘的数据库就很尴尬了,因为系统盘只有40G,剩余可用估计也就20G左右,此时如果innodb_flush_log_at_trx_commit=1,如何同时保证不丢失数据、满足性能要求,然后就呵呵考验DBA和架构师的水平了。 PS: 网上找了张对比图,目前常用的linux iops测试工具有如下:

从上面可以发现,其中少了fio,主要是fio会损坏文件系统,所以一般不推荐使用。
iometer使用可参考:http://www.linuxidc.com/Linux/2010-09/28918.htm
关于innodb_flush_log_at_trx_commit、innodb_flush_method、innodb_log_block_size和fsync()、O_DIRECT、iops、云盘的关系与总结的更多相关文章
- 全球首个百万IOPS云盘即将商业化 阿里云推出超高性能云盘ESSD
近日,在经过近半年的上线公测后,阿里云全球首个跨入IOPS百万时代的云盘——ESSD即将迎来商业化,单盘IOPS高达100万,这是阿里云迄今为止性能最强的企业级块存储服务. 搭配ECS云服务器使用, ...
- read/write/fsync与fread/fwrite/fflush的关系和区别
read/write/fsync: 1. linux底层操作: 2. 内核调用, 涉及到进程上下文的切换,即用户态到核心态的转换,这是个比较消耗性能的操作. fread/fwrite/fflush: ...
- InnoDB O_DIRECT选项漫谈(一)【转】
本文来自:http://insidemysql.blog.163.com/blog/static/2028340422013671186977/ 最近和文件系统内核开发人员做技术交流,对O_DIR ...
- sync fsync fdatasync ---systemtap跟踪
aa.stp: probe kernel .function ( "sys_sync" ) { printf ( "probfunc:%s fun:%s\n", ...
- sysbench测试阿里云ECS云磁盘的IOPS,吞吐量
测试阿里云ECS 对象:在aliyun上买了一个ECS附加的云盘,使用sysbench测试云盘的IOPS和吞吐量 sysbench prepare 准备文件,10个文件,1个1G [root@iZwz ...
- IOPS和Throughput
IOPS和Throughput吞吐量两个参数是衡量存储性能的主要指标.IOPS表示存储每秒传输IO的数量,Throughput吞吐量则表示每秒数据的传输总量.两者在不同的情况下都能表示存储的性能状况, ...
- 磁盘性能评价指标—IOPS和吞吐量
转:http://blog.csdn.net/hanchengxi/article/details/19089589 一.磁盘 I/O 的概念 I/O 的概念,从字义来理解就是输入输出.操作系统从上层 ...
- 论存储IOPS和Throughput吞吐量之间的关系
论存储IOPS和Throughput吞吐量之间的关系 http://www.csdn.net/article/2015-01-14/2823552 IOPS和Throughput吞吐量两个参数是衡量存 ...
- 云数据库将进入企业级百万IOPS时代
IOPS (Input/Output Operations Per Second),即每秒进行读写(I/O)操作的次数,以衡量存储每秒可接受多少次主机发出的访问.数据库,特别是关系型数据库由于需要处理 ...
随机推荐
- 24-Python3 OS
24-Python3 OS ''' OS文件/目录方法 ''' ##os.access():检验权限模式 fo1 = open('/Users/ligaijiang/PycharmProjects/f ...
- AWS EC2 Root密码重置
- mac console color setting
1. 编辑文件 ~/.bash_profile 添加 export CLICOLOR=1 export LSCOLORS=GxFxCxDxBxegedabagaced 2. 加载生效 source ~ ...
- Stephen Wolfram自述
Stephen Wolfram自述 作者: 阮一峰 大家听说过Stephen Wolfram(斯蒂芬·沃尔夫勒姆)吗? 了解他的经历和成就吗? 我对他了解不多,但是读了下面这篇2005年的演讲,联 ...
- Asp.net Core认证和授权:Cookie认证
关于asp.net core 的文章,博客园已经有很多大牛写过了. 这里我只是记录下自己在学习中的点滴和一些不懂的地方 Cookie一般是用户网站授权,当用户访问需要授权(authorization) ...
- string.Format格式化输出
staticstring Format (string format,object arg0):将指定字符串中的一个或多个格式项替换为指定对象的字符串表示形式 (1)格式化货币(跟系统的环境有关,中文 ...
- Oracle如何查询当前的crs/has自启动状态
我们知道在某些停机测试场景,是需要人为禁用crs/has的自启动的,防止过程中主机反复重启对数据库集群造成影响. 使用crsctl disable/enable crs命令可以禁用/启用crs的自启动 ...
- Android -- ViewGroup源码分析+自定义
1,我们前三篇博客了解了一下自定义View的基本方法和流程 从源码的角度一步步打造自己的TextView 深入了解自定义属性 onMeasure()源码分析 之前,我们只是学习过自定义View,其实自 ...
- Oracle / PLSQL函数 - LENGTH和LENGTHB
1.LENGTH( string1 ) 2.LENGTHB( string1 ) 在oracle中,这两个函数都有差不多意思,最大的区别在于:length 求得是字符长度,lengthb求得是字节长度 ...
- hdu5029 树链剖分 + 线段树
将树映射在线段上进行操作 然后每个 重链变成一个连续的区间 #include <iostream> #include <cstdio> #include <strin ...