1

I wrote a program to test IO performance in java useing FileChannel. Write data and call force(false) immediately. My Linux server has 12 ssd hard drives, sda~sdl, and I test writing data to different hard drive, the performance varies widely, and I don't know why?

code:

public static void main(String[] args) throws IOException, InterruptedException {
    RandomAccessFile aFile = new RandomAccessFile(args[0], "rw");
    int count = Integer.parseInt(args[1]);
    int idx = count;
    FileChannel channel = aFile.getChannel();
    long time = 0;
    long bytes = 0;
    while (--idx > 0) {
        String newData = "New String to write to file..." + System.currentTimeMillis();
        String buff = "";
        for (int i = 0 ; i<100; i++) {
            buff += newData;
        }
        bytes += buff.length();
        ByteBuffer buf = ByteBuffer.allocate(buff.length());
        buf.clear();
        buf.put(buff.getBytes());
        buf.flip();
        while(buf.hasRemaining()) {
            channel.write(buf);
        }
        long st = System.nanoTime();
        channel.force(false);
        long et = System.nanoTime();
        System.out.println("force time : " + (et - st));
        time += (et -st);
    }
    System.out.println("wirte " + count + " record, " + bytes + " bytes, force avg time : " + time/count);
}

Result like this:
sda: wirte 1000000 record, 4299995700 bytes, force avg time : 273480 ns
sdb: wirte 100000 record, 429995700 bytes, force avg time : 5868387 ns

The average time vary significantly.

Here is some IO monitor data.
sda: iostat data image
sdb: iostat data image

7
  • Can you clarify what you see as the problem? There doesn't appear to be enough information to draw any conclusions. 0.005 seconds variation doesn't mean much for disk IO unless it is hightly reproducible. I assume the drives are all the same except sda also have the operating system on it? Commented Jul 10, 2016 at 9:35
  • Note: when you write to a file for a benchmark, you can't need to create dummy data (unless the data will be compressed) A file full of zero bytes is the same as one containing random data. Commented Jul 10, 2016 at 9:36
  • Are all these disks the same model of drive on the same controller with the same file system type? BTW even 72 MB/s doesn't sound very high for an SSD. I would be looking for 400 - 500 MB/s Commented Jul 10, 2016 at 9:40
  • I would start by writing blocks of well over 4 KB e.g. 256 KB or 2 MB. Commented Jul 10, 2016 at 9:40
  • All the hard drives are the same model,ext3 file system,I don't know why the sda's force latency is much lower. Commented Jul 11, 2016 at 2:04

1 Answer 1

1

You need to start by measure your SSD disks performance using some standard tool like fio.

Then you can test your utility again using numbers from fio output.

Looks like you are writing into the Linux write cache so that can explain your results :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.