平均硬盘参考频率

平均硬盘参考频率

如何查找 Ubuntu 频繁引用硬盘驱动器(用于读/写目的)的频率以及如何调整它?

答案1

进行这些观察的命令是iostat
,包含在软件包中sysstat。使用以下命令安装它(对于没有它的系统):

sudo apt-get -y install sysstat

可以如此使用:

$ iostat

Linux 4.4.0-64-generic (george-HP-Pavilion-17-Notebook-PC)  04/03/2017  _x86_64_    (4 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           4.56    0.02    2.17    1.67    0.00   91.59

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
loop0             0.00         0.02         0.00       1093          0
loop1             0.04         0.04         0.00       1799          0
loop2             0.18         0.20         0.00       9607          0
loop3             0.00         0.02         0.00       1079          0
loop4             0.00         0.00         0.00        108          0
sda               7.70        87.28       178.21    4194476    8564449
scd1              0.00         0.00         0.00        166          0

捕捉于megabytes

$ iostat -m

Linux 4.4.0-64-generic (george-HP-Pavilion-17-Notebook-PC)  04/03/2017  _x86_64_    (4 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           4.56    0.02    2.17    1.67    0.00   91.59

Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn
loop0             0.00         0.00         0.00          1          0
loop1             0.04         0.00         0.00          1          0
loop2             0.18         0.00         0.00          9          0
loop3             0.00         0.00         0.00          1          0
loop4             0.00         0.00         0.00          0          0
sda               7.69         0.09         0.17       4096       8370
scd1              0.00         0.00         0.00          0          0

扩展报告-x parameter

$ iostat -x


Linux 4.4.0-64-generic (george-HP-Pavilion-17-Notebook-PC)  04/03/2017  _x86_64_    (4 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           4.56    0.02    2.17    1.67    0.00   91.59

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
loop0             0.00     0.00    0.00    0.00     0.02     0.00    28.76     0.00   53.89   53.89    0.00  28.74   0.00
loop1             0.00     0.00    0.04    0.00     0.04     0.00     2.09     0.00   76.24   76.24    0.00   3.18   0.01
loop2             0.00     0.00    0.18    0.00     0.20     0.00     2.23     0.00   20.97   20.97    0.00   1.22   0.02
loop3             0.00     0.00    0.00    0.00     0.02     0.00    25.69     0.00   47.00   47.00    0.00  32.43   0.01
loop4             0.00     0.00    0.00    0.00     0.00     0.00     6.55     0.00   42.30   42.30    0.00  28.97   0.00
sda               0.36     7.68    3.05    4.64    87.12   178.06    68.95     0.29   37.84   35.88   39.14   4.88   3.75
scd1              0.00     0.00    0.00    0.00     0.00     0.00     9.49     0.00   11.20   11.20    0.00  10.17   0.00

添加延迟以输出结果。这将以 2 秒的间隔生成 3 份报告:

$ iostat -k 2 3


Linux 4.4.0-64-generic (george-HP-Pavilion-17-Notebook-PC)  04/03/2017  _x86_64_    (4 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           4.56    0.02    2.17    1.67    0.00   91.59

Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn
loop0             0.00         0.00         0.00          1          0
loop1             0.04         0.00         0.00          1          0
loop2             0.18         0.00         0.00          9          0
loop3             0.00         0.00         0.00          1          0
loop4             0.00         0.00         0.00          0          0
sda               7.69         0.09         0.17       4096       8375
scd1              0.00         0.00         0.00          0          0

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           4.03    0.00    1.64    0.63    0.00   93.70

Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn
loop0             0.00         0.00         0.00          0          0
loop1             0.00         0.00         0.00          0          0
loop2             0.00         0.00         0.00          0          0
loop3             0.00         0.00         0.00          0          0
loop4             0.00         0.00         0.00          0          0
sda               1.50         0.00         0.01          0          0
scd1              0.00         0.00         0.00          0          0

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           3.16    0.00    2.28    0.51    0.00   94.06

Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn
loop0             0.00         0.00         0.00          0          0
loop1             0.00         0.00         0.00          0          0
loop2             0.00         0.00         0.00          0          0
loop3             0.00         0.00         0.00          0          0
loop4             0.00         0.00         0.00          0          0
sda               0.50         0.00         0.00          0          0
scd1              0.00         0.00         0.00          0          0

现在以 2 秒的间隔连续查看它:

$ iostat 2

以下是如何阅读 iostat 报告

The first section contains CPU report

%user : show the percentage of CPU utilization that occured while executing at the user (application) level
%nice : show the percentage of CPU utilization that occured while executing at the user level with nice priority
%system : show the percentage of CPU utilization that occured while executing at the system (kernel) level
%iowait : show the percentage of the time that the CPU or CPUs were idle during whcih the system had an outstanding disk I/O request
%steal : show the percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor
%idle : show the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request

第二部分包含设备利用率报告

Device : device / partition name as listed in /dev directory
tps : show the number of transfers per second that were issued to the device. Higher tps means the processor is busier
Blk_read/s : show the amount of data read from the device expressed in a number of blocks (kilobytes, megabytes) per second
Blk_wrtn/s : show the amount of data written to the device expressed in a number of blocks (kilobytes, megabytes) per second
Blk_read : show the total number of blocks read
Blk_wrtn : show the total number of blocks written

对于问题的第二部分:

I/O 调度程序用于改变或优化I/OLinux 上的操作,其各种类型包括:

  • CFQ [cfq](完全公平队列)是 Linux 内核的 I/O 调度程序,是许多 Linux 发行版的默认调度程序。

  • Noop 调度程序(noop)是 Linux 内核基于 FIFO 队列概念的最简单的 I/O 调度程序。

  • 预期调度器(anticipatory)是一种用于调度硬盘输入/输出的算法,也是被CFQ取代的旧调度器

  • 截止期限调度程序(deadline)——它尝试保证请求的开始服务时间。

要查看当前的磁盘调度程序:

sudo cat /sys/block/{DEVICE-NAME}/queue/scheduler

# where device name is [sda | sdb | ...]
# The one with the "[  ]" around it the one in use.

其中每一个都有其不同的优点缺点。要更改为其中任何一个,可以使用以下两种方法:

  1. 在运行时:

    # echo scheduler_type_name > /sys/block/sda/queue/scheduler
    # echo noop > /sys/block/sda/queue/scheduler
    
  2. 对于以下情况的持久性reboot

    a. 编辑vi /etc/default/grub,然后

    b.添加此行:GRUB_CMDLINE_LINUX="elevator=noop"

    c. 重启

    d. 查看这里对于使用差异表现postgresql

来源:

https://blog.codeship.com/linux-io-scheduler-tuning/

https://www.cyberciti.biz/faq/linux-change-io-scheduler-for-harddisk/

https://unix.stackexchange.com/questions/48138/how-to-throttle-per-process-io-to-a-max-limit

http://linoxide.com/linux-command/linux-iostat-command/

相关内容