【问题标题】:FIO runtime different than gettimeofday()FIO 运行时不同于 gettimeofday()
【发布时间】:2017-03-14 23:12:45
【问题描述】:

我正在尝试测量 FIO 基准测试的执行时间。我目前正在这样做在 gettimeofday() 之间包装 FIO 调用:

gettimeofday(&startFioFix, NULL);
FILE* process = popen("fio --name=randwrite --ioengine=posixaio rw=randwrite --size=100M --direct=1 --thread=1 --bs=4K", "r");
gettimeofday(&doneFioFix, NULL);

并将经过的时间计算为:

double tstart = startFioFix.tv_sec + startFioFix.tv_usec / 1000000.;
double tend = doneFioFix.tv_sec + doneFioFix.tv_usec / 1000000.;
double telapsed = (tend - tstart);

现在,问题是

  1. 经过的时间与 FIO 输出的 runt 不同(更大)。你能帮我理解为什么吗?事实可以在 FIO 输出中看到:

    randwrite: (g=0): rw=randwrite, bs=4K-4K/4K-4K/4K-4K, ioengine=posixaio, iodepth=1
    fio-2.2.8
    Starting 1 thread
    
    randwrite: (groupid=0, jobs=1): err= 0: pid=3862: Tue Nov  1 18:07:50 2016
    write: io=102400KB, bw=91674KB/s, iops=22918, runt=  1117msec
    ...
    

    而 telapsed 是:

    telapsed: 1.76088 seconds
    
  2. FIO 执行的实际时间是多少: a) FIO 给出的 runt,或 b) getttimeofday() 所经过的时间

  3. FIO 如何衡量其runt? (可能这个问题与 1 有关。)

PS:我试图替换 gettimeofday(用 std::chrono::high_resolution_clock::now()),但它的行为也相同(同样,我的意思是它也提供了比 更大的经过时间矮个子)

提前感谢您的时间和帮助。

【问题讨论】:

    标签: c++ linux performance io execution-time


    【解决方案1】:

    快速点:Linux 上的gettimeofday() 使用的时钟不一定以恒定间隔滴答作响,甚至可以向后移动(参见http://man7.org/linux/man-pages/man2/gettimeofday.2.htmlhttps://stackoverflow.com/a/3527632/4513656) - 这可能会使telapsed 不可靠(或甚至是负面的)。

    1. 您的 gettimeofday/popen/gettimeofday 测量值 (telapsed) 将是:fio 进程启动(即 Linux 上的 fork+exec)已过 + fio 初始化(例如线程创建,因为我看到了--thread,ioengine 初始化) + fio 作业已过 (runt) + fio 已停止 + 进程已停止)。您将其与runt 进行比较,后者是telapsed 的子组件。不太可能所有非runt 组件都会立即发生(即占用 0 微秒),因此预计runt 将小于telapsed。尝试使用 --debug=all 运行 fio,以查看它除了实际为作业提交 I/O 之外所做的所有事情。
    2. 这很难回答,因为这取决于您说“fio 执行”时想要表达的意思以及原因(即,这个问题很难以明确的方式解释)。您是否对 fio 尝试为给定作业提交 I/O 实际花费了多长时间 (runt) 感兴趣?您是否对系统启动/停止一个新进程需要多长时间感兴趣,而这个新进程恰好尝试在给定时间段内提交 I/O (telapsed)?您是否对提交 I/O 花费了多少 CPU 时间感兴趣(以上都不是)?所以因为我很困惑,所以我会问你一些问题:你打算将结果用于什么以及为什么?
    3. 为什么不看源代码呢? https://github.com/axboe/fio/blob/7a3b2fc3434985fa519db55e8f81734c24af274d/stat.c#L405 显示 runt 来自 ts->runtime[ddir]。您可以看到它是通过调用 set_epoch_time() (https://github.com/axboe/fio/blob/6be06c46544c19e513ff80e7b841b1de688ffc66/backend.c#L1664) 来初始化的,并由从 thread_main() 调用的 update_runtime() ( https://github.com/axboe/fio/blob/6be06c46544c19e513ff80e7b841b1de688ffc66/backend.c#L371 ) 更新。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-18
      • 1970-01-01
      • 2017-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-19
      相关资源
      最近更新 更多