如何在Linux中测量命令的IOPS? [英] How to measure IOPS for a command in linux?

查看:1222
本文介绍了如何在Linux中测量命令的IOPS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个仿真模型,我想确定何时存储IOPS容量成为瓶颈(例如,HDD具有约150 IOPS,而SSD可以具有150,000).因此,我正在尝试提出一种在命令(git)中对IOPS进行基准测试的方法,以实现其中某些不同的操作(推,拉,合并,克隆).

I'm working on a simulation model, where I want to determine when the storage IOPS capacity becomes a bottleneck (e.g. and HDD has ~150 IOPS, while an SSD can have 150,000). So I'm trying to come up with a way to benchmark IOPS in a command (git) for some of it's different operations (push, pull, merge, clone).

到目前为止,我已经找到了iostat之类的工具,但是,我不确定如何将报告限制为单个命令的作用.

So far, I have found tools like iostat, however, I am not sure how to limit the report to what a single command does.

我能想到的最好的主意是确定我的HDD IOPS容量,在实际命令上使用时间,看看它能持续多久,再乘以IOPS,这就是我的IOPS:

The best idea I can come up with is to determine my HDD IOPS capacity, use time on the actual command, see how long it lasts, multiply that by IOPS and those are my IOPS:

HDD ->150 IOPS
time df -h

real    0m0.032s

150 * .032 = 4.8 IOPS

但是,这当然是非常愚蠢的,因为执行的持续时间可能与CPU使用率而不是HDD使用率有关,因此除非这段时间内HDD的使用率是100%,否则测量类似那个.

But, this is of course very stupid, because the duration of the execution may have been related to CPU usage rather than HDD usage, so unless usage of HDD was 100% for that time, it makes no sense to measure things like that.

那么,如何测量命令的IOPS?

So, how can I measure the IOPS for a command?

推荐答案

在典型的Linux系统上,有多个time(1)命令;默认是内置的bash(1),它有些基本.还有一个/usr/bin/time,您可以通过完全像这样调用它来运行,或者通过在其前面加上反斜杠来告诉bash(1)不要使用别名和内置函数:\time. Debian在默认安装的时间"软件包中提供了该软件包,Ubuntu可能完全相同,其他发行版也非常相似.

There are multiple time(1) commands on a typical Linux system; the default is a bash(1) builtin which is somewhat basic. There is also /usr/bin/time which you can run by either calling it exactly like that, or telling bash(1) to not use aliases and builtins by prefixing it with a backslash thus: \time. Debian has it in the "time" package which is installed by default, Ubuntu is likely identical, and other distributions will be quite similar.

以与内置shell相似的方式调用它已经更加冗长和翔实,尽管它可能更加不透明,除非您已经熟悉数字的真正含义:

Invoking it in a similar fashion to the shell builtin is already more verbose and informative, albeit perhaps more opaque unless you're already familiar with what the numbers really mean:

$ \time df
[output elided]
0.00user 0.00system 0:00.01elapsed 66%CPU (0avgtext+0avgdata 864maxresident)k
0inputs+0outputs (0major+261minor)pagefaults 0swaps

但是,我想提醒您注意手册页,其中列出了-f选项以自定义输出格式,尤其是%w格式,该格式计算进程放弃其CPU的次数I/O的时间片:

However, I'd like to draw your attention to the man page which lists the -f option to customise the output format, and in particular the %w format which counts the number of times the process gave up its CPU timeslice for I/O:

$ \time -f 'ios=%w' du Maildir >/dev/null
ios=184
$ \time -f 'ios=%w' du Maildir >/dev/null
ios=1

请注意,第一次运行停止了I/O 184次,但是第二次运行仅停止了一次.第一个数字是可信的,因为在我的~/Maildir中有124个目录:目录和inode的读取大约为每个目录提供IOPS,少了一点,因为某些inode可能彼此相邻并可以在一个操作中读取,再加上一些额外的内容以映射到du(1)二进制文件,共享库等中.

Note that the first run stopped for I/O 184 times, but the second run stopped just once. The first figure is credible, as there are 124 directories in my ~/Maildir: the reading of the directory and the inode gives roughly two IOPS per directory, less a bit because some inodes were likely next to each other and read in one operation, plus some extra again for mapping in the du(1) binary, shared libraries, and so on.

由于Linux的磁盘缓存,第二个数字当然要低一些.因此,最后一步是刷新缓存. sync(1)是一个熟悉的命令,它会将脏的写刷新到磁盘,但不会刷新读缓存.您可以通过将3写入/proc/sys/vm/drop_caches来刷新该代码. (其他值有时也有用,但在这里您需要3.)作为非root用户,执行此操作的最简单方法是:

The second figure is of course lower due to Linux's disk cache. So the final piece is to flush the cache. sync(1) is a familiar command which flushes dirty writes to disk, but doesn't flush the read cache. You can flush that one by writing 3 to /proc/sys/vm/drop_caches. (Other values are also occasionally useful, but you want 3 here.) As a non-root user, the simplest way to do this is:

echo 3 | sudo tee /proc/sys/vm/drop_caches

将其与/usr/bin/time结合可以使您构建需要对基准命令进行基准测试的脚本.

Combining that with /usr/bin/time should allow you to build the scripts you need to benchmark the commands you're interested in.

除未成年人外,使用tee(1)是因为它不起作用:

As a minor aside, tee(1) is used because this won't work:

sudo echo 3 >/proc/sys/vm/drop_caches

原因?尽管echo(1)以root身份运行,但重定向是使用您的普通用户帐户进行的,该帐户没有对drop_caches的写入权限. tee(1)以root身份有效地进行重定向.

The reason? Although the echo(1) runs as root, the redirection is as your normal user account, which doesn't have write permissions to drop_caches. tee(1) effectively does the redirection as root.

这篇关于如何在Linux中测量命令的IOPS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆