I would like to know how can you measure disk speed using Java API.
Random read,sequential read and Random and sequential write.
If someone thinks it's not a real question. Please explain so before closing it.
Thanks
I would like to know how can you measure disk speed using Java API.
Random read,sequential read and Random and sequential write.
If someone thinks it's not a real question. Please explain so before closing it.
Thanks
Have you thought about using Caliper?
From the site:
I would create a big file in the disk to assure you reserve always the same space and then proceed with the tests, i.e. reading/writing chunks of the file with RFA, varying the size of those chunks. I would also vary the position of the chunks (randomly or going back an forth the init and end of the file). All this will let you measure the average transfer rate for certain situations depending on the size of the chunk, etc.
Take into consideration however, no matter if you use java or simple C, that you do not have access to low level file organization. You could be using a HD that is fragmented (the emptier the this the more unlikely it is very fragmented). That information is only available at kernel level (not user-land level). However if you carry out a lot of tests (not one read of one part of the file, but many along all the file space) and the disk is considerably empty (to assure that the block on the disk does not have a lot of fragmentation), you could statistically get quite reasonable indicator of the read/write speed.
Another important issue I had forgotten that will impact your measurements is cache. The fist time you read a chunk from a file you are likely not to be using cache, but not the second time. For that I recommend you to read the approaches of this other question.
You can take a look at a disk utility I wrote in java. It may not be super fancy but it works.
https://sourceforge.net/projects/jdiskmark/
Here is a snippet of the write measurement code:
The code is on gitlab: https://gitlab.com/jamesmarkchan/jDiskMark/