Search in sources :

Example 1 with ConcurrentLinkedDeque8

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

the class MemoryEventStorageSpi method cleanupQueue.

/**
     * Method cleans up all events that either outnumber queue size
     * or exceeds time-to-live value. It does none if someone else
     * cleans up queue (lock is locked) or if there are queue readers
     * (readersNum > 0).
     */
private void cleanupQueue() {
    long now = U.currentTimeMillis();
    long queueOversize = evts.sizex() - expireCnt;
    for (int i = 0; i < queueOversize && evts.sizex() > expireCnt; i++) {
        Event expired = evts.poll();
        if (log.isDebugEnabled())
            log.debug("Event expired by count: " + expired);
    }
    while (true) {
        ConcurrentLinkedDeque8.Node<Event> node = evts.peekx();
        if (// Queue is empty.
        node == null)
            break;
        Event evt = node.item();
        if (// Competing with another thread.
        evt == null)
            continue;
        if (now - evt.timestamp() < expireAgeMs)
            break;
        if (evts.unlinkx(node) && log.isDebugEnabled())
            log.debug("Event expired by age: " + node.item());
    }
}
Also used : ConcurrentLinkedDeque8(org.jsr166.ConcurrentLinkedDeque8) Event(org.apache.ignite.events.Event)

Example 2 with ConcurrentLinkedDeque8

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

the class GridConcurrentLinkedDequeMultiThreadedTest method testQueueMultiThreaded.

/**
     * @throws Exception If failed.
     */
@SuppressWarnings({ "BusyWait" })
public void testQueueMultiThreaded() throws Exception {
    final AtomicBoolean done = new AtomicBoolean();
    final ConcurrentLinkedDeque8<Byte> queue = new ConcurrentLinkedDeque8<>();
    // Poll thread.
    IgniteInternalFuture<?> pollFut = multithreadedAsync(new Callable<Object>() {

        @Nullable
        @Override
        public Object call() throws Exception {
            info("Thread started.");
            while (!done.get()) try {
                queue.poll();
            } catch (Throwable t) {
                error("Error in poll thread.", t);
                done.set(true);
            }
            info("Thread finished.");
            return null;
        }
    }, 5, "queue-poll");
    // Producer thread.
    IgniteInternalFuture<?> prodFut = multithreadedAsync(new Callable<Object>() {

        @Nullable
        @Override
        public Object call() throws Exception {
            info("Thread started.");
            while (!done.get()) {
                Node<Byte> n = queue.addx((byte) 1);
                if (RND.nextBoolean())
                    queue.unlinkx(n);
            }
            info("Thread finished.");
            return null;
        }
    }, 5, "queue-prod");
    Thread.sleep(2 * 60 * 1000);
    done.set(true);
    pollFut.get();
    prodFut.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConcurrentLinkedDeque8(org.jsr166.ConcurrentLinkedDeque8) Node(org.jsr166.ConcurrentLinkedDeque8.Node) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ConcurrentLinkedDeque8

use of org.jsr166.ConcurrentLinkedDeque8 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)

Example 4 with ConcurrentLinkedDeque8

use of org.jsr166.ConcurrentLinkedDeque8 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 5 with ConcurrentLinkedDeque8

use of org.jsr166.ConcurrentLinkedDeque8 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)

Aggregations

ConcurrentLinkedDeque8 (org.jsr166.ConcurrentLinkedDeque8)9 Random (java.util.Random)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 LongAdder8 (org.jsr166.LongAdder8)3 Date (java.util.Date)2 UUID (java.util.UUID)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ExecutorService (java.util.concurrent.ExecutorService)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Event (org.apache.ignite.events.Event)2 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IgniteException (org.apache.ignite.IgniteException)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1