Search in sources :

Example 11 with ComputeTaskFuture

use of org.apache.ignite.compute.ComputeTaskFuture in project ignite by apache.

the class SingleSplitsLoadTest method testLoad.

/**
     * Load test grid.
     *
     * @throws Exception If task execution failed.
     */
public void testLoad() throws Exception {
    final Ignite ignite = G.ignite(getTestIgniteInstanceName());
    final long end = getTestDurationInMinutes() * 60 * 1000 + System.currentTimeMillis();
    // Warm up.
    ignite.compute().withTimeout(5000).execute(SingleSplitTestTask.class.getName(), 3);
    info("Load test will be executed for '" + getTestDurationInMinutes() + "' mins.");
    info("Thread count: " + getThreadCount());
    final GridLoadTestStatistics stats = new GridLoadTestStatistics();
    GridTestUtils.runMultiThreaded(new Runnable() {

        /** {@inheritDoc} */
        @Override
        public void run() {
            while (end - System.currentTimeMillis() > 0) {
                long start = System.currentTimeMillis();
                try {
                    int levels = 20;
                    ComputeTaskFuture<Integer> fut = ignite.compute().executeAsync(new SingleSplitTestTask(), levels);
                    int res = fut.get();
                    if (res != levels)
                        fail("Received wrong result [expected=" + levels + ", actual=" + res + ']');
                    long taskCnt = stats.onTaskCompleted(fut, levels, System.currentTimeMillis() - start);
                    if (taskCnt % 500 == 0)
                        info(stats.toString());
                } catch (IgniteException e) {
                    error("Failed to execute grid task.", e);
                    fail();
                }
            }
        }
    }, getThreadCount(), "grid-notaop-load-test");
    info("Final test statistics: " + stats);
}
Also used : IgniteException(org.apache.ignite.IgniteException) ComputeTaskFuture(org.apache.ignite.compute.ComputeTaskFuture) GridLoadTestStatistics(org.apache.ignite.loadtest.GridLoadTestStatistics) Ignite(org.apache.ignite.Ignite)

Example 12 with ComputeTaskFuture

use of org.apache.ignite.compute.ComputeTaskFuture in project ignite by apache.

the class GridMultiSplitsLoadTest method testLoad.

/**
     * Load test grid.
     *
     * @throws Exception If task execution failed.
     */
public void testLoad() throws Exception {
    final Ignite ignite = G.ignite(getTestIgniteInstanceName());
    final long end = getTestDurationInMinutes() * 60 * 1000 + System.currentTimeMillis();
    // Warm up.
    ignite.compute().withTimeout(5000).execute(GridLoadTestTask.class.getName(), 3);
    info("Load test will be executed for '" + getTestDurationInMinutes() + "' mins.");
    info("Thread count: " + getThreadCount());
    final GridLoadTestStatistics stats = new GridLoadTestStatistics();
    GridTestUtils.runMultiThreaded(new Runnable() {

        /** {@inheritDoc} */
        @Override
        public void run() {
            while (end - System.currentTimeMillis() > 0) {
                int levels = 3;
                int exp = factorial(levels);
                long start = System.currentTimeMillis();
                try {
                    ComputeTaskFuture<Integer> fut = ignite.compute().executeAsync(GridLoadTestTask.class, levels);
                    int res = fut.get();
                    if (res != exp)
                        fail("Received wrong result [expected=" + exp + ", actual=" + res + ']');
                    long taskCnt = stats.onTaskCompleted(fut, exp, System.currentTimeMillis() - start);
                    if (taskCnt % 500 == 0)
                        info(stats.toString());
                } catch (IgniteException e) {
                    error("Failed to execute grid task.", e);
                    fail();
                }
            }
        }
    }, getThreadCount(), "grid-notaop-load-test");
    info("Final test statistics: " + stats);
}
Also used : IgniteException(org.apache.ignite.IgniteException) ComputeTaskFuture(org.apache.ignite.compute.ComputeTaskFuture) GridLoadTestStatistics(org.apache.ignite.loadtest.GridLoadTestStatistics) Ignite(org.apache.ignite.Ignite)

Example 13 with ComputeTaskFuture

use of org.apache.ignite.compute.ComputeTaskFuture in project ignite by apache.

the class GridSingleSplitsRedeployLoadTest method testLoad.

/**
     * Load test grid.
     *
     * @throws Exception If task execution failed.
     */
public void testLoad() throws Exception {
    final Ignite ignite = G.ignite(getTestIgniteInstanceName());
    final long end = getTestDurationInMinutes() * 60 * 1000 + System.currentTimeMillis();
    ignite.compute().localDeployTask(loadTaskClass(), loadTaskClass().getClassLoader());
    info("Load test will be executed for '" + getTestDurationInMinutes() + "' mins.");
    info("Thread count: " + getThreadCount());
    final GridLoadTestStatistics stats = new GridLoadTestStatistics();
    new Thread(new Runnable() {

        /** {@inheritDoc} */
        @SuppressWarnings("BusyWait")
        @Override
        public void run() {
            try {
                while (end - System.currentTimeMillis() > 0) {
                    Class<? extends ComputeTask<?, ?>> cls = loadTaskClass();
                    // info("Deploying class: " + cls);
                    ignite.compute().localDeployTask(cls, cls.getClassLoader());
                    Thread.sleep(1000);
                }
            } catch (Exception e) {
                error("Failed to deploy grid task.", e);
                fail();
            }
        }
    }, "grid-notaop-deploy-load-test").start();
    GridTestUtils.runMultiThreaded(new Runnable() {

        /** {@inheritDoc} */
        @Override
        public void run() {
            try {
                int levels = 3;
                while (end - System.currentTimeMillis() > 0) {
                    long start = System.currentTimeMillis();
                    // info("Executing task: " + TASK_NAME);
                    ComputeTaskFuture<Integer> fut = ignite.compute().execute(TASK_NAME, levels);
                    int res = fut.get();
                    if (res != levels)
                        fail("Received wrong result [expected=" + levels + ", actual=" + res + ']');
                    long taskCnt = stats.onTaskCompleted(fut, levels, System.currentTimeMillis() - start);
                    if (taskCnt % 500 == 0)
                        info(stats.toString());
                }
            } catch (IgniteException e) {
                error("Failed to execute grid task.", e);
                fail();
            }
        }
    }, getThreadCount(), "grid-notaop-load-test");
    info("Final test statistics: " + stats);
}
Also used : IgniteException(org.apache.ignite.IgniteException) ComputeTaskFuture(org.apache.ignite.compute.ComputeTaskFuture) GridLoadTestStatistics(org.apache.ignite.loadtest.GridLoadTestStatistics) Ignite(org.apache.ignite.Ignite) IgniteException(org.apache.ignite.IgniteException)

Example 14 with ComputeTaskFuture

use of org.apache.ignite.compute.ComputeTaskFuture in project ignite by apache.

the class GridCachePutAllFailoverSelfTest method checkPutAllFailover.

/**
     * Tests putAll() method along with failover and cache backup.
     *
     * Checks that the resulting primary cache size is the same as
     * expected.
     *
     * @param near Near enabled.
     * @param workerCnt Worker count.
     * @param shutdownCnt Shutdown count.
     * @throws Exception If failed.
     */
public void checkPutAllFailover(boolean near, int workerCnt, int shutdownCnt) throws Exception {
    nearEnabled = near;
    backups = shutdownCnt;
    Collection<Integer> testKeys = generateTestKeys();
    final Ignite master = startGrid(MASTER);
    List<Ignite> workers = new ArrayList<>(workerCnt);
    for (int i = 1; i <= workerCnt; i++) workers.add(startGrid("worker" + i));
    info("Master: " + master.cluster().localNode().id());
    List<Ignite> runningWorkers = new ArrayList<>(workerCnt);
    for (int i = 1; i <= workerCnt; i++) {
        UUID id = workers.get(i - 1).cluster().localNode().id();
        info(String.format("Worker%d - %s", i, id));
        runningWorkers.add(workers.get(i - 1));
    }
    try {
        // Dummy call to fetch affinity function from remote node
        master.affinity(CACHE_NAME).mapKeyToNode("Dummy");
        Random rnd = new Random();
        Collection<Integer> dataChunk = new ArrayList<>(DATA_CHUNK_SIZE);
        int entryCntr = 0;
        int chunkCntr = 0;
        final AtomicBoolean jobFailed = new AtomicBoolean(false);
        int failoverPushGap = 0;
        final CountDownLatch emptyLatch = new CountDownLatch(1);
        final AtomicBoolean inputExhausted = new AtomicBoolean();
        IgniteCompute comp = compute(master.cluster().forPredicate(workerNodesFilter));
        for (Integer key : testKeys) {
            dataChunk.add(key);
            entryCntr++;
            if (entryCntr == DATA_CHUNK_SIZE) {
                // time to send data
                chunkCntr++;
                assert dataChunk.size() == DATA_CHUNK_SIZE;
                log.info("Pushing data chunk [chunkNo=" + chunkCntr + "]");
                ComputeTaskFuture<Void> fut = comp.executeAsync(new GridCachePutAllTask(runningWorkers.get(rnd.nextInt(runningWorkers.size())).cluster().localNode().id(), CACHE_NAME), dataChunk);
                // Blocks if queue is full.
                resQueue.put(fut);
                fut.listen(new CI1<IgniteFuture<Void>>() {

                    @Override
                    public void apply(IgniteFuture<Void> f) {
                        ComputeTaskFuture<?> taskFut = (ComputeTaskFuture<?>) f;
                        try {
                            //if something went wrong - we'll get exception here
                            taskFut.get();
                        } catch (IgniteException e) {
                            log.error("Job failed", e);
                            jobFailed.set(true);
                        }
                        // Remove complete future from queue to allow other jobs to proceed.
                        resQueue.remove(taskFut);
                        if (inputExhausted.get() && resQueue.isEmpty())
                            emptyLatch.countDown();
                    }
                });
                entryCntr = 0;
                dataChunk = new ArrayList<>(DATA_CHUNK_SIZE);
                if (chunkCntr >= FAIL_ON_CHUNK_NO) {
                    if (workerCnt - runningWorkers.size() < shutdownCnt) {
                        if (failoverPushGap > 0)
                            failoverPushGap--;
                        else {
                            Ignite victim = runningWorkers.remove(0);
                            info("Shutting down node: " + victim.cluster().localNode().id());
                            stopGrid(victim.name());
                            // Fail next node after some jobs have been pushed.
                            failoverPushGap = FAILOVER_PUSH_GAP;
                        }
                    }
                }
            }
        }
        inputExhausted.set(true);
        if (resQueue.isEmpty())
            emptyLatch.countDown();
        assert chunkCntr == TEST_MAP_SIZE / DATA_CHUNK_SIZE;
        // Wait for queue to empty.
        log.info("Waiting for empty queue...");
        boolean failedWait = false;
        if (!emptyLatch.await(AWAIT_TIMEOUT_SEC, TimeUnit.SECONDS)) {
            info(">>> Failed to wait for queue to empty.");
            failedWait = true;
        }
        if (!failedWait)
            assertFalse("One or more jobs have failed.", jobFailed.get());
        Collection<Integer> absentKeys = findAbsentKeys(runningWorkers.get(0), testKeys);
        if (!failedWait && !absentKeys.isEmpty()) {
            // Give some time to preloader.
            U.sleep(20000);
            absentKeys = findAbsentKeys(runningWorkers.get(0), testKeys);
        }
        info(">>> Absent keys: " + absentKeys);
        if (!F.isEmpty(absentKeys)) {
            for (Ignite g : runningWorkers) {
                IgniteKernal k = (IgniteKernal) g;
                info(">>>> Entries on node: " + k.getLocalNodeId());
                GridCacheAdapter<Object, Object> cache = k.internalCache("partitioned");
                for (Integer key : absentKeys) {
                    GridCacheEntryEx entry = cache.peekEx(key);
                    if (entry != null)
                        info(" >>> " + entry);
                    if (cache.context().isNear()) {
                        GridCacheEntryEx entry0 = cache.context().near().dht().peekEx(key);
                        if (entry0 != null)
                            info(" >>> " + entry);
                    }
                }
                info("");
            }
        }
        assertTrue(absentKeys.isEmpty());
        // Actual primary cache size.
        int primaryCacheSize = 0;
        for (Ignite g : runningWorkers) {
            info("Cache size [node=" + g.name() + ", localSize=" + g.cache(CACHE_NAME).localSize() + ", localPrimarySize=" + g.cache(CACHE_NAME).localSize(PRIMARY) + ']');
            primaryCacheSize += ((IgniteKernal) g).internalCache(CACHE_NAME).primarySize();
        }
        assertEquals(TEST_MAP_SIZE, primaryCacheSize);
        for (Ignite g : runningWorkers) assertEquals(TEST_MAP_SIZE, g.cache(CACHE_NAME).size(PRIMARY));
    } finally {
        stopAllGrids();
    }
}
Also used : ArrayList(java.util.ArrayList) IgniteFuture(org.apache.ignite.lang.IgniteFuture) Random(java.util.Random) IgniteException(org.apache.ignite.IgniteException) ComputeTaskFuture(org.apache.ignite.compute.ComputeTaskFuture) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) IgniteCompute(org.apache.ignite.IgniteCompute) IgniteKernal(org.apache.ignite.internal.IgniteKernal) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 15 with ComputeTaskFuture

use of org.apache.ignite.compute.ComputeTaskFuture in project ignite by apache.

the class GridCancelledJobsMetricsSelfTest method testCancelledJobs.

/**
     * @throws Exception If failed.
     */
public void testCancelledJobs() throws Exception {
    final Ignite ignite = G.ignite(getTestIgniteInstanceName());
    Collection<ComputeTaskFuture<?>> futs = new ArrayList<>();
    for (int i = 1; i <= 10; i++) futs.add(ignite.compute().executeAsync(CancelledTask.class, null));
    // Wait to be sure that metrics were updated.
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return ignite.cluster().localNode().metrics().getTotalCancelledJobs() > 0;
        }
    }, 5000);
    colSpi.externalCollision();
    for (ComputeTaskFuture<?> fut : futs) {
        try {
            fut.get();
            assert false : "Job was not interrupted.";
        } catch (IgniteException e) {
            if (e.hasCause(InterruptedException.class))
                throw new IgniteCheckedException("Test run has been interrupted.", e);
            info("Caught expected exception: " + e.getMessage());
        }
    }
    // Job was cancelled and now we need to calculate metrics.
    int totalCancelledJobs = ignite.cluster().localNode().metrics().getTotalCancelledJobs();
    assert totalCancelledJobs == 10 : "Metrics were not updated. Expected 10 got " + totalCancelledJobs;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteException(org.apache.ignite.IgniteException) ArrayList(java.util.ArrayList) ComputeTaskFuture(org.apache.ignite.compute.ComputeTaskFuture) Ignite(org.apache.ignite.Ignite)

Aggregations

Ignite (org.apache.ignite.Ignite)17 ComputeTaskFuture (org.apache.ignite.compute.ComputeTaskFuture)17 IgniteException (org.apache.ignite.IgniteException)9 GridLoadTestStatistics (org.apache.ignite.loadtest.GridLoadTestStatistics)7 CountDownLatch (java.util.concurrent.CountDownLatch)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 ArrayList (java.util.ArrayList)4 UUID (java.util.UUID)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteCompute (org.apache.ignite.IgniteCompute)2 ComputeTask (org.apache.ignite.compute.ComputeTask)2 IgniteFuture (org.apache.ignite.lang.IgniteFuture)2 GridTestClassLoader (org.apache.ignite.testframework.GridTestClassLoader)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Random (java.util.Random)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1