use of org.apache.ignite.compute.ComputeTaskCancelledException in project ignite by apache.
the class GridJobExecutionSingleNodeLoadTest method main.
/**
* @param args Command line arguments:
* 1-st: Number of worker threads. Default: 32.
* 2-nd: Test duration in seconds. 0 means infinite. Default: 0.
* 3-rd: File to output test results to.
* @throws Exception If failed.
*/
public static void main(String[] args) throws Exception {
GridFileLock fileLock = GridLoadTestUtils.fileLock();
fileLock.lock();
try {
// Command line arguments.
int threadCnt = args.length == 0 ? 64 : Integer.parseInt(args[0]);
final int duration = args.length < 2 ? 0 : Integer.parseInt(args[1]);
final String outputFileName = args.length < 3 ? null : args[2];
final AtomicLong tasksCnt = new AtomicLong();
final AtomicBoolean finish = new AtomicBoolean();
ExecutorService pool = Executors.newFixedThreadPool(threadCnt);
Collection<Callable<Object>> producers = new ArrayList<>(threadCnt);
Thread collector = null;
Thread timer = null;
try {
final Ignite g = G.start("modules/core/src/test/config/grid-job-load.xml");
X.println("Warming up...");
GridLoadTestUtils.runMultithreadedInLoop(new Callable<Object>() {
@Override
public Object call() {
g.compute().execute(GridJobExecutionLoadTestTask.class, null);
return null;
}
}, threadCnt, WARM_UP_DURATION);
System.gc();
X.println("Running main test.");
for (int i = 0; i < threadCnt; i++) producers.add(new Callable<Object>() {
@SuppressWarnings({ "unchecked", "InfiniteLoopStatement" })
@Override
public Object call() throws Exception {
while (!finish.get()) {
try {
g.compute().execute(GridJobExecutionLoadTestTask.class, null);
tasksCnt.incrementAndGet();
} catch (ComputeTaskCancelledException ignored) {
// No-op.
} catch (IgniteException e) {
e.printStackTrace();
}
}
return null;
}
});
// Thread that measures and outputs performance statistics.
collector = new Thread(new Runnable() {
@SuppressWarnings({ "BusyWait", "InfiniteLoopStatement" })
@Override
public void run() {
GridCumulativeAverage avgTasksPerSec = new GridCumulativeAverage();
try {
while (!finish.get()) {
long cnt0 = tasksCnt.get();
Thread.sleep(UPDATE_INTERVAL_SEC * 1000);
long cnt1 = tasksCnt.get();
long curTasksPerSec = (cnt1 - cnt0) / UPDATE_INTERVAL_SEC;
X.println(">>> Tasks/s: " + curTasksPerSec);
avgTasksPerSec.update(curTasksPerSec);
}
} catch (InterruptedException ignored) {
X.println(">>> Interrupted.");
Thread.currentThread().interrupt();
}
X.println(">>> Average tasks/s: " + avgTasksPerSec);
if (outputFileName != null) {
X.println("Writing test results to a file: " + outputFileName);
try {
GridLoadTestUtils.appendLineToFile(outputFileName, "%s,%d", GridLoadTestUtils.DATE_TIME_FORMAT.format(new Date()), avgTasksPerSec.get());
} catch (IOException e) {
X.error("Failed to output to a file", e);
}
}
}
});
collector.start();
if (duration > 0) {
// Thread that stops the test after a specified period of time.
timer = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(duration * 1000);
finish.set(true);
} catch (InterruptedException ignored) {
// No-op.
}
}
});
timer.start();
}
pool.invokeAll(producers);
X.println("All done, stopping.");
collector.interrupt();
pool.shutdown();
} finally {
if (collector != null && !collector.isInterrupted())
collector.interrupt();
if (timer != null)
timer.interrupt();
G.stopAll(true);
}
} finally {
fileLock.close();
}
}
use of org.apache.ignite.compute.ComputeTaskCancelledException in project ignite by apache.
the class IgniteUtils method exceptionConverters.
/**
* Gets map with converters to convert internal checked exceptions to public API unchecked exceptions.
*
* @return Exception converters.
*/
private static Map<Class<? extends IgniteCheckedException>, C1<IgniteCheckedException, IgniteException>> exceptionConverters() {
Map<Class<? extends IgniteCheckedException>, C1<IgniteCheckedException, IgniteException>> m = new HashMap<>();
m.put(IgniteInterruptedCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteInterruptedException(e.getMessage(), (InterruptedException) e.getCause());
}
});
m.put(IgniteFutureCancelledCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteFutureCancelledException(e.getMessage(), e);
}
});
m.put(IgniteFutureTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteFutureTimeoutException(e.getMessage(), e);
}
});
m.put(ClusterGroupEmptyCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new ClusterGroupEmptyException(e.getMessage(), e);
}
});
m.put(ClusterTopologyCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
ClusterTopologyException topEx = new ClusterTopologyException(e.getMessage(), e);
ClusterTopologyCheckedException checked = (ClusterTopologyCheckedException) e;
if (checked.retryReadyFuture() != null)
topEx.retryReadyFuture(new IgniteFutureImpl<>(checked.retryReadyFuture()));
return topEx;
}
});
m.put(IgniteDeploymentCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteDeploymentException(e.getMessage(), e);
}
});
m.put(ComputeTaskTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new ComputeTaskTimeoutException(e.getMessage(), e);
}
});
m.put(ComputeTaskCancelledCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new ComputeTaskCancelledException(e.getMessage(), e);
}
});
m.put(IgniteTxRollbackCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionRollbackException(e.getMessage(), e);
}
});
m.put(IgniteTxHeuristicCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionHeuristicException(e.getMessage(), e);
}
});
m.put(IgniteTxTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
if (e.getCause() instanceof TransactionDeadlockException)
return new TransactionTimeoutException(e.getMessage(), e.getCause());
return new TransactionTimeoutException(e.getMessage(), e);
}
});
m.put(IgniteTxOptimisticCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionOptimisticException(e.getMessage(), e);
}
});
m.put(IgniteClientDisconnectedCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteClientDisconnectedException(((IgniteClientDisconnectedCheckedException) e).reconnectFuture(), e.getMessage(), e);
}
});
return m;
}
Aggregations