linux iostat 进程,为什么linux命令(iostat)中的每秒读取数(r / s)始终为零?

我运行一个

java代码,它会从文本文件中生成大量的读写内容.程序源非常简单,在循环中我在测试文件中写入2000行,然后我再次读取它们只是为了生成大量的磁盘读写.但是当程序运行时,我通过“iostat -d -x 1”监视磁盘我发现第二个“r / s”中的读取没有变化但是“w / s”增加了我的预期!

这是iostat命令的示例输出:

Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util

sda 0.00 913.00 0.00 82.00 0.00 7872.00 96.00 0.58 7.09 7.11 58.30

Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util

sda 0.00 869.00 0.00 79.00 0.00 7584.00 96.00 0.57 7.11 7.18 56.70

Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util

sda 0.00 847.00 0.00 77.00 0.00 7392.00 96.00 0.57 7.42 7.43 57.20

Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util

sda 0.00 1221.00 0.00 113.00 0.00 10760.00 95.22 0.84 7.47 7.32 82.70

如图所示,所有“r / s”都为零!但在Java程序中,我读到的文件和我在文件中写的一样多吗?!当我运行Java代码时,每秒写入次数增加,但“r / s”没有变化!!

这是我在监视磁盘时运行的java代码:

import java.io.*;

public class Test {

public static void main(String [] args) throws IOException{

String fileName = "/scratch/dump_file.txt";

File f = new File(fileName);

// Attempt to delete it

boolean success = f.delete();

int j=0;

while(j<20000)

{

++j;

Writer output = null;

String text = "A test content";

File file = new File(fileName);

output = new BufferedWriter(new FileWriter(file));

int i=1;

while(i<2000)

{

//Here we start writing 2000 lines into file line by line

output.write("j==="+Integer.toString(j)+text+Integer.toString(i)+"\n");

++i;

}

output.close();

System.out.println("Your file has been written");

String line = null;

try {

// FileReader reads text files in the default encoding.

FileReader fileReader = new FileReader(fileName);

BufferedReader bufferedReader =

new BufferedReader(fileReader);

i=1;

while((line = bufferedReader.readLine()) != null) {

//Here we start reading from file line by line and show the result on screen

++i;

System.out.println(line);

}

// Always close file

bufferedReader.close();

}

catch(FileNotFoundException ex) {

System.out.println(

"Unable to open file '" +

fileName + "'");

}

catch(IOException ex) {

System.out.println(

"Error reading file '"

+ fileName + "'");

// Or we could just do this:

// ex.printStackTrace();

}

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值