use of org.apache.crail.CrailBuffer in project incubator-crail by apache.
the class CrailBenchmark method getFileAsync.
void getFileAsync(String filename, int loop, int batch) throws Exception, InterruptedException {
System.out.println("getFileAsync, filename " + filename + ", loop " + loop + ", batch " + batch);
// warmup
ConcurrentLinkedQueue<CrailBuffer> bufferQueue = new ConcurrentLinkedQueue<CrailBuffer>();
CrailBuffer buf = fs.allocateBuffer();
bufferQueue.add(buf);
warmUp(filename, warmup, bufferQueue);
fs.freeBuffer(buf);
// benchmark
System.out.println("starting benchmark...");
fs.getStatistics().reset();
LinkedBlockingQueue<Future<CrailNode>> fileQueue = new LinkedBlockingQueue<Future<CrailNode>>();
long start = System.currentTimeMillis();
for (int i = 0; i < loop; i++) {
// single operation == loop
for (int j = 0; j < batch; j++) {
Future<CrailNode> future = fs.lookup(filename);
fileQueue.add(future);
}
for (int j = 0; j < batch; j++) {
Future<CrailNode> future = fileQueue.poll();
future.get();
}
}
long end = System.currentTimeMillis();
double executionTime = ((double) (end - start));
double latency = executionTime * 1000.0 / ((double) batch);
System.out.println("execution time [ms] " + executionTime);
System.out.println("latency [us] " + latency);
fs.getStatistics().print("close");
}
use of org.apache.crail.CrailBuffer in project incubator-crail by apache.
the class CrailBenchmark method readRandom.
void readRandom(String filename, int size, int loop, boolean buffered) throws Exception {
System.out.println("readRandom, filename " + filename + ", size " + size + ", loop " + loop + ", buffered " + buffered);
CrailBuffer buf = null;
if (size == CrailConstants.BUFFER_SIZE) {
buf = fs.allocateBuffer();
} else if (size < CrailConstants.BUFFER_SIZE) {
CrailBuffer _buf = fs.allocateBuffer();
_buf.clear().limit(size);
buf = _buf.slice();
} else {
buf = OffHeapBuffer.wrap(ByteBuffer.allocateDirect(size));
}
// warmup
ConcurrentLinkedQueue<CrailBuffer> bufferQueue = new ConcurrentLinkedQueue<CrailBuffer>();
bufferQueue.add(buf);
warmUp(filename, warmup, bufferQueue);
// benchmark
System.out.println("starting benchmark...");
fs.getStatistics().reset();
CrailFile file = fs.lookup(filename).get().asFile();
CrailBufferedInputStream bufferedStream = file.getBufferedInputStream(file.getCapacity());
CrailInputStream directStream = file.getDirectInputStream(file.getCapacity());
double sumbytes = 0;
double ops = 0;
long _range = file.getCapacity() - ((long) buf.capacity());
_range = _range / size;
double range = (double) _range;
Random random = new Random();
long start = System.currentTimeMillis();
while (ops < loop) {
if (buffered) {
buf.clear();
double _offset = range * random.nextDouble();
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 * 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();
double executionTime = ((double) (end - start)) / 1000.0;
double throughput = 0.0;
double latency = 0.0;
double sumbits = sumbytes * 8.0;
if (executionTime > 0) {
throughput = sumbits / executionTime / 1000.0 / 1000.0;
latency = 1000000.0 * executionTime / ops;
}
bufferedStream.close();
directStream.close();
System.out.println("execution time " + executionTime);
System.out.println("ops " + ops);
System.out.println("sumbytes " + sumbytes);
System.out.println("throughput " + throughput);
System.out.println("latency " + latency);
fs.getStatistics().print("close");
}
use of org.apache.crail.CrailBuffer in project incubator-crail by apache.
the class CrailBenchmark method writeAsync.
void writeAsync(String filename, int size, int loop, int batch, int storageClass, int locationClass, boolean skipDir) throws Exception {
System.out.println("writeAsync, filename " + filename + ", size " + size + ", loop " + loop + ", batch " + batch + ", storageClass " + storageClass + ", locationClass " + locationClass);
ConcurrentLinkedQueue<CrailBuffer> bufferQueue = new ConcurrentLinkedQueue<CrailBuffer>();
for (int i = 0; i < batch; i++) {
CrailBuffer buf = null;
if (size == CrailConstants.BUFFER_SIZE) {
buf = fs.allocateBuffer();
} else if (size < CrailConstants.BUFFER_SIZE) {
CrailBuffer _buf = fs.allocateBuffer();
_buf.clear().limit(size);
buf = _buf.slice();
} else {
buf = OffHeapBuffer.wrap(ByteBuffer.allocateDirect(size));
}
bufferQueue.add(buf);
}
// warmup
warmUp(filename, warmup, bufferQueue);
// benchmark
System.out.println("starting benchmark...");
LinkedBlockingQueue<Future<CrailResult>> futureQueue = new LinkedBlockingQueue<Future<CrailResult>>();
HashMap<Integer, CrailBuffer> futureMap = new HashMap<Integer, CrailBuffer>();
fs.getStatistics().reset();
long _loop = (long) loop;
long _bufsize = (long) CrailConstants.BUFFER_SIZE;
long _capacity = _loop * _bufsize;
double sumbytes = 0;
double ops = 0;
CrailFile file = fs.create(filename, CrailNodeType.DATAFILE, CrailStorageClass.get(storageClass), CrailLocationClass.get(locationClass), !skipDir).get().asFile();
CrailOutputStream directStream = file.getDirectOutputStream(_capacity);
long start = System.currentTimeMillis();
for (int i = 0; i < batch - 1 && ops < loop; i++) {
CrailBuffer buf = bufferQueue.poll();
buf.clear();
Future<CrailResult> future = directStream.write(buf);
futureQueue.add(future);
futureMap.put(future.hashCode(), buf);
ops = ops + 1.0;
}
while (ops < loop) {
CrailBuffer buf = bufferQueue.poll();
buf.clear();
Future<CrailResult> future = directStream.write(buf);
futureQueue.add(future);
futureMap.put(future.hashCode(), buf);
future = futureQueue.poll();
future.get();
buf = futureMap.get(future.hashCode());
bufferQueue.add(buf);
sumbytes = sumbytes + buf.capacity();
ops = ops + 1.0;
}
while (!futureQueue.isEmpty()) {
Future<CrailResult> future = futureQueue.poll();
future.get();
CrailBuffer buf = futureMap.get(future.hashCode());
sumbytes = sumbytes + buf.capacity();
ops = ops + 1.0;
}
long end = System.currentTimeMillis();
double executionTime = ((double) (end - start)) / 1000.0;
double throughput = 0.0;
double latency = 0.0;
double sumbits = sumbytes * 8.0;
if (executionTime > 0) {
throughput = sumbits / executionTime / 1000.0 / 1000.0;
latency = 1000000.0 * executionTime / ops;
}
directStream.close();
System.out.println("execution time " + executionTime);
System.out.println("ops " + ops);
System.out.println("sumbytes " + sumbytes);
System.out.println("throughput " + throughput);
System.out.println("latency " + latency);
fs.getStatistics().print("close");
}
use of org.apache.crail.CrailBuffer in project incubator-crail by apache.
the class CrailBenchmark method write.
void write(String filename, int size, int loop, int storageClass, int locationClass, boolean buffered, boolean skipDir) throws Exception {
System.out.println("write, filename " + filename + ", size " + size + ", loop " + loop + ", storageClass " + storageClass + ", locationClass " + locationClass + ", buffered " + buffered);
CrailBuffer buf = null;
if (size == CrailConstants.BUFFER_SIZE) {
buf = fs.allocateBuffer();
} else if (size < CrailConstants.BUFFER_SIZE) {
CrailBuffer _buf = fs.allocateBuffer();
_buf.clear().limit(size);
buf = _buf.slice();
} else {
buf = OffHeapBuffer.wrap(ByteBuffer.allocateDirect(size));
}
// warmup
ConcurrentLinkedQueue<CrailBuffer> bufferQueue = new ConcurrentLinkedQueue<CrailBuffer>();
bufferQueue.add(buf);
warmUp(filename, warmup, bufferQueue);
// benchmark
System.out.println("starting benchmark...");
fs.getStatistics().reset();
long _loop = (long) loop;
long _bufsize = (long) CrailConstants.BUFFER_SIZE;
long _capacity = _loop * _bufsize;
double sumbytes = 0;
double ops = 0;
CrailFile file = fs.create(filename, CrailNodeType.DATAFILE, CrailStorageClass.get(storageClass), CrailLocationClass.get(locationClass), !skipDir).get().asFile();
CrailBufferedOutputStream bufferedStream = buffered ? file.getBufferedOutputStream(_capacity) : null;
CrailOutputStream directStream = !buffered ? file.getDirectOutputStream(_capacity) : null;
long start = System.currentTimeMillis();
while (ops < loop) {
buf.clear();
if (buffered) {
bufferedStream.write(buf.getByteBuffer());
} else {
directStream.write(buf).get();
}
sumbytes = sumbytes + buf.capacity();
ops = ops + 1.0;
}
if (buffered) {
bufferedStream.close();
}
long end = System.currentTimeMillis();
double executionTime = ((double) (end - start)) / 1000.0;
double throughput = 0.0;
double latency = 0.0;
double sumbits = sumbytes * 8.0;
if (executionTime > 0) {
throughput = sumbits / executionTime / 1000.0 / 1000.0;
latency = 1000000.0 * executionTime / ops;
}
System.out.println("execution time " + executionTime);
System.out.println("ops " + ops);
System.out.println("sumbytes " + sumbytes);
System.out.println("throughput " + throughput);
System.out.println("latency " + latency);
fs.getStatistics().print("close");
}
use of org.apache.crail.CrailBuffer in project incubator-crail by apache.
the class CrailBenchmark method warmUp.
private void warmUp(String filename, int operations, ConcurrentLinkedQueue<CrailBuffer> bufferList) throws Exception {
Random random = new Random();
String warmupFilename = filename + random.nextInt();
System.out.println("warmUp, warmupFile " + warmupFilename + ", operations " + operations);
if (operations > 0) {
CrailFile warmupFile = fs.create(warmupFilename, CrailNodeType.DATAFILE, CrailStorageClass.DEFAULT, CrailLocationClass.DEFAULT, true).get().asFile();
CrailBufferedOutputStream warmupStream = warmupFile.getBufferedOutputStream(0);
for (int i = 0; i < operations; i++) {
CrailBuffer buf = bufferList.poll();
buf.clear();
warmupStream.write(buf.getByteBuffer());
bufferList.add(buf);
}
warmupStream.purge().get();
warmupStream.close();
fs.delete(warmupFilename, false).get().syncDir();
}
}
Aggregations