Search in sources :

Example 11 with CrailFile

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

the class CrailHadoopFileSystem method open.

public FSDataInputStream open(Path path, int bufferSize) throws IOException {
    CrailFile fileInfo = null;
    try {
        fileInfo = dfs.lookup(path.toUri().getRawPath()).get().asFile();
        CrailBufferedInputStream inputStream = fileInfo.getBufferedInputStream(fileInfo.getCapacity());
        return new CrailHDFSInputStream(inputStream);
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : CrailFile(org.apache.crail.CrailFile) IOException(java.io.IOException) CrailBufferedInputStream(org.apache.crail.CrailBufferedInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 12 with CrailFile

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

the class CrailBenchmark method early.

void early(String filename) throws Exception {
    ByteBuffer buf = ByteBuffer.allocateDirect(32);
    CrailFile file = fs.create(filename, CrailNodeType.DATAFILE, CrailStorageClass.DEFAULT, CrailLocationClass.DEFAULT, true).early().asFile();
    CrailBufferedOutputStream stream = file.getBufferedOutputStream(0);
    System.out.println("buffered stream initialized");
    Thread.sleep(1000);
    stream.write(buf);
    System.out.println("buffered stream written");
    Thread.sleep(1000);
    stream.write(buf);
    System.out.println("buffered stream written");
    stream.purge();
    stream.close();
    System.out.println("buffered stream closed");
    fs.getStatistics().print("close");
}
Also used : CrailFile(org.apache.crail.CrailFile) CrailBufferedOutputStream(org.apache.crail.CrailBufferedOutputStream) ByteBuffer(java.nio.ByteBuffer)

Example 13 with CrailFile

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

the class CrailBenchmark method readInt.

void readInt(String filename, int loop) throws Exception {
    System.out.println("seek, filename " + filename + ", loop " + loop);
    // benchmark
    System.out.println("starting benchmark...");
    double ops = 0;
    CrailFile file = fs.lookup(filename).get().asFile();
    CrailBufferedInputStream inputStream = file.getBufferedInputStream(loop * 4);
    System.out.println("starting read at position " + inputStream.position());
    while (ops < loop) {
        System.out.print("reading position " + inputStream.position() + ", expected " + inputStream.position() / 4 + " ");
        int intValue = inputStream.readInt();
        System.out.println(", value " + intValue);
        ops++;
    }
    inputStream.close();
    fs.getStatistics().print("close");
}
Also used : CrailFile(org.apache.crail.CrailFile) CrailBufferedInputStream(org.apache.crail.CrailBufferedInputStream)

Example 14 with CrailFile

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

the class CrailBenchmark method seekInt.

void seekInt(String filename, int loop) throws Exception {
    System.out.println("seek, filename " + filename + ", loop " + loop);
    // benchmark
    System.out.println("starting benchmark...");
    double ops = 0;
    CrailFile file = fs.lookup(filename).get().asFile();
    Random random = new Random();
    long nbrOfInts = file.getCapacity() / 4;
    CrailBufferedInputStream seekStream = file.getBufferedInputStream(loop * 4);
    System.out.println("starting seek phase, nbrOfInts " + nbrOfInts + ", position " + seekStream.position());
    long falseMatches = 0;
    while (ops < loop) {
        int intIndex = random.nextInt((int) nbrOfInts);
        int pos = intIndex * 4;
        seekStream.seek((long) pos);
        int intValue = seekStream.readInt();
        if (intIndex != intValue) {
            falseMatches++;
            System.out.println("reading, position " + pos + ", expected " + pos / 4 + ", ########## value " + intValue);
        } else {
            System.out.println("reading, position " + pos + ", expected " + pos / 4 + ", value " + intValue);
        }
        ops++;
    }
    seekStream.close();
    long end = System.currentTimeMillis();
    System.out.println("falseMatches " + falseMatches);
    fs.getStatistics().print("close");
}
Also used : Random(java.util.Random) CrailFile(org.apache.crail.CrailFile) CrailBufferedInputStream(org.apache.crail.CrailBufferedInputStream)

Example 15 with CrailFile

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

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