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();
}
}
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);
}
Aggregations