Search in sources :

Example 1 with CrailBufferedInputStream

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

the class CrailHDFS method open.

@Override
public FSDataInputStream open(Path path, int bufferSize) throws AccessControlException, FileNotFoundException, UnresolvedLinkException, IOException {
    CrailFile fileInfo = null;
    try {
        fileInfo = dfs.lookup(path.toUri().getRawPath()).get().asFile();
    } catch (Exception e) {
        throw new IOException(e);
    }
    CrailBufferedInputStream inputStream = null;
    if (fileInfo != null) {
        try {
            inputStream = fileInfo.getBufferedInputStream(fileInfo.getCapacity());
        } catch (Exception e) {
            throw new IOException(e);
        }
    }
    if (inputStream != null) {
        return new CrailHDFSInputStream(inputStream);
    } else {
        throw new IOException("Failed to open file, path " + path.toString());
    }
}
Also used : CrailFile(org.apache.crail.CrailFile) IOException(java.io.IOException) CrailBufferedInputStream(org.apache.crail.CrailBufferedInputStream) URISyntaxException(java.net.URISyntaxException) UnresolvedLinkException(org.apache.hadoop.fs.UnresolvedLinkException) ParentNotDirectoryException(org.apache.hadoop.fs.ParentNotDirectoryException) FileAlreadyExistsException(org.apache.hadoop.fs.FileAlreadyExistsException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) AccessControlException(org.apache.hadoop.security.AccessControlException) UnsupportedFileSystemException(org.apache.hadoop.fs.UnsupportedFileSystemException)

Example 2 with CrailBufferedInputStream

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

the class CrailBenchmark method readMultiStreamInt.

void readMultiStreamInt(String filename, int loop, int batch) throws Exception {
    System.out.println("readMultiStreamInt, filename " + filename + ", loop " + loop + ", batch " + batch);
    System.out.println("starting benchmark...");
    fs.getStatistics().reset();
    CrailBufferedInputStream multiStream = fs.lookup(filename).get().asMultiFile().getMultiStream(batch);
    double ops = 0;
    long falseMatches = 0;
    while (ops < loop) {
        System.out.print("reading position " + multiStream.position() + ", expected " + multiStream.position() / 4 + " ");
        long expected = multiStream.position() / 4;
        int intValue = multiStream.readInt();
        if (expected != intValue) {
            falseMatches++;
        }
        System.out.println(", value " + intValue);
        ops++;
    }
    multiStream.close();
    System.out.println("falseMatches " + falseMatches);
    fs.getStatistics().print("close");
}
Also used : CrailBufferedInputStream(org.apache.crail.CrailBufferedInputStream)

Example 3 with CrailBufferedInputStream

use of org.apache.crail.CrailBufferedInputStream 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 4 with CrailBufferedInputStream

use of org.apache.crail.CrailBufferedInputStream 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 5 with CrailBufferedInputStream

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

the class CrailBenchmark method readMultiStream.

void readMultiStream(String filename, int size, int loop, int batch) throws Exception {
    System.out.println("readMultiStream, filename " + filename + ", size " + size + ", loop " + loop + ", batch " + batch);
    // warmup
    ConcurrentLinkedQueue<CrailBuffer> bufferQueue = new ConcurrentLinkedQueue<CrailBuffer>();
    for (int i = 0; i < warmup; i++) {
        CrailBuffer buf = fs.allocateBuffer().limit(size).slice();
        bufferQueue.add(buf);
    }
    warmUp(filename, warmup, bufferQueue);
    while (!bufferQueue.isEmpty()) {
        CrailBuffer buf = bufferQueue.poll();
        fs.freeBuffer(buf);
    }
    // benchmark
    System.out.println("starting benchmark...");
    fs.getStatistics().reset();
    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));
    }
    ByteBuffer buf = _buf.getByteBuffer();
    for (int i = 0; i < loop; i++) {
        CrailBufferedInputStream multiStream = fs.lookup(filename).get().asMultiFile().getMultiStream(batch);
        double sumbytes = 0;
        long _sumbytes = 0;
        double ops = 0;
        buf.clear();
        long start = System.currentTimeMillis();
        int ret = multiStream.read(buf);
        while (ret >= 0) {
            sumbytes = sumbytes + ret;
            long _ret = (long) ret;
            _sumbytes += _ret;
            ops = ops + 1.0;
            buf.clear();
            ret = multiStream.read(buf);
        }
        long end = System.currentTimeMillis();
        multiStream.close();
        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("round " + i + ":");
        System.out.println("bytes read " + _sumbytes);
        System.out.println("execution time " + executionTime);
        System.out.println("ops " + ops);
        System.out.println("throughput " + throughput);
        System.out.println("latency " + latency);
    }
    fs.getStatistics().print("close");
}
Also used : ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) ByteBuffer(java.nio.ByteBuffer) CrailBufferedInputStream(org.apache.crail.CrailBufferedInputStream) CrailBuffer(org.apache.crail.CrailBuffer)

Aggregations

CrailBufferedInputStream (org.apache.crail.CrailBufferedInputStream)9 CrailFile (org.apache.crail.CrailFile)6 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)3 CrailBuffer (org.apache.crail.CrailBuffer)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 Random (java.util.Random)2 CrailInputStream (org.apache.crail.CrailInputStream)2 URISyntaxException (java.net.URISyntaxException)1 ByteBuffer (java.nio.ByteBuffer)1 CrailKeyValue (org.apache.crail.CrailKeyValue)1 FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)1 ParentNotDirectoryException (org.apache.hadoop.fs.ParentNotDirectoryException)1 UnresolvedLinkException (org.apache.hadoop.fs.UnresolvedLinkException)1 UnsupportedFileSystemException (org.apache.hadoop.fs.UnsupportedFileSystemException)1 AccessControlException (org.apache.hadoop.security.AccessControlException)1 ByteArrayByteIterator (site.ycsb.ByteArrayByteIterator)1 DBException (site.ycsb.DBException)1 Status (site.ycsb.Status)1