Search in sources :

Example 11 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;
    pool.shutdownNow();
    pool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}
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) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) ExecutorService(java.util.concurrent.ExecutorService) LongAdder8(org.jsr166.LongAdder8)

Example 12 with LongAdder8

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

the class GridCircularBufferPerformanceTest method testArrayBlockingQueueThroughput.

/**
     * @throws Exception If failed.
     */
public void testArrayBlockingQueueThroughput() throws Exception {
    final int size = 256 * 1024;
    final ArrayBlockingQueue<Integer> buf = new ArrayBlockingQueue<>(size);
    final LongAdder8 cnt = new LongAdder8();
    final AtomicBoolean finished = new AtomicBoolean();
    multithreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            while (!finished.get()) {
                U.sleep(5000);
                info("Ops/sec: " + cnt.sumThenReset() / 5);
            }
            return null;
        }
    }, 1);
    multithreaded(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            while (!finished.get()) {
                buf.add(1);
                buf.poll();
                cnt.increment();
            }
            return null;
        }
    }, 8);
    info("Buffer: " + buf);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) LongAdder8(org.jsr166.LongAdder8)

Example 13 with LongAdder8

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

the class GridCircularBufferPerformanceTest method testDequeueThroughput.

/**
     * @throws Exception If failed.
     */
public void testDequeueThroughput() throws Exception {
    final ConcurrentLinkedDeque8<Integer> buf = new ConcurrentLinkedDeque8<>();
    final LongAdder8 cnt = new LongAdder8();
    final AtomicBoolean finished = new AtomicBoolean();
    multithreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            while (!finished.get()) {
                U.sleep(5000);
                info("Ops/sec: " + cnt.sumThenReset() / 5);
            }
            return null;
        }
    }, 1);
    final int size = 256 * 1024;
    multithreaded(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            while (!finished.get()) {
                buf.add(1);
                if (buf.sizex() > size)
                    buf.poll();
                cnt.increment();
            }
            return null;
        }
    }, 8);
    info("Buffer: " + buf);
}
Also used : ConcurrentLinkedDeque8(org.jsr166.ConcurrentLinkedDeque8) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LongAdder8(org.jsr166.LongAdder8)

Example 14 with LongAdder8

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

the class IntMaxValueEntriesTest method test.

/** {@inheritDoc} */
@Override
public boolean test(Map<Object, Object> ctx) throws Exception {
    final IgniteCache<Integer, Object> cache = cache();
    final IgniteDataStreamer<Integer, Object> stmr = ignite().dataStreamer(cache.getName());
    final List<Thread> threads = new ArrayList<>(THREADS);
    final LongAdder8 addedCnt = new LongAdder8();
    int delta = (int) ((KEYS_HI + Math.abs(KEYS_LO)) / THREADS);
    System.out.println("Delta: " + delta);
    for (int i = 0; i < THREADS; i++) {
        final int lo = i == 0 ? KEYS_LO : delta * i + 1;
        final int hi = i == THREADS - 1 ? (int) KEYS_HI : (int) ((long) delta * (i + 1));
        Thread t = new Thread(new Runnable() {

            @Override
            public void run() {
                ThreadLocalRandom rnd = ThreadLocalRandom.current();
                byte val = (byte) rnd.nextInt();
                println("Start from " + lo + " to " + hi);
                for (int j = lo, k = 0; j < hi; j++, k++) {
                    stmr.addData(j, val++);
                    addedCnt.increment();
                    if (k % REPORT_DELTA == 0)
                        println(addedCnt.sum() + " entries");
                }
                println("Thread finished. " + addedCnt.sum() + " entries.");
            }
        });
        threads.add(t);
        t.start();
    }
    for (Thread thread : threads) thread.join();
    println("All threads finished. " + addedCnt.sum() + " entries.");
    println("Streamer flush");
    stmr.flush();
    println("Streamer flushed");
    println("Calculating cache size");
    println("Cache size: " + cache.size());
    println("Calculating long cache size");
    println("Cache size long: " + cache.sizeLong());
    Thread.sleep(10000);
    println("Iterating started");
    long cnt = 0;
    for (Cache.Entry<Integer, Object> ignored : cache) {
        cnt++;
        if (cnt > 0 && cnt % REPORT_DELTA == 0)
            println("Iterated via " + cnt + " entries");
    }
    println("Iterated via " + cnt + " entries");
    cache.destroy();
    return true;
}
Also used : ArrayList(java.util.ArrayList) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) LongAdder8(org.jsr166.LongAdder8) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Example 15 with LongAdder8

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

the class GridIoManager method runIoTest.

/**
     * @param warmup Warmup duration in milliseconds.
     * @param duration Test duration in milliseconds.
     * @param threads Thread count.
     * @param latencyLimit Max latency in nanoseconds.
     * @param rangesCnt Ranges count in resulting histogram.
     * @param payLoadSize Payload size in bytes.
     * @param procFromNioThread {@code True} to process requests in NIO threads.
     * @param nodes Nodes participating in test.
     */
public void runIoTest(final long warmup, final long duration, final int threads, final long latencyLimit, final int rangesCnt, final int payLoadSize, final boolean procFromNioThread, final List<ClusterNode> nodes) {
    ExecutorService svc = Executors.newFixedThreadPool(threads + 1);
    final AtomicBoolean warmupFinished = new AtomicBoolean();
    final AtomicBoolean done = new AtomicBoolean();
    final CyclicBarrier bar = new CyclicBarrier(threads + 1);
    final LongAdder8 cnt = new LongAdder8();
    final long sleepDuration = 5000;
    final byte[] payLoad = new byte[payLoadSize];
    final Map<UUID, IoTestThreadLocalNodeResults>[] res = new Map[threads];
    boolean failed = true;
    try {
        svc.execute(new Runnable() {

            @Override
            public void run() {
                boolean failed = true;
                try {
                    bar.await();
                    long start = System.currentTimeMillis();
                    if (log.isInfoEnabled())
                        log.info("IO test started " + "[warmup=" + warmup + ", duration=" + duration + ", threads=" + threads + ", latencyLimit=" + latencyLimit + ", rangesCnt=" + rangesCnt + ", payLoadSize=" + payLoadSize + ", procFromNioThreads=" + procFromNioThread + ']');
                    for (; ; ) {
                        if (!warmupFinished.get() && System.currentTimeMillis() - start > warmup) {
                            if (log.isInfoEnabled())
                                log.info("IO test warmup finished.");
                            warmupFinished.set(true);
                            start = System.currentTimeMillis();
                        }
                        if (warmupFinished.get() && System.currentTimeMillis() - start > duration) {
                            if (log.isInfoEnabled())
                                log.info("IO test finished, will wait for all threads to finish.");
                            done.set(true);
                            bar.await();
                            failed = false;
                            break;
                        }
                        if (log.isInfoEnabled())
                            log.info("IO test [opsCnt/sec=" + (cnt.sumThenReset() * 1000 / sleepDuration) + ", warmup=" + !warmupFinished.get() + ", elapsed=" + (System.currentTimeMillis() - start) + ']');
                        Thread.sleep(sleepDuration);
                    }
                    // At this point all threads have finished the test and
                    // stored data to the resulting array of maps.
                    // Need to iterate it over and sum values for all threads.
                    printIoTestResults(res);
                } catch (InterruptedException | BrokenBarrierException e) {
                    U.error(log, "IO test failed.", e);
                } finally {
                    if (failed)
                        bar.reset();
                }
            }
        });
        for (int i = 0; i < threads; i++) {
            final int i0 = i;
            res[i] = U.newHashMap(nodes.size());
            svc.execute(new Runnable() {

                @Override
                public void run() {
                    boolean failed = true;
                    ThreadLocalRandom rnd = ThreadLocalRandom.current();
                    int size = nodes.size();
                    Map<UUID, IoTestThreadLocalNodeResults> res0 = res[i0];
                    try {
                        boolean warmupFinished0 = false;
                        bar.await();
                        for (; ; ) {
                            if (done.get())
                                break;
                            if (!warmupFinished0)
                                warmupFinished0 = warmupFinished.get();
                            ClusterNode node = nodes.get(rnd.nextInt(size));
                            List<IgniteIoTestMessage> msgs = sendIoTest(node, payLoad, procFromNioThread).get();
                            cnt.increment();
                            for (IgniteIoTestMessage msg : msgs) {
                                UUID nodeId = msg.senderNodeId();
                                assert nodeId != null;
                                IoTestThreadLocalNodeResults nodeRes = res0.get(nodeId);
                                if (nodeRes == null)
                                    res0.put(nodeId, nodeRes = new IoTestThreadLocalNodeResults(rangesCnt, latencyLimit));
                                nodeRes.onResult(msg);
                            }
                        }
                        bar.await();
                        failed = false;
                    } catch (Exception e) {
                        U.error(log, "IO test worker thread failed.", e);
                    } finally {
                        if (failed)
                            bar.reset();
                    }
                }
            });
        }
        failed = false;
    } finally {
        if (failed)
            U.shutdownNow(GridIoManager.class, svc, log);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) IgniteDeploymentCheckedException(org.apache.ignite.internal.IgniteDeploymentCheckedException) IgniteException(org.apache.ignite.IgniteException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) CyclicBarrier(java.util.concurrent.CyclicBarrier) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) ExecutorService(java.util.concurrent.ExecutorService) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) 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