【发布时间】:2019-11-25 21:48:47
【问题描述】:
iostat -x -d
可以显示许多 i/o 统计信息。 对于iostat的util,解释为:
向设备发出 I/O 请求的 CPU 时间百分比(设备的带宽利用率)。当该值接近 100% 时会发生设备饱和
我想知道 util 是如何计算的?
我做了一个实验,(见下面的代码),启动40个线程随机读取40个文件。我想磁盘利用率应该很高,但我错了, iostat如下,任何人都可以给出为什么?谢了
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
sdb1 0.01 0.44 0.24 0.57 3.44 8.14 14.34 0.00 2.28 0.66 0.05
代码:
#include <iostream>
#include <fstream>
#include <pthread.h>
using namespace std;
void* work(void* a)
{
int* id = (int*)a;
string file = "sys.partition";
char buf[100];
sprintf(buf, "%d", *id);
file.append(string(buf));
ifstream in(file.c_str());
in.seekg(0, ios_base::end);
size_t len = in.tellg();
cout << "open file : " << file << " , " << len << endl;
srand(time(NULL));
while(true)
{
size_t pos = rand() % len;
in.seekg(pos);
//cout << pos << endl;
in.read(buf, 10);
system("sync");
}
in.close();
}
int main(int argc, char** argv)
{
static const int num = 40;
pthread_t threads[num];
for (int i = 0; i < num; i++) {
pthread_create(&threads[i], NULL, work, &i);
}
for (int i = 0; i < num; i++) {
pthread_join(threads[i], NULL);
}
return 0;
}
【问题讨论】:
-
格式完全改变,溢出应该改进编辑器。
-
溢出来救援!改进完成!
-
要么查看@zengr 对您的问题所做的更改,要么阅读格式帮助:stackoverflow.com/editing-help
标签: linux linux-kernel linux-device-driver