Search in sources :

Example 11 with StopWatch

use of org.apache.hadoop.util.StopWatch in project hadoop by apache.

the class RawErasureCoderBenchmark method performBench.

/**
   * Performs benchmark.
   *
   * @param opType      The operation to perform. Can be encode or decode
   * @param coder       The coder to use
   * @param numThreads  Number of threads to launch concurrently
   * @param dataSizeMB  Total test data size in MB
   * @param chunkSizeKB Chunk size in KB
   */
public static void performBench(String opType, CODER coder, int numThreads, int dataSizeMB, int chunkSizeKB) throws Exception {
    BenchData.configure(dataSizeMB, chunkSizeKB);
    RawErasureEncoder encoder = null;
    RawErasureDecoder decoder = null;
    ByteBuffer testData;
    boolean isEncode = opType.equals("encode");
    if (isEncode) {
        encoder = getRawEncoder(coder.ordinal());
        testData = genTestData(encoder.preferDirectBuffer(), BenchData.bufferSizeKB);
    } else {
        decoder = getRawDecoder(coder.ordinal());
        testData = genTestData(decoder.preferDirectBuffer(), BenchData.bufferSizeKB);
    }
    ExecutorService executor = Executors.newFixedThreadPool(numThreads);
    List<Future<Long>> futures = new ArrayList<>(numThreads);
    StopWatch sw = new StopWatch().start();
    for (int i = 0; i < numThreads; i++) {
        futures.add(executor.submit(new BenchmarkCallable(isEncode, encoder, decoder, testData.duplicate())));
    }
    List<Long> durations = new ArrayList<>(numThreads);
    try {
        for (Future<Long> future : futures) {
            durations.add(future.get());
        }
        long duration = sw.now(TimeUnit.MILLISECONDS);
        double totalDataSize = BenchData.totalDataSizeKB * numThreads / 1024.0;
        DecimalFormat df = new DecimalFormat("#.##");
        System.out.println(coder + " " + opType + " " + df.format(totalDataSize) + "MB data, with chunk size " + BenchData.chunkSize / 1024 + "KB");
        System.out.println("Total time: " + df.format(duration / 1000.0) + " s.");
        System.out.println("Total throughput: " + df.format(totalDataSize / duration * 1000.0) + " MB/s");
        printThreadStatistics(durations, df);
    } catch (Exception e) {
        System.out.println("Error waiting for thread to finish.");
        e.printStackTrace();
        throw e;
    } finally {
        executor.shutdown();
    }
}
Also used : DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer) StopWatch(org.apache.hadoop.util.StopWatch) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future)

Example 12 with StopWatch

use of org.apache.hadoop.util.StopWatch in project hadoop by apache.

the class ITestBlockingThreadPoolExecutorService method verifyQueueSize.

/**
   * Verify the size of the executor's queue, by verifying that the first
   * submission to block is {@code expectedQueueSize + 1}.
   * @param executorService executor service to test
   * @param expectedQueueSize size of queue
   */
protected void verifyQueueSize(ExecutorService executorService, int expectedQueueSize) {
    StopWatch stopWatch = new StopWatch().start();
    for (int i = 0; i < expectedQueueSize; i++) {
        executorService.submit(sleeper);
        assertDidntBlock(stopWatch);
    }
    executorService.submit(sleeper);
    assertDidBlock(stopWatch);
}
Also used : StopWatch(org.apache.hadoop.util.StopWatch)

Aggregations

StopWatch (org.apache.hadoop.util.StopWatch)12 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 FileStatus (org.apache.hadoop.fs.FileStatus)4 LocatedFileStatus (org.apache.hadoop.fs.LocatedFileStatus)4 Path (org.apache.hadoop.fs.Path)4 InterruptedIOException (java.io.InterruptedIOException)2 DecimalFormat (java.text.DecimalFormat)2 BlockLocation (org.apache.hadoop.fs.BlockLocation)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 PathFilter (org.apache.hadoop.fs.PathFilter)2 ByteString (com.google.protobuf.ByteString)1 InetAddress (java.net.InetAddress)1 ByteBuffer (java.nio.ByteBuffer)1 LinkedList (java.util.LinkedList)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 DfsClientConf (org.apache.hadoop.hdfs.client.impl.DfsClientConf)1 ClientDatanodeProtocol (org.apache.hadoop.hdfs.protocol.ClientDatanodeProtocol)1 DatanodeInfo (org.apache.hadoop.hdfs.protocol.DatanodeInfo)1