Search in sources :

Example 1 with CrailInputStream

use of org.apache.crail.CrailInputStream 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");
}
Also used : CrailInputStream(org.apache.crail.CrailInputStream) Random(java.util.Random) CrailFile(org.apache.crail.CrailFile) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CrailBufferedInputStream(org.apache.crail.CrailBufferedInputStream) CrailBuffer(org.apache.crail.CrailBuffer)

Example 2 with CrailInputStream

use of org.apache.crail.CrailInputStream in project incubator-crail by apache.

the class CrailBenchmark method readSequential.

void readSequential(String filename, int size, int loop, boolean buffered) throws Exception {
    System.out.println("readSequential, 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);
    CrailFile file = fs.lookup(filename).get().asFile();
    CrailBufferedInputStream bufferedStream = file.getBufferedInputStream(file.getCapacity());
    CrailInputStream directStream = file.getDirectInputStream(file.getCapacity());
    // benchmark
    System.out.println("starting benchmark...");
    fs.getStatistics().reset();
    double sumbytes = 0;
    double ops = 0;
    long start = System.currentTimeMillis();
    while (ops < loop) {
        if (buffered) {
            buf.clear();
            double ret = (double) bufferedStream.read(buf.getByteBuffer());
            if (ret > 0) {
                sumbytes = sumbytes + ret;
                ops = ops + 1.0;
            } else {
                ops = ops + 1.0;
                if (bufferedStream.position() == 0) {
                    break;
                } else {
                    bufferedStream.seek(0);
                }
            }
        } else {
            buf.clear();
            double ret = (double) directStream.read(buf).get().getLen();
            if (ret > 0) {
                sumbytes = sumbytes + ret;
                ops = ops + 1.0;
            } else {
                ops = ops + 1.0;
                if (directStream.position() == 0) {
                    break;
                } else {
                    directStream.seek(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;
    }
    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");
}
Also used : CrailInputStream(org.apache.crail.CrailInputStream) CrailFile(org.apache.crail.CrailFile) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CrailBufferedInputStream(org.apache.crail.CrailBufferedInputStream) CrailBuffer(org.apache.crail.CrailBuffer)

Example 3 with CrailInputStream

use of org.apache.crail.CrailInputStream in project incubator-crail by apache.

the class CrailBenchmark method getKey.

void getKey(String filename, int size, int loop) throws Exception {
    System.out.println("getKey, path " + filename + ", size " + size + ", loop " + loop);
    CrailBuffer buf = fs.allocateBuffer().clear().limit(size).slice();
    CrailFile file = fs.create(filename, CrailNodeType.DATAFILE, CrailStorageClass.DEFAULT, CrailLocationClass.DEFAULT, true).get().asFile();
    file.syncDir();
    CrailOutputStream directOutputStream = file.getDirectOutputStream(0);
    directOutputStream.write(buf).get();
    directOutputStream.close();
    // benchmark
    System.out.println("starting benchmark...");
    fs.getStatistics().reset();
    long start = System.currentTimeMillis();
    for (int i = 0; i < loop; i++) {
        CrailInputStream directInputStream = fs.lookup(filename).get().asFile().getDirectInputStream(0);
        buf.clear();
        directInputStream.read(buf).get();
        directInputStream.close();
    }
    long end = System.currentTimeMillis();
    double executionTime = ((double) (end - start));
    double latency = executionTime * 1000.0 / ((double) loop);
    System.out.println("execution time [ms] " + executionTime);
    System.out.println("latency [us] " + latency);
    fs.getStatistics().print("close");
}
Also used : CrailInputStream(org.apache.crail.CrailInputStream) CrailOutputStream(org.apache.crail.CrailOutputStream) CrailFile(org.apache.crail.CrailFile) CrailBuffer(org.apache.crail.CrailBuffer)

Example 4 with CrailInputStream

use of org.apache.crail.CrailInputStream in project incubator-crail by apache.

the class CrailBenchmark method readSequentialAsync.

void readSequentialAsync(String filename, int size, int loop, int batch) throws Exception {
    System.out.println("readSequentialAsync, filename " + filename + ", size " + size + ", loop " + loop + ", batch " + batch);
    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...");
    double sumbytes = 0;
    double ops = 0;
    fs.getStatistics().reset();
    CrailFile file = fs.lookup(filename).get().asFile();
    CrailInputStream directStream = file.getDirectInputStream(file.getCapacity());
    HashMap<Integer, CrailBuffer> futureMap = new HashMap<Integer, CrailBuffer>();
    LinkedBlockingQueue<Future<CrailResult>> futureQueue = new LinkedBlockingQueue<Future<CrailResult>>();
    long start = System.currentTimeMillis();
    for (int i = 0; i < batch - 1 && ops < loop; i++) {
        CrailBuffer buf = bufferQueue.poll();
        buf.clear();
        Future<CrailResult> future = directStream.read(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.read(buf);
        futureQueue.add(future);
        futureMap.put(future.hashCode(), buf);
        future = futureQueue.poll();
        CrailResult result = future.get();
        buf = futureMap.get(future.hashCode());
        bufferQueue.add(buf);
        sumbytes = sumbytes + result.getLen();
        ops = ops + 1.0;
    }
    while (!futureQueue.isEmpty()) {
        Future<CrailResult> future = futureQueue.poll();
        CrailResult result = future.get();
        futureMap.get(future.hashCode());
        sumbytes = sumbytes + result.getLen();
        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");
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) CrailBuffer(org.apache.crail.CrailBuffer) CrailInputStream(org.apache.crail.CrailInputStream) Future(java.util.concurrent.Future) CrailFile(org.apache.crail.CrailFile) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CrailResult(org.apache.crail.CrailResult)

Aggregations

CrailBuffer (org.apache.crail.CrailBuffer)4 CrailFile (org.apache.crail.CrailFile)4 CrailInputStream (org.apache.crail.CrailInputStream)4 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)3 CrailBufferedInputStream (org.apache.crail.CrailBufferedInputStream)2 HashMap (java.util.HashMap)1 Random (java.util.Random)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Future (java.util.concurrent.Future)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 CrailOutputStream (org.apache.crail.CrailOutputStream)1 CrailResult (org.apache.crail.CrailResult)1