6

我阅读proc/<pid>/io以测量 SQL 查询的 IO 活动,其中<pid>是数据库服务器的 PID。我在每个查询之前和之后读取值以计算差异并获取请求导致读取和/或写入的字节数。

据我所知,该字段READ_BYTES计算实际的磁盘 IO,同时RCHAR包括更多,例如 linux 页面缓存可以满足的读取(请参阅了解 /proc/[pid]/io 中的计数器以 进行澄清)。这导致了一个假设,即RCHAR应该得出一个等于或大于 的值READ_BYTES,但我的结果与这个假设相矛盾。

我可以想象为 Infobright ICE 获得的结果会产生一些小的块或页面开销(值为 MB):

        Query        RCHAR   READ_BYTES
tpch_q01.sql|    34.44180|    34.89453|
tpch_q02.sql|     2.89191|     3.64453|
tpch_q03.sql|    32.58994|    33.19531|
tpch_q04.sql|    17.78325|    18.27344|

但我完全无法理解 MonetDB 的 IO 计数器(值为 MB):

        Query        RCHAR   READ_BYTES
tpch_q01.sql|     0.07501|   220.58203|
tpch_q02.sql|     1.37840|    18.16016|
tpch_q03.sql|     0.08272|   162.38281|
tpch_q04.sql|     0.06604|    83.25391|

我对包含的假设有误RCHARREAD_BYTES?有没有办法欺骗 MonetDB 可以使用的内核计数器?这里发生了什么?

我可能会补充一点,我会在每次查询之前清除页面缓存并重新启动数据库服务器。我在 Ubuntu 11.10 上,运行内核 3.0.0-15-generic。

4

2 回答 2

4

我只能想到两点:

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/filesystems/proc.txt;hb=HEAD#l1305

1:

1446 read_bytes
1447 ----------
1448
1449 I/O counter: bytes read
1450 Attempt to count the number of bytes which this process really did cause to
1451 be fetched from the storage layer.

我读了“导致从存储层获取”以包括预读,无论如何。

2:

1411 rchar
1412 -----
1413
1414 I/O counter: chars read
1415 The number of bytes which this task has caused to be read from storage. This
1416 is simply the sum of bytes which this process passed to read() and pread().
1417 It includes things like tty IO and it is unaffected by whether or not actual
1418 physical disk IO was required (the read might have been satisfied from
1419 pagecache)

请注意,这没有说明“通过内存映射文件访问磁盘”。我认为这是更可能的原因,并且您的 MonetDB 可能会映射出它的数据库文件,然后对它们执行所有操作。

由于其性质,我不太确定如何检查 mmap 上使用的带宽。

于 2012-05-20T20:47:06.727 回答
0

你也可以阅读Linux内核源代码文件:/include/linux/task_io_accounting.h

struct task_io_accounting {
#ifdef CONFIG_TASK_XACCT
  /* bytes read */
  u64 rchar;
  /*  bytes written */
  u64 wchar;
  /* # of read syscalls */
  u64 syscr;
  /* # of write syscalls */
  u64 syscw;
#endif /* CONFIG_TASK_XACCT */

#ifdef CONFIG_TASK_IO_ACCOUNTING
  /*
   * The number of bytes which this task has caused to be read from
   * storage.
   */
  u64 read_bytes;

  /*
   * The number of bytes which this task has caused, or shall cause to be
   * written to disk.
   */
  u64 write_bytes;

  /*
   * A task can cause "negative" IO too.  If this task truncates some
   * dirty pagecache, some IO which another task has been accounted for
   * (in its write_bytes) will not be happening.  We _could_ just
   * subtract that from the truncating task's write_bytes, but there is
   * information loss in doing that.
   */
  u64 cancelled_write_bytes;
#endif /* CONFIG_TASK_IO_ACCOUNTING */
};
于 2014-05-23T07:25:34.973 回答