Search in sources :

Example 1 with LongAdder8

use of org.jsr166.LongAdder8 in project ignite by apache.

the class HadoopExecutorServiceTest method testShutdown.

/**
     * @throws Exception If failed.
     */
public void testShutdown() throws Exception {
    for (int i = 0; i < 5; i++) {
        final HadoopExecutorService exec = new HadoopExecutorService(log, "_GRID_NAME_", 10, 5);
        final LongAdder8 sum = new LongAdder8();
        final AtomicBoolean finish = new AtomicBoolean();
        IgniteInternalFuture<?> fut = multithreadedAsync(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                while (!finish.get()) {
                    exec.submit(new Callable<Void>() {

                        @Override
                        public Void call() throws Exception {
                            sum.increment();
                            return null;
                        }
                    });
                }
                return null;
            }
        }, 19);
        Thread.sleep(200);
        assertTrue(exec.shutdown(50));
        long res = sum.sum();
        assertTrue(res > 0);
        finish.set(true);
        fut.get();
        // Nothing was executed after shutdown.
        assertEquals(res, sum.sum());
        X.println("_ ok");
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HadoopExecutorService(org.apache.ignite.internal.processors.hadoop.taskexecutor.HadoopExecutorService) LongAdder8(org.jsr166.LongAdder8) Callable(java.util.concurrent.Callable)

Example 2 with LongAdder8

use of org.jsr166.LongAdder8 in project ignite by apache.

the class HadoopExecutorServiceTest method testExecutesAll.

/**
     * @throws Exception If failed.
     */
public void testExecutesAll() throws Exception {
    final HadoopExecutorService exec = new HadoopExecutorService(log, "_GRID_NAME_", 10, 5);
    for (int i = 0; i < 5; i++) {
        final int loops = 5000;
        int threads = 17;
        final LongAdder8 sum = new LongAdder8();
        multithreaded(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                for (int i = 0; i < loops; i++) {
                    exec.submit(new Callable<Void>() {

                        @Override
                        public Void call() throws Exception {
                            sum.increment();
                            return null;
                        }
                    });
                }
                return null;
            }
        }, threads);
        while (exec.active() != 0) {
            X.println("__ active: " + exec.active());
            Thread.sleep(200);
        }
        assertEquals(threads * loops, sum.sum());
        X.println("_ ok");
    }
    assertTrue(exec.shutdown(0));
}
Also used : HadoopExecutorService(org.apache.ignite.internal.processors.hadoop.taskexecutor.HadoopExecutorService) LongAdder8(org.jsr166.LongAdder8) Callable(java.util.concurrent.Callable)

Example 3 with LongAdder8

use of org.jsr166.LongAdder8 in project ignite by apache.

the class IgniteDataStreamerPerformanceTest method doTest.

/**
     * @throws Exception If failed.
     */
private void doTest() throws Exception {
    System.gc();
    System.gc();
    System.gc();
    try {
        useCache = true;
        startGridsMultiThreaded(GRID_CNT);
        useCache = false;
        Ignite ignite = startGrid();
        final IgniteDataStreamer<Integer, String> ldr = ignite.dataStreamer(DEFAULT_CACHE_NAME);
        ldr.perNodeBufferSize(8192);
        ldr.receiver(DataStreamerCacheUpdaters.<Integer, String>batchedSorted());
        ldr.autoFlushFrequency(0);
        final LongAdder8 cnt = new LongAdder8();
        long start = U.currentTimeMillis();
        Thread t = new Thread(new Runnable() {

            @SuppressWarnings("BusyWait")
            @Override
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(10000);
                    } catch (InterruptedException ignored) {
                        break;
                    }
                    info(">>> Adds/sec: " + cnt.sumThenReset() / 10);
                }
            }
        });
        t.setDaemon(true);
        t.start();
        //Runtime.getRuntime().availableProcessors();
        int threadNum = 2;
        multithreaded(new Callable<Object>() {

            @SuppressWarnings("InfiniteLoopStatement")
            @Override
            public Object call() throws Exception {
                ThreadLocalRandom8 rnd = ThreadLocalRandom8.current();
                while (true) {
                    int i = rnd.nextInt(ENTRY_CNT);
                    ldr.addData(i, vals[rnd.nextInt(vals.length)]);
                    cnt.increment();
                }
            }
        }, threadNum, "loader");
        info("Closing loader...");
        ldr.close(false);
        long duration = U.currentTimeMillis() - start;
        info("Finished performance test. Duration: " + duration + "ms.");
    } finally {
        stopAllGrids();
    }
}
Also used : ThreadLocalRandom8(org.jsr166.ThreadLocalRandom8) Ignite(org.apache.ignite.Ignite) LongAdder8(org.jsr166.LongAdder8)

Example 4 with LongAdder8

use of org.jsr166.LongAdder8 in project ignite by apache.

the class BlockingQueueTest method testBlockingQueueMultithreaded.

/**
     * @param testName Test name.
     * @param q Queue.
     * @throws Exception If failed.
     */
private static void testBlockingQueueMultithreaded(String testName, final BlockingQueue<Object> q) throws Exception {
    waitGc();
    X.println(">>> Starting test for: " + testName);
    final LongAdder8 adder = new LongAdder8();
    GridTestUtils.runMultiThreaded(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            adder.add(testBlockingQueue(q));
            return null;
        }
    }, THREAD_CNT, "queue-test-worker");
    X.println(">>> Tested queue [testName=" + testName + ", dur=" + adder.sum() + "ms]");
    assert q.isEmpty();
}
Also used : LongAdder8(org.jsr166.LongAdder8)

Example 5 with LongAdder8

use of org.jsr166.LongAdder8 in project ignite by apache.

the class GridFutureListenPerformanceTest method main.

/**
     * @param args Args.
     * @throws InterruptedException If failed.
     */
public static void main(String[] args) throws InterruptedException {
    final LongAdder8 cnt = new LongAdder8();
    final ConcurrentLinkedDeque8<GridFutureAdapter<Object>> futs = new ConcurrentLinkedDeque8<>();
    ExecutorService pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
    Thread statThread = new Thread() {

        @SuppressWarnings("BusyWait")
        @Override
        public void run() {
            while (!done) {
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException ignored) {
                    return;
                }
                System.out.println(new Date() + " Notifications per sec: " + (cnt.sumThenReset() / 5));
            }
        }
    };
    statThread.setDaemon(true);
    statThread.start();
    for (int i = 0; i < Runtime.getRuntime().availableProcessors(); i++) {
        pool.submit(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                Random rnd = new Random();
                while (!done) {
                    for (int j = 0; j < rnd.nextInt(10); j++) {
                        GridFutureAdapter<Object> fut = new GridFutureAdapter<>();
                        futs.add(fut);
                        for (int k = 1; k < rnd.nextInt(3); k++) {
                            fut.listen(new IgniteInClosure<IgniteInternalFuture<Object>>() {

                                @Override
                                public void apply(IgniteInternalFuture<Object> t) {
                                    try {
                                        t.get();
                                    } catch (IgniteCheckedException e) {
                                        e.printStackTrace();
                                    }
                                    cnt.increment();
                                }
                            });
                        }
                    }
                    GridFutureAdapter<Object> fut;
                    while ((fut = futs.poll()) != null) fut.onDone();
                }
                return null;
            }
        });
    }
    Thread.sleep(5 * 60 * 1000);
    done = true;
}
Also used : ConcurrentLinkedDeque8(org.jsr166.ConcurrentLinkedDeque8) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Date(java.util.Date) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Random(java.util.Random) ExecutorService(java.util.concurrent.ExecutorService) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) LongAdder8(org.jsr166.LongAdder8)

Aggregations

LongAdder8 (org.jsr166.LongAdder8)24 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)15 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 UUID (java.util.UUID)5 ExecutorService (java.util.concurrent.ExecutorService)5 Random (java.util.Random)4 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 IgniteUuid (org.apache.ignite.lang.IgniteUuid)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Callable (java.util.concurrent.Callable)3 Ignite (org.apache.ignite.Ignite)3 IgniteKernal (org.apache.ignite.internal.IgniteKernal)3 GridIoManager (org.apache.ignite.internal.managers.communication.GridIoManager)3 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)3 Message (org.apache.ignite.plugin.extensions.communication.Message)3 ConcurrentLinkedDeque8 (org.jsr166.ConcurrentLinkedDeque8)3 IOException (java.io.IOException)2 Timer (java.util.Timer)2