Search in sources :

Example 1 with ProcessExecutionResult

use of org.yardstickframework.BenchmarkUtils.ProcessExecutionResult in project ignite by apache.

the class IgniteFailoverAbstractBenchmark method onWarmupFinished.

/**
 * {@inheritDoc}
 */
@Override
public void onWarmupFinished() {
    if (cfg.memberId() == 0 && restarterStarted.compareAndSet(false, true)) {
        Thread restarterThread = new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    println("Servers restarter started on driver: " + IgniteFailoverAbstractBenchmark.this.getClass().getSimpleName());
                    Ignite ignite = ignite();
                    // Read servers configs from cache to local map.
                    IgniteCache<Integer, BenchmarkConfiguration> srvsCfgsCache = ignite.getOrCreateCache(new CacheConfiguration<Integer, BenchmarkConfiguration>().setName("serversConfigs"));
                    final Map<Integer, BenchmarkConfiguration> srvsCfgs = new HashMap<>();
                    for (Cache.Entry<Integer, BenchmarkConfiguration> e : srvsCfgsCache) {
                        println("Read entry from 'serversConfigs' cache : " + e);
                        srvsCfgs.put(e.getKey(), e.getValue());
                    }
                    assert ignite.cluster().forServers().nodes().size() == srvsCfgs.size();
                    final int backupsCnt = args.backups();
                    assert backupsCnt >= 1 : "Backups: " + backupsCnt;
                    final boolean isDebug = ignite.log().isDebugEnabled();
                    // Main logic.
                    while (!Thread.currentThread().isInterrupted()) {
                        Thread.sleep(args.restartDelay() * 1000);
                        int numNodesToRestart = nextRandom(1, backupsCnt + 1);
                        List<Integer> ids = new ArrayList<>();
                        ids.addAll(srvsCfgs.keySet());
                        Collections.shuffle(ids);
                        println("Waiting for partitioned map exchage of all nodes");
                        ignite.compute().broadcastAsync(new AwaitPartitionMapExchangeTask()).get(args.cacheOperationTimeoutMillis());
                        println("Start servers restarting [numNodesToRestart=" + numNodesToRestart + ", shuffledIds=" + ids + "]");
                        for (int i = 0; i < numNodesToRestart; i++) {
                            Integer id = ids.get(i);
                            BenchmarkConfiguration bc = srvsCfgs.get(id);
                            ProcessExecutionResult res = BenchmarkUtils.kill9Server(bc, isDebug);
                            println("Server with id " + id + " has been killed." + (isDebug ? " Process execution result:\n" + res : ""));
                        }
                        Thread.sleep(args.restartSleep() * 1000);
                        for (int i = 0; i < numNodesToRestart; i++) {
                            Integer id = ids.get(i);
                            BenchmarkConfiguration bc = srvsCfgs.get(id);
                            ProcessExecutionResult res = BenchmarkUtils.startServer(bc, isDebug);
                            println("Server with id " + id + " has been started." + (isDebug ? " Process execution result:\n" + res : ""));
                        }
                    }
                } catch (Throwable e) {
                    println("Got exception: " + e);
                    e.printStackTrace();
                    U.dumpThreads(null);
                    if (e instanceof Error)
                        throw (Error) e;
                }
            }
        }, "servers-restarter");
        restarterThread.setDaemon(true);
        restarterThread.start();
    }
}
Also used : BenchmarkConfiguration(org.yardstickframework.BenchmarkConfiguration) IgniteCache(org.apache.ignite.IgniteCache) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) Ignite(org.apache.ignite.Ignite) ArrayList(java.util.ArrayList) List(java.util.List) ProcessExecutionResult(org.yardstickframework.BenchmarkUtils.ProcessExecutionResult) HashMap(java.util.HashMap) Map(java.util.Map) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Ignite (org.apache.ignite.Ignite)1 IgniteCache (org.apache.ignite.IgniteCache)1 GridDhtPartitionFullMap (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap)1 GridDhtPartitionMap (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap)1 IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)1 BenchmarkConfiguration (org.yardstickframework.BenchmarkConfiguration)1 ProcessExecutionResult (org.yardstickframework.BenchmarkUtils.ProcessExecutionResult)1