【存储】如何计算IOPS ?

简介:
我们知道评估io性能的三个关键指标为:
 1 IOPS
   每秒钟处理的IO请求数量。IOPS是随机访问类型业务(OLTP类)很重要的一个参考指标。
 2 IO Response Time
   IO的响应时间。IO响应时间是从操作系统内核发出一个IO请求到接收到IO响应的时间。因此,IO Response time除了包括磁盘获取数据的时间,还包括了操作系统以及在存储系统内部IO等待的时间。
 3 Throughput
  吞吐量。这个指标衡量标识了最大的数据传输量。如上说明,这个值在顺序访问或者大数据量访问的情况下会比较重要。尤其在大数据量写的时候。
   如何计算IOPS ? 本文通过利用/proc/disksats 的内容来计算磁盘iops,如果是多个磁盘,需要多个变量来标记每个磁盘的累计值和前一秒的值,做减法操作。
首先介绍一下/proc/diskstats 的意义
root@rac1 markbench]# cat /proc/diskstats
   1    0 ram0 0 0 0 0 0 0 0 0 0 0 0
   1    1 ram1 0 0 0 0 0 0 0 0 0 0 0
   3    0 hda 215832 48798 8460369 1779489 10387352 10706454 278983110 129355207 12 30046343 131143587
   3    1 hda1 328 1805 2367 1482 24 11 61 1518 0 1499 3000
   3    2 hda2 214383 41704 8442154 1766493 10387210 10706256 278981160 129335402 12 30040228 131110596
   3    3 hda3 174 1250 1455 920 0 0 0 0 0 110 920
   3    4 hda4 4 0 8 9 0 0 0 0 0 9 9
   3    5 hda5 925 4006 13977 10447 118 187 1889 18287 0 7409 28734
  202   32 xvdc 38 76 912 14 0 0 0 0 0 14 14
  202   16 xvdb 40 76 928 17 0 0 0 0 0 17 17
  22    0 hdc 18 86 416 39 0 0 0 0 0 35 39
   9    0  md0 0 0 0 0 0 0 0 0 0 0 0

这个命令用于显示磁盘、分区和统计信息:hda为整个硬盘的统计信息,hda1为第一个分区的统计信息,hda2为第二个分区的统计信息。
ramdisk设备为通过软件将RAM当做硬盘来使用的一项技术。

[root@rac1 markbench]#  cat /sys/block/hda/hda2/stat
  214428    41704  8443522  1767344 10431899 10785067 282040104 130435808        9 30120018 132201965

/proc/diskstats文件比/sys/block/hda/hda2/stat文件多3列,从左至右分别对应主设备号,次设备号和设备名称。后续的11列的意义在这两个文件里是相同的,除了第9列,所有的域都是从启动时的累积值。 

第1 列 读完成次数,成功完成读的总次数。
(number of issued reads. This is the total number of reads completed successfully.)

第2 列 合并读完成次数, 第6 列合并写完成次数。为了效率可能会合并相邻的读和写。从而两次4K的读在它最终被处理到磁盘上之前可能会变成一次8K的读,才被计数(和排队),因此只有一次I/O操作。该值使你知道这样的操作有多频繁。
(number of reads merged)

第3 列 读扇区的次数,成功读过的扇区总次数。
(number of sectors read. This is the total number of sectors read successfully.)

第4 列 读花费的毫秒数,这是所有读操作所花费的毫秒数(用__make_request()到end_that_request_last()测量)。
(number of milliseconds spent reading. This is the total number of milliseconds spent by all reads (as measured from __make_request() to end_that_request_last()).)

第5 列 写完成次数,成功写完成的总次数。
(number of writes completed. This is the total number of writes completed successfully.)

第6 列 合并写完成次数  
(number of writes merged Reads and writes which are adjacent to each other may be merged for efficiency. Thus two 4K reads may become one 8K read before it is ultimately handed to the disk, and so it will be counted (and queued) as only one I/O. This field lets you know how often this was done.)

第7 列 写扇区次数,成功写扇区总次数。
(number of sectors written. This is the total number of sectors written successfully.)

第8 列 写操作花费的毫秒数,这是所有写操作所花费的毫秒数(用__make_request()到end_that_request_last()测量)。
(number of milliseconds spent writing This is the total number of milliseconds spent by all writes (as measured from __make_request() to end_that_request_last()).)

第9 列 正在处理的输入/输出请求数-I/O的当前进度,只有这个域应该是0。当请求被交给适当的request_queue_t时增加和请求完成时减小。
(number of I/Os currently in progress. The only field that should go to zero. Incremented as requests are given to appropriate request_queue_t and decremented as they finish.)

第10 列 输入/输出操作花费的毫秒数,花在I/O操作上的毫秒数,这个域会增长只要field 9不为0。
(number of milliseconds spent doing I/Os. This field is increased so long as field 9 is nonzero.)

第11 列 输入/输出操作花费的加权毫秒数  花在I/O操作上的毫秒数,在每次I/O开始,I/O结束,I/O合并时这个域都会增加。这可以给I/O完成时间和存储那些可以累积的提供一个便利的测量标准。
(number of milliseconds spent doing I/Os. This field is incremented at each I/O start, I/O completion, I/O merge, or read of these stats by the number of I/Os in progress (field 9) times the number of milliseconds spent doing I/O since the last update of this field. This can provide an easy measure of both I/O completion time and the backlog that may be accumulating.)


统计的iops 的脚本如下:
#!/bin/bash
uplrio=0
uplwio=0
updrio=0
updwio=0

while true ; do
        lrio=$(grep hda2 /proc/diskstats | awk '{print $4}')
        lwio=$(grep hda2 /proc/diskstats | awk '{print $8}')
        llrio=$(echo $lrio - $uplrio | bc)
        llwio=$(echo $lwio - $uplwio | bc)
        iops=$(echo "$llrio + $llwio " | bc)
        echo "iops:$iops Data_Read $llrio Data_Write $llwio "
        uplrio=$lrio
        uplwio=$lwio
        sleep 1
done

效果展示:
[root@rac1 markbench]# sh iops.sh 
iops:10348521 Data_Read 214045 Data_Write 10134476  --第一个因为是累计值-0的结果,所以比较大,可以忽略。
iops:322 Data_Read 0 Data_Write 322 
iops:596 Data_Read 0 Data_Write 596 
iops:589 Data_Read 0 Data_Write 589 
iops:615 Data_Read 0 Data_Write 615 
iops:599 Data_Read 0 Data_Write 599 
iops:455 Data_Read 0 Data_Write 455 
iops:533 Data_Read 0 Data_Write 533 
iops:516 Data_Read 0 Data_Write 516 
iops:214 Data_Read 0 Data_Write 214 
iops:544 Data_Read 0 Data_Write 544 
相关文章
|
机器学习/深度学习 弹性计算 云计算
阿里云ECS实例规格
阿里云ECS实例规格
|
网络协议 算法 网络性能优化
TCP滑动窗口、流量控制及拥塞控制详解
TCP滑动窗口、流量控制及拥塞控制详解
|
Kubernetes 应用服务中间件 nginx
Kubernetes上安装Metallb和Ingress并部署应用程序
Kubernetes上安装Metallb和Ingress并部署nginx应用程序,使用LoadBalancer类型的KubernetesService
895 114
|
存储 缓存 监控
磁盘I/O
【10月更文挑战第4天】磁盘I/O
716 2
|
数据处理
基于ARM的嵌入式原理与应用:ALU的功能与特点
基于ARM的嵌入式原理与应用:ALU的功能与特点
1854 0
|
存储 弹性计算 固态存储
三分钟磁盘存储性能IOPS、I/O及吞吐量指标详解
磁盘存储性能指标IOPS是什么?磁盘I/O和吞吐量是指什么?详细说下磁盘存储性能指标I/O、吞吐量和IOPS之间的关系及意义,以阿里云服务器为例,来详细说下高IO磁盘性能使用场景及ECS云服务器实例规格选择:
|
弹性计算 监控 负载均衡
【阿里云弹性计算】ECS实例迁移实战:无缝迁移到阿里云的步骤与技巧
【5月更文挑战第22天】阿里云ECS实例迁移实战详解,涵盖无缝迁移步骤与技巧:选择合适迁移方案,如VPC或使用阿里云工具;创建目标环境,数据迁移及配置同步;测试验证功能正常,流量切换;选择低峰期,保证数据一致,实时监控,提升迁移成功率。本文为云平台迁移提供实用指南。
629 2
|
存储 缓存 监控
Elasticsearch elastic io 100%,但磁盘的iops和吞吐量没爆没啥原因吗?
Elasticsearch elastic io 100%,但磁盘的iops和吞吐量没爆没啥原因吗?
575 2

热门文章

最新文章