Search in sources :

Example 6 with CrailFile

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

Example 7 with CrailFile

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

Example 8 with CrailFile

use of org.apache.crail.CrailFile 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 9 with CrailFile

use of org.apache.crail.CrailFile 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 10 with CrailFile

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

the class CrailHDFS method createInternal.

@Override
public FSDataOutputStream createInternal(Path path, EnumSet<CreateFlag> flag, FsPermission absolutePermission, int bufferSize, short replication, long blockSize, Progressable progress, ChecksumOpt checksumOpt, boolean createParent) throws AccessControlException, FileAlreadyExistsException, FileNotFoundException, ParentNotDirectoryException, UnsupportedFileSystemException, UnresolvedLinkException, IOException {
    CrailFile fileInfo = null;
    try {
        fileInfo = dfs.create(path.toUri().getRawPath(), CrailNodeType.DATAFILE, CrailStorageClass.PARENT, CrailLocationClass.PARENT, true).get().asFile();
    } catch (Exception e) {
        if (e.getMessage().contains(RpcErrors.messages[RpcErrors.ERR_PARENT_MISSING])) {
            fileInfo = null;
        } else {
            throw new IOException(e);
        }
    }
    if (fileInfo == null) {
        Path parent = path.getParent();
        this.mkdir(parent, FsPermission.getDirDefault(), true);
        try {
            fileInfo = dfs.create(path.toUri().getRawPath(), CrailNodeType.DATAFILE, CrailStorageClass.PARENT, CrailLocationClass.PARENT, true).get().asFile();
        } catch (Exception e) {
            throw new IOException(e);
        }
    }
    CrailBufferedOutputStream outputStream = null;
    if (fileInfo != null) {
        try {
            fileInfo.syncDir();
            outputStream = fileInfo.getBufferedOutputStream(Integer.MAX_VALUE);
        } catch (Exception e) {
            throw new IOException(e);
        }
    } else {
        throw new IOException("Failed to create file, path " + path.toString());
    }
    if (outputStream != null) {
        return new CrailHDFSOutputStream(outputStream, statistics);
    } else {
        throw new IOException("Failed to create file, path " + path.toString());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) CrailFile(org.apache.crail.CrailFile) CrailBufferedOutputStream(org.apache.crail.CrailBufferedOutputStream) IOException(java.io.IOException) 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)

Aggregations

CrailFile (org.apache.crail.CrailFile)17 CrailBuffer (org.apache.crail.CrailBuffer)8 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)6 CrailBufferedInputStream (org.apache.crail.CrailBufferedInputStream)6 CrailBufferedOutputStream (org.apache.crail.CrailBufferedOutputStream)6 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 CrailInputStream (org.apache.crail.CrailInputStream)4 HashMap (java.util.HashMap)3 Random (java.util.Random)3 Future (java.util.concurrent.Future)3 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)3 CrailOutputStream (org.apache.crail.CrailOutputStream)3 URISyntaxException (java.net.URISyntaxException)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CrailNode (org.apache.crail.CrailNode)2 CrailResult (org.apache.crail.CrailResult)2 FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)2 ParentNotDirectoryException (org.apache.hadoop.fs.ParentNotDirectoryException)2 Path (org.apache.hadoop.fs.Path)2