Search in sources :

Example 16 with Ignite

use of org.apache.ignite.Ignite in project ignite by apache.

the class IgniteAtomicSequenceExample method main.

/**
     * Executes example.
     *
     * @param args Command line arguments, none required.
     * @throws Exception If example execution failed.
     */
public static void main(String[] args) throws Exception {
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        System.out.println();
        System.out.println(">>> Cache atomic sequence example started.");
        // Try increment atomic sequence on all cluster nodes. Note that this node is also part of the cluster.
        ignite.compute().broadcast(new SequenceClosure("example-sequence"));
        System.out.println();
        System.out.println("Finished atomic sequence example...");
        System.out.println("Check all nodes for output (this node is also part of the cluster).");
        System.out.println();
    }
}
Also used : Ignite(org.apache.ignite.Ignite)

Example 17 with Ignite

use of org.apache.ignite.Ignite in project ignite by apache.

the class CacheApiExample method main.

/**
     * Executes example.
     *
     * @param args Command line arguments, none required.
     * @throws IgniteException If example execution failed.
     */
public static void main(String[] args) throws IgniteException {
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        System.out.println();
        System.out.println(">>> Cache API example started.");
        // Auto-close cache at the end of the example.
        try (IgniteCache<Integer, String> cache = ignite.getOrCreateCache(CACHE_NAME)) {
            // Demonstrate atomic map operations.
            atomicMapOperations(cache);
        } finally {
            // Distributed cache could be removed from cluster only by #destroyCache() call.
            ignite.destroyCache(CACHE_NAME);
        }
    }
}
Also used : Ignite(org.apache.ignite.Ignite)

Example 18 with Ignite

use of org.apache.ignite.Ignite in project ignite by apache.

the class CacheAsyncApiExample method main.

/**
     * Executes example.
     *
     * @param args Command line arguments, none required.
     * @throws IgniteException If example execution failed.
     */
public static void main(String[] args) throws IgniteException {
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        System.out.println();
        System.out.println(">>> Cache asynchronous API example started.");
        // Auto-close cache at the end of the example.
        try (IgniteCache<Integer, String> cache = ignite.getOrCreateCache(CACHE_NAME)) {
            Collection<IgniteFuture<?>> futs = new ArrayList<>();
            // Execute several puts asynchronously.
            for (int i = 0; i < 10; i++) futs.add(cache.putAsync(i, String.valueOf(i)));
            // Wait for completion of all futures.
            for (IgniteFuture<?> fut : futs) fut.get();
            // Execute get operation asynchronously and wait for result.
            cache.getAsync(1).listen(new IgniteInClosure<IgniteFuture<String>>() {

                @Override
                public void apply(IgniteFuture<String> fut) {
                    System.out.println("Get operation completed [value=" + fut.get() + ']');
                }
            });
        } finally {
            // Distributed cache could be removed from cluster only by #destroyCache() call.
            ignite.destroyCache(CACHE_NAME);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) IgniteFuture(org.apache.ignite.lang.IgniteFuture) Ignite(org.apache.ignite.Ignite)

Example 19 with Ignite

use of org.apache.ignite.Ignite in project ignite by apache.

the class GridifySingleSplitLoadTest method testGridifyLoad.

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

        @Override
        public void run() {
            while (end - System.currentTimeMillis() > 0) {
                int levels = 3;
                int exp = factorial(levels);
                long start = System.currentTimeMillis();
                int res = new GridifyLoadTestJobTarget().executeLoadTestJob(exp);
                if (res != exp)
                    fail("Received wrong result [expected=" + exp + ", actual=" + res + ']');
                long taskCnt = stats.onTaskCompleted(null, exp, System.currentTimeMillis() - start);
                if (taskCnt % 500 == 0)
                    info(stats.toString());
            }
        }
    }, getThreadCount(), "grid-load-test-thread");
    info("Final test statistics: " + stats);
}
Also used : GridLoadTestStatistics(org.apache.ignite.loadtest.GridLoadTestStatistics) Ignite(org.apache.ignite.Ignite)

Example 20 with Ignite

use of org.apache.ignite.Ignite in project ignite by apache.

the class DistributedRegressionExample method main.

/** Run example. */
public static void main(String[] args) throws InterruptedException {
    System.out.println();
    System.out.println(">>> Linear regression over sparse distributed matrix API usage example started.");
    // Start ignite grid.
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        System.out.println(">>> Ignite grid started.");
        // Create IgniteThread, we must work with SparseDistributedMatrix inside IgniteThread
        // because we create ignite cache internally.
        IgniteThread igniteThread = new IgniteThread(ignite.configuration().getIgniteInstanceName(), SparseDistributedMatrixExample.class.getSimpleName(), () -> {
            double[] data = { 8, 78, 284, 9.100000381, 109, 9.300000191, 68, 433, 8.699999809, 144, 7.5, 70, 739, 7.199999809, 113, 8.899999619, 96, 1792, 8.899999619, 97, 10.19999981, 74, 477, 8.300000191, 206, 8.300000191, 111, 362, 10.89999962, 124, 8.800000191, 77, 671, 10, 152, 8.800000191, 168, 636, 9.100000381, 162, 10.69999981, 82, 329, 8.699999809, 150, 11.69999981, 89, 634, 7.599999905, 134, 8.5, 149, 631, 10.80000019, 292, 8.300000191, 60, 257, 9.5, 108, 8.199999809, 96, 284, 8.800000191, 111, 7.900000095, 83, 603, 9.5, 182, 10.30000019, 130, 686, 8.699999809, 129, 7.400000095, 145, 345, 11.19999981, 158, 9.600000381, 112, 1357, 9.699999809, 186, 9.300000191, 131, 544, 9.600000381, 177, 10.60000038, 80, 205, 9.100000381, 127, 9.699999809, 130, 1264, 9.199999809, 179, 11.60000038, 140, 688, 8.300000191, 80, 8.100000381, 154, 354, 8.399999619, 103, 9.800000191, 118, 1632, 9.399999619, 101, 7.400000095, 94, 348, 9.800000191, 117, 9.399999619, 119, 370, 10.39999962, 88, 11.19999981, 153, 648, 9.899999619, 78, 9.100000381, 116, 366, 9.199999809, 102, 10.5, 97, 540, 10.30000019, 95, 11.89999962, 176, 680, 8.899999619, 80, 8.399999619, 75, 345, 9.600000381, 92, 5, 134, 525, 10.30000019, 126, 9.800000191, 161, 870, 10.39999962, 108, 9.800000191, 111, 669, 9.699999809, 77, 10.80000019, 114, 452, 9.600000381, 60, 10.10000038, 142, 430, 10.69999981, 71, 10.89999962, 238, 822, 10.30000019, 86, 9.199999809, 78, 190, 10.69999981, 93, 8.300000191, 196, 867, 9.600000381, 106, 7.300000191, 125, 969, 10.5, 162, 9.399999619, 82, 499, 7.699999809, 95, 9.399999619, 125, 925, 10.19999981, 91, 9.800000191, 129, 353, 9.899999619, 52, 3.599999905, 84, 288, 8.399999619, 110, 8.399999619, 183, 718, 10.39999962, 69, 10.80000019, 119, 540, 9.199999809, 57, 10.10000038, 180, 668, 13, 106, 9, 82, 347, 8.800000191, 40, 10, 71, 345, 9.199999809, 50, 11.30000019, 118, 463, 7.800000191, 35, 11.30000019, 121, 728, 8.199999809, 86, 12.80000019, 68, 383, 7.400000095, 57, 10, 112, 316, 10.39999962, 57, 6.699999809, 109, 388, 8.899999619, 94 };
            final int nobs = 53;
            final int nvars = 4;
            System.out.println(">>> Create new SparseDistributedMatrix inside IgniteThread.");
            // Create SparseDistributedMatrix, new cache will be created automagically.
            SparseDistributedMatrix distributedMatrix = new SparseDistributedMatrix(0, 0, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
            System.out.println(">>> Create new linear regression object");
            OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression();
            regression.newSampleData(data, nobs, nvars, distributedMatrix);
            System.out.println();
            System.out.println(">>> Estimates the regression parameters b:");
            System.out.println(Arrays.toString(regression.estimateRegressionParameters()));
            System.out.println(">>> Estimates the residuals, ie u = y - X*b:");
            System.out.println(Arrays.toString(regression.estimateResiduals()));
            System.out.println(">>> Standard errors of the regression parameters:");
            System.out.println(Arrays.toString(regression.estimateRegressionParametersStandardErrors()));
            System.out.println(">>> Estimates the variance of the regression parameters, ie Var(b):");
            Tracer.showAscii(regression.estimateRegressionParametersVariance());
            System.out.println(">>> Estimates the standard error of the regression:");
            System.out.println(regression.estimateRegressionStandardError());
            System.out.println(">>> R-Squared statistic:");
            System.out.println(regression.calculateRSquared());
            System.out.println(">>> Adjusted R-squared statistic:");
            System.out.println(regression.calculateAdjustedRSquared());
            System.out.println(">>> Returns the variance of the regressand, ie Var(y):");
            System.out.println(regression.estimateErrorVariance());
        });
        igniteThread.start();
        igniteThread.join();
    }
}
Also used : SparseDistributedMatrix(org.apache.ignite.ml.math.impls.matrix.SparseDistributedMatrix) SparseDistributedMatrixExample(org.apache.ignite.examples.ml.math.matrix.SparseDistributedMatrixExample) OLSMultipleLinearRegression(org.apache.ignite.ml.regressions.OLSMultipleLinearRegression) Ignite(org.apache.ignite.Ignite) IgniteThread(org.apache.ignite.thread.IgniteThread)

Aggregations

Ignite (org.apache.ignite.Ignite)1560 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)275 CountDownLatch (java.util.concurrent.CountDownLatch)188 IgniteException (org.apache.ignite.IgniteException)187 Transaction (org.apache.ignite.transactions.Transaction)166 IgniteCache (org.apache.ignite.IgniteCache)161 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)161 ArrayList (java.util.ArrayList)135 ClusterNode (org.apache.ignite.cluster.ClusterNode)121 UUID (java.util.UUID)104 Event (org.apache.ignite.events.Event)104 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)98 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)97 CacheException (javax.cache.CacheException)94 HashMap (java.util.HashMap)78 IgniteKernal (org.apache.ignite.internal.IgniteKernal)71 Map (java.util.Map)61 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)61 Callable (java.util.concurrent.Callable)60 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)60