Search in sources :

Example 1 with SimulateLoadTask

use of com.hazelcast.console.SimulateLoadTask in project hazelcast by hazelcast.

the class ClientConsoleApp method handleExecutorSimulate.

private void handleExecutorSimulate(String[] args) {
    String first = args[0];
    int threadCount = Integer.parseInt(first.substring(1, first.indexOf(".")));
    if (threadCount < 1 || threadCount > MAX_THREAD_COUNT) {
        throw new RuntimeException("threadcount can't be smaller than 1 or larger than 16");
    }
    int taskCount = Integer.parseInt(args[1]);
    int durationSec = Integer.parseInt(args[2]);
    long startMs = System.currentTimeMillis();
    IExecutorService executor = hazelcast.getExecutorService(executorNamespace + ' ' + threadCount);
    List<Future> futures = new LinkedList<Future>();
    List<Member> members = new LinkedList<Member>(hazelcast.getCluster().getMembers());
    int totalThreadCount = hazelcast.getCluster().getMembers().size() * threadCount;
    int latchId = 0;
    for (int k = 0; k < taskCount; k++) {
        Member member = members.get(k % members.size());
        if (taskCount % totalThreadCount == 0) {
            latchId = taskCount / totalThreadCount;
            hazelcast.getCountDownLatch("latch" + latchId).trySetCount(totalThreadCount);
        }
        Future f = executor.submitToMember(new SimulateLoadTask(durationSec, k + 1, "latch" + latchId), member);
        futures.add(f);
    }
    for (Future f : futures) {
        try {
            f.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
    long durationMs = System.currentTimeMillis() - startMs;
    println(format("Executed %s tasks in %s ms", taskCount, durationMs));
}
Also used : IExecutorService(com.hazelcast.core.IExecutorService) LinkedList(java.util.LinkedList) Future(java.util.concurrent.Future) SimulateLoadTask(com.hazelcast.console.SimulateLoadTask) ExecutionException(java.util.concurrent.ExecutionException) Member(com.hazelcast.core.Member)

Aggregations

SimulateLoadTask (com.hazelcast.console.SimulateLoadTask)1 IExecutorService (com.hazelcast.core.IExecutorService)1 Member (com.hazelcast.core.Member)1 LinkedList (java.util.LinkedList)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1