Skip to content

Commit

Permalink
Fix bug in random read benchmark when switching between buffered and …
Browse files Browse the repository at this point in the history
…direct streams
  • Loading branch information
Patrick Stuedi committed Sep 13, 2017
1 parent 34724d9 commit efe869b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class CrailConstants {
private static final Logger LOG = CrailUtils.getLogger();

public static final String VERSION_KEY = "crail.version";
public static int VERSION = 2991;
public static int VERSION = 2992;

public static final String DIRECTORY_DEPTH_KEY = "crail.directorydepth";
public static int DIRECTORY_DEPTH = 16;
Expand Down
16 changes: 9 additions & 7 deletions client/src/main/java/com/ibm/crail/tools/CrailBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ void readRandom(String filename, int size, int loop, boolean buffered) throws Ex
double sumbytes = 0;
double ops = 0;
long _range = file.getCapacity() - ((long)buf.capacity());
_range = _range / size;
double range = (double) _range;
Random random = new Random();

Expand All @@ -346,27 +347,28 @@ void readRandom(String filename, int size, int loop, boolean buffered) throws Ex
if (buffered){
buf.clear();
double _offset = range*random.nextDouble();
long offset = (long) _offset;
directStream.seek(offset);
double ret = (double) directStream.read(buf).get().getLen();
long offset = (long) _offset*size;
bufferedStream.seek(offset);
double ret = (double) bufferedStream.read(buf.getByteBuffer());
if (ret > 0) {
sumbytes = sumbytes + ret;
ops = ops + 1.0;
} else {
break;
}

} else {
buf.clear();
double _offset = range*random.nextDouble();
long offset = (long) _offset;
bufferedStream.seek(offset);
double ret = (double) bufferedStream.read(buf.getByteBuffer());
long offset = (long) _offset*size;
directStream.seek(offset);
double ret = (double) directStream.read(buf).get().getLen();
if (ret > 0) {
sumbytes = sumbytes + ret;
ops = ops + 1.0;
} else {
break;
}
}
}
}
long end = System.currentTimeMillis();
Expand Down

0 comments on commit efe869b

Please sign in to comment.