jmh-core/src/main/java/org/openjdk/jmh/runner/LoopBenchmarkHandler.java
Print this page
*** 79,88 ****
--- 79,90 ----
ThreadParams[] threadParamses = distributeThreads(numThreads, benchmarkParams.getThreadGroups());
for (int i = 0; i < runners.length; i++) {
runners[i] = new BenchmarkTask(control, threadParamses[i]);
}
+ long waitDeadline = System.nanoTime() + benchmarkParams.getTimeout().convertTo(TimeUnit.NANOSECONDS);
+
// profilers start way before the workload starts to capture
// the edge behaviors.
startProfilers(benchmarkParams, params);
// submit tasks to threadpool
*** 123,155 ****
} catch (InterruptedException e) {
// ignore
}
}
- // Adjust waiting intervals:
- // - We don't know the running time for SingleShot benchmarks,
- // we wait for at least 10 minutes for benchmark to stop; this
- // can be adjusted with usual warmup/measurement duration settings;
- // - For other benchmarks, we wait for twice the run time,
- // but at least 5 seconds to cover for low run times.
- long timeToWait;
- switch (benchmarkParams.getMode()) {
- case SingleShotTime:
- timeToWait = Math.max(TimeUnit.SECONDS.toNanos(600), runtime.convertTo(TimeUnit.NANOSECONDS));
- break;
- default:
- timeToWait = Math.max(runtime.convertTo(TimeUnit.NANOSECONDS) * 2, TimeUnit.SECONDS.toNanos(5));
- }
-
// Wait for the result, continuously polling the worker threads.
// The abrupt exception in any worker will float up here.
int expected = numThreads;
while (expected > 0) {
for (BenchmarkTask task : results.keySet()) {
Future<Collection<? extends Result>> fr = results.get(task);
try {
! fr.get(timeToWait, TimeUnit.NANOSECONDS);
expected--;
} catch (InterruptedException ex) {
throw new BenchmarkException(ex);
} catch (ExecutionException ex) {
// unwrap: ExecutionException -> Throwable-wrapper -> InvocationTargetException
--- 125,143 ----
} catch (InterruptedException e) {
// ignore
}
}
// Wait for the result, continuously polling the worker threads.
// The abrupt exception in any worker will float up here.
int expected = numThreads;
while (expected > 0) {
for (BenchmarkTask task : results.keySet()) {
Future<Collection<? extends Result>> fr = results.get(task);
try {
! long waitFor = Math.max(TimeUnit.MILLISECONDS.toNanos(100), waitDeadline - System.nanoTime());
! fr.get(waitFor, TimeUnit.NANOSECONDS);
expected--;
} catch (InterruptedException ex) {
throw new BenchmarkException(ex);
} catch (ExecutionException ex) {
// unwrap: ExecutionException -> Throwable-wrapper -> InvocationTargetException