Choosing a good InnoDB log file size is key to InnoDB write performance. This can be done by measuring the amount of writes in the redo logs. You can find a detailed explanation in this post.

To sum up, here are the main points:

  • The redo logs should be large enough to store at most an hour of logs at peak-time
  • You can either use the LSN in the SHOW ENGINE INNODB STATUS OUTPUT or the Innodb_os_log_written global status variable (if you are a Percona Server user, the LSN is also given by the Innodb_lsn_current status variable)

While reviewing the recommendation I made for a customer, one of my colleagues told me I was wrong in my redo log size calculations. After each one double checked the calculations, it turned out that we experienced something not expected:

  • Using Innodb_os_log_written, I found that around 7.15 GB of redo logs were written per hour
  • Using the LSN, my colleague found 2.70 GB/hour (almost a 3x difference!)

Something was obviously wrong in our understanding of how to measure the amount of writes in the redo logs. Let’s first have a look at what the documentation says. It states that

  • Innodb_os_log_written is the number of bytes written to the log file
  • The LSN is an arbitrary, ever-increasing value [that] represents a point in time corresponding to operations recorded in the redo log

What is not obvious from the documentation is that while Innodb_os_log_written is incremented when the log file is written, the LSN is incremented when the log buffer is written.

This is interesting. It means that the durability setting can skew the results: if innodb_flush_log_at_trx_commit is set to 0, you can accidentally omit or add 1 second of write activity. Of course if you measure variations over 60s, this will not explain a 3x difference with the LSN. It also means that if the write workload is very non uniform, you can easily get very different numbers if you are not taking measures exactly at the same time for the 2 methods.

However, the write workload had not so much variance in my case. I also ran a test with a constant write workload (a mono-threaded script that inserts one row at a time in a table, as fast as it can) and I ended up with the same result: numbers were very different between the 2 methods. Even stranger, the innodb_os_log_written method consistently gave higher numbers than the LSN method, when we would have expected the opposite.

It was time for digging into the source code. All the credits should actually be given to Alexey Kopytov, who not only took the time to read the code again and to make tests, but who also caught something we all missed: writing to the redo logs and increasing the LSN have completely different logics.

The LSN simply shows the byte offset, so when you write 100 bytes to the log buffer, the LSN is increased by 100.
Writing to the redo logs is a much more complicated process: every write is a 512-byte write and there can be overlapping writes. Not clear? Let’s look at an example when innodb_flush_log_at_trx_commit is set to 1 or 2 (again, thanks Alexey):

  • Transaction 1 writ+es 100 bytes to the log buffer
  • At commit, InnoDB writes a 512-byte block at offset xxx and increments Innodb_os_log_written by 512 bytes
  • Transaction 2 writes 200 bytes to the log buffer
  • At commit, InnoDB appends those 200 bytes to the same log block and overwrites the same 512-byte file block at offset xxx, then increases Innodb_os_log_written by another 512 bytes

At this point, the LSN has increased by 300 and Innodb_os_log_written by 1024 (a 3x difference!). This means that the documentation is correct: Innodb_os_log_written is the number of bytes written to the redo logs. But it does not reflect the growth of the redo logs.

So when you are trying to size the redo logs, looking at the LSN variations is a much better approximation than looking at the Innodb_os_log_written variations, which can be significantly far from the reality. However keep in mind that even the LSN is an approximate metric: if your write workload is non uniform and your sampling interval too short, you may well underestimate or overestimate the growth of your redo logs.

参考:

http://www.percona.com/blog/2012/10/08/measuring-the-amount-of-writes-in-innodb-redo-logs/

http://dev.mysql.com/doc/refman/5.6/en/server-status-variables.html#statvar_Innodb_os_log_written

Measuring the amount of writes in InnoDB redo logs的更多相关文章

  1. 14.7.2 Changing the Number or Size of InnoDB Redo Log Files 改变InnoDB Redo Log Files的数量和大小

    14.7.2 Changing the Number or Size of InnoDB Redo Log Files 改变InnoDB Redo Log Files的数量和大小 改变 InnoDB ...

  2. 14.2.3 InnoDB Redo Log

    14.2.3 InnoDB Redo Log 14.2.3.1 Group Commit for Redo Log Flushing redo log 是一个基于磁盘数据结构的用于在crash 恢复正 ...

  3. 14.5.2 Changing the Number or Size of InnoDB Redo Log Files 改变InnoDB Redo Log Files的数量

    14.5.2 Changing the Number or Size of InnoDB Redo Log Files 改变InnoDB Redo Log Files的数量 改变InnoDB redo ...

  4. 调整innodb redo log files数目和大小的具体方法和步骤

    相较于Oracle的在线调整redo日志的数目和大小,mysql这点则有所欠缺,即使目前的mysql80版本,也不能对innodb redo日志的数目和大小进行在线调整,下面仅就mysql调整inno ...

  5. MySQL · 引擎特性 · InnoDB redo log漫游(转)

    前言 InnoDB 有两块非常重要的日志,一个是undo log,另外一个是redo log,前者用来保证事务的原子性以及InnoDB的MVCC,后者用来保证事务的持久性. 和大多数关系型数据库一样, ...

  6. 2. 更改InnoDB redo日志文件的数量或大小

    2. 更改InnoDB redo日志文件的数量或大小 要更改InnoDB 重做日志文件的数量或大小,请执行以下步骤: 1)停止MySQL服务器,确保正常关闭且没有错误发生 2) 编辑my.cnf以更改 ...

  7. 14.5.7 Storing InnoDB Undo Logs in Separate Tablespaces 存储InnoDB Undo logs 到单独的表空间

    14.5.7 Storing InnoDB Undo Logs in Separate Tablespaces 存储InnoDB Undo logs 到单独的表空间 在MySQL 5.6.3,你可以存 ...

  8. 14.2.4 InnoDB Undo Logs

    14.2.4 InnoDB Undo Logs : 一个Undo log (或者成为回滚段) 是一个存储区域 持有被活动事务修改的数据的copy. 如果另外的事务需要看原始的数据(作为一致性读操作的一 ...

  9. Performing User-Managed Database-18.4、Restoring Datafiles and Archived Redo Logs

    18.4.Restoring Datafiles and Archived Redo Logs 假定介质故障损坏的一个或多个数据文件,数据文件必须恢复损坏的文件之前恢复. 该位置是不是想恢复原来姿势. ...

随机推荐

  1. memcpy的用法及实现

    memcpy函数的功能是从源src所指的内存地址的起始位置开始拷贝n个字节到目标dest所指的内存地址的起始位置中,返回dest所指内存地址的起始位置. #include <string.h&g ...

  2. 调用未绑定的父类方法和使用supper 函数 之间的选择.

    class New_int(int): # 定义一个新的类 继承 int 类 def __add__(self,other): # 重写 + 运算符 # __add__ 就是 int 中 + 的行为 ...

  3. 沙盒密探——可实现的js缓存攻击

    我们描述了第一次完全运行在浏览器端的微结构单通道攻击.与其他参和这种类型的相反,这种攻击不再需要攻击者在肉鸡上安装任何软件,为了让攻击更容易,肉鸡仅仅需要浏览哪些攻击者控制的不被信任的网页内容.这会让 ...

  4. squid 延伸

    #openssl req -new -x509 -days 365 -nodes -out stunnel.pem -keyout stunnel.pem # openssl gendh 512> ...

  5. lower_bound和upper_bound算法

    参考:http://www.cnblogs.com/cobbliu/archive/2012/05/21/2512249.html ForwardIter lower_bound(ForwardIte ...

  6. csdn第四名

    编号:1027时间:2016年7月18日11:10:42功能:csdn第四名URL :http://blog.csdn.net/yuanmeng001

  7. elfutils-libelf由于依赖而安装失败

    在Redhat安装Oracles前需要按照依赖包,但是在安装elfutils-libelf遇到了两个包相互依赖的情况 [root@rhvm1 /]# rpm -i elfutils-libelf-de ...

  8. Linux磁盘文件的命名

    磁盘的常用接口有两种:IDE和SATA接口,目前主流的是SATA接口. IDE接口由IDE扁平电缆线连接,一个电缆可连接两个IDE接口,通常主机又都会提供两个IDE接口,因此最多可以接到四个IDE设备 ...

  9. ss命令使用示例

    导读 ss是Socket Statistics的缩写,可以用来获取socket统计信息,它可以显示和netstat类似的内容.但ss的优势在于它能够显示更多更详细的有关TCP和连接状态的信息,而且比n ...

  10. c 函数及指针学习 5

    聚合数据类型 能够同时存储超过一个的单独数据. c语言提供了数组和结构体. 1. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #include <stdio.h> # ...