Bug #68882 Document the time_elapsed/interval part of SHOW INNODB STATUS
Submitted: 7 Apr 2013 18:27 Modified: 24 May 2013 19:48
Reporter: Ted Nyman Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:5.1, 5.5, 5.6 OS:Any
Assigned to: Bugs System CPU Architecture:Any
Tags: documentation, logging

[7 Apr 2013 18:27] Ted Nyman
Description:
The buf_print_io() function in 5.1 and buf_print_io_instance() in 5.5
and 5.6 (http://bazaar.launchpad.net/~mysql/mysql-server/5.5/view/head:/storage/innobase/buf/buf0bu...)
are used prominently by SHOW INNODB STATUS to show data about the buffer
cache. Some of the data is *per second*. For example:

Pages made young 764892283, not young 12854192
8.99 youngs/s, 48.95 non-youngs/s

What is not clear in documentation, or in the STATUS itself, is that the
the per-second calculations are based on the interval between the
last time the status was printed and now.

In buf_stats_get_pool_info():

pool_info->page_not_made_young_rate =
(buf_pool->stat.n_pages_not_made_young
- buf_pool->old_stat.n_pages_not_made_young) / time_elapsed;

And time_elapsed is:

time_elapsed = 0.001 + difftime(current_time,
buf_pool->last_printout_time);

This is not necessarily the incorrect implementation (although one could
imagine setting time_elapsed to be standard, say 1 minute), but it has 
important side-effects. Consider the case where a statistics gathering tool
regularly accesses this stat every 10 minutes. It would correctly show
changes over time — in the evening, say, the rate would decrease. 

However, imagine that an administrator or another stats gathering tool
runs SHOW INNODB STATUS 20 seconds before the every-10-minutes stats gathering tool does.
Now, since the interval is based on last printout, the per-second 
stat recorded this time around is not based on a 10 minute interval, but on a 
20 second interval. This may result in what appears to be a spike, or a drop, 
but is in fact an artifact of a different, unexpected polling interval. 

The documentation, for example, "Monitoring the Buffer Pool" in https://dev.mysql.com/doc/refman/5.5/en/innodb-buffer-pool.html, does not indicate 
that the per-second stats depend on the last printout interval. For example:

"youngs/s non-youngs/s: The number of accesses to old pages that have resulted in making them young or not. This metric differs from that of the previous item in two ways. First, it relates only to old pages. Second, it is based on number of accesses to pages and not the number of pages. (There can be multiple accesses to a given page, all of which are counted.)"

https://dev.mysql.com/doc/refman/5.5/en/innodb-monitors.html does not mention it either.

SHOW INNODB STATUS itself *does* at least give this data on its very first line:

"Per second averages calculated from the last 18 seconds"

However, there is no indication of *what* determines that interval — that is only clear from reading
source.

How to repeat:
Read documentation, compare with source

Suggested fix:
Improve documentation to describe how the interval for calculation is actually determined.
[8 Apr 2013 12:04] MySQL Verification Team
Thank you for the bug report.
[24 May 2013 19:48] Bugs System
The reference manual has been updated to include information regarding per second averages provided in InnoDB Monitor output and how the calculation is  based on the elapsed time between the current time and the last 
time InnoDB Monitor output was printed.

Thank you for the bug report.