Search in sources :

Example 6 with LongAdder8

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

the class GridCacheBinaryObjectsAbstractMultiThreadedSelfTest method testGetPut.

/**
     * @throws Exception If failed.
     */
@SuppressWarnings("BusyWait")
public void testGetPut() throws Exception {
    final AtomicBoolean flag = new AtomicBoolean();
    final LongAdder8 cnt = new LongAdder8();
    IgniteInternalFuture<?> f = multithreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            int threadId = idxGen.getAndIncrement() % 2;
            ThreadLocalRandom rnd = ThreadLocalRandom.current();
            while (!flag.get()) {
                IgniteCache<Object, Object> c = jcache(rnd.nextInt(gridCount()));
                switch(threadId) {
                    case 0:
                        // Put/get/remove binary -> binary.
                        c.put(new TestObject(rnd.nextInt(10000)), new TestObject(rnd.nextInt(10000)));
                        IgniteCache<Object, Object> p2 = ((IgniteCacheProxy<Object, Object>) c).keepBinary();
                        BinaryObject v = (BinaryObject) p2.get(new TestObject(rnd.nextInt(10000)));
                        if (v != null)
                            v.deserialize();
                        c.remove(new TestObject(rnd.nextInt(10000)));
                        break;
                    case 1:
                        // Put/get int -> binary.
                        c.put(rnd.nextInt(10000), new TestObject(rnd.nextInt(10000)));
                        IgniteCache<Integer, BinaryObject> p4 = ((IgniteCacheProxy<Object, Object>) c).keepBinary();
                        BinaryObject v1 = p4.get(rnd.nextInt(10000));
                        if (v1 != null)
                            v1.deserialize();
                        p4.remove(rnd.nextInt(10000));
                        break;
                    default:
                        assert false;
                }
                cnt.add(3);
            }
            return null;
        }
    }, THREAD_CNT);
    for (int i = 0; i < 30 && !f.isDone(); i++) Thread.sleep(1000);
    flag.set(true);
    f.get();
    info("Operations in 30 sec: " + cnt.sum());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BinaryObject(org.apache.ignite.binary.BinaryObject) IgniteCache(org.apache.ignite.IgniteCache) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) BinaryObject(org.apache.ignite.binary.BinaryObject) LongAdder8(org.jsr166.LongAdder8) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 7 with LongAdder8

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

the class SortedEvictionPolicyPerformanceTest method testThroughput.

/**
     * Tests throughput.
     */
public void testThroughput() throws Exception {
    final LongAdder8 cnt = new LongAdder8();
    final AtomicBoolean finished = new AtomicBoolean();
    final int pPut = P_PUT;
    final int pGet = P_PUT + P_GET;
    final IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
    multithreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            for (; ; ) {
                U.sleep(1000);
                info("Ops/sec: " + cnt.sumThenReset());
            }
        }
    }, 1);
    multithreaded(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            while (!finished.get()) {
                int p = RND.nextInt(100);
                int key = RND.nextInt(KEYS);
                if (p >= 0 && p < pPut)
                    cache.put(key, 0);
                else if (p >= pPut && p < pGet)
                    cache.get(key);
                else
                    cache.remove(key);
                cnt.increment();
            }
            return null;
        }
    }, THREADS);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LongAdder8(org.jsr166.LongAdder8)

Example 8 with LongAdder8

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

the class GridJobExecutionSingleNodeSemaphoreLoadTest method main.

/**
     * @param args Command line arguments:
     *             1-st: Number of worker threads. Default equals to available CPU number / 2.
     *             2-nd: Concurrent tasks count. Default: 1024.
     *             3-rd: Test duration in seconds. 0 means infinite. Default: 0.
     *             4-th: File to output test results to.
     * @throws Exception If failed.
     */
public static void main(String[] args) throws Exception {
    GridFileLock fileLock = GridLoadTestUtils.fileLock();
    fileLock.lock();
    try {
        // Command line arguments.
        //
        // NOTE: on MacOS better numbers are shown if public pool core and max sizes are
        // equal to CPU count. And producer threads count is equal to CPU count.
        //
        int threadCnt = args.length > 0 ? Integer.parseInt(args[0]) : Runtime.getRuntime().availableProcessors() / 2;
        int taskCnt = args.length > 1 ? Integer.parseInt(args[1]) : 1024;
        final int duration = args.length > 2 ? Integer.parseInt(args[2]) : 0;
        final String outputFileName = args.length > 3 ? args[3] : null;
        final LongAdder8 execCnt = new LongAdder8();
        try {
            final Ignite g = G.start("modules/tests/config/grid-job-load.xml");
            X.println("Thread count: " + threadCnt);
            X.println("Task count: " + taskCnt);
            X.println("Duration: " + duration);
            X.println("Warming up...");
            g.compute().execute(GridJobExecutionLoadTestTask.class, null);
            g.compute().execute(GridJobExecutionLoadTestTask.class, null);
            runTest(g, threadCnt, taskCnt, WARM_UP_DURATION, execCnt);
            System.gc();
            execCnt.reset();
            X.println("Running main test.");
            IgniteInternalFuture<Void> collectorFut = GridTestUtils.runAsync(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    GridCumulativeAverage avgTasksPerSec = new GridCumulativeAverage();
                    try {
                        while (!Thread.currentThread().isInterrupted()) {
                            U.sleep(UPDATE_INTERVAL_SEC * 1000);
                            long curTasksPerSec = execCnt.sumThenReset() / UPDATE_INTERVAL_SEC;
                            X.println(">>> Tasks/s: " + curTasksPerSec);
                            avgTasksPerSec.update(curTasksPerSec);
                        }
                    } catch (IgniteInterruptedCheckedException ignored) {
                        X.println(">>> Interrupted.");
                        Thread.currentThread().interrupt();
                    }
                    X.println(">>> Average tasks/s: " + avgTasksPerSec);
                    if (outputFileName != null) {
                        X.println("Writing test results to a file: " + outputFileName);
                        try {
                            GridLoadTestUtils.appendLineToFile(outputFileName, "%s,%d", GridLoadTestUtils.DATE_TIME_FORMAT.format(new Date()), avgTasksPerSec.get());
                        } catch (IOException e) {
                            X.error("Failed to output to a file", e);
                        }
                    }
                    return null;
                }
            });
            runTest(g, threadCnt, taskCnt, duration * 1000, execCnt);
            X.println("All done, stopping.");
            collectorFut.cancel();
        } finally {
            G.stopAll(true);
        }
    } finally {
        fileLock.close();
    }
}
Also used : IOException(java.io.IOException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IOException(java.io.IOException) Date(java.util.Date) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridCumulativeAverage(org.apache.ignite.loadtests.util.GridCumulativeAverage) Ignite(org.apache.ignite.Ignite) GridFileLock(org.apache.ignite.testframework.GridFileLock) LongAdder8(org.jsr166.LongAdder8)

Example 9 with LongAdder8

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

the class GridBoundedConcurrentLinkedHashSetLoadTest method main.

/**
     * @param args Arguments.
     */
public static void main(String[] args) throws Exception {
    QueuePolicy qPlc = args.length > 0 ? QueuePolicy.valueOf(args[0]) : SINGLE_Q;
    int threadCnt = args.length > 1 ? Integer.valueOf(args[1]) : Runtime.getRuntime().availableProcessors();
    X.println("Queue policy: " + qPlc);
    X.println("Threads: " + threadCnt);
    ExecutorService pool = Executors.newFixedThreadPool(threadCnt);
    final Collection<IgniteUuid> set = new GridBoundedConcurrentLinkedHashSet<>(10240, 32, 0.75f, 128, qPlc);
    X.println("Set: " + set);
    final LongAdder8 execCnt = new LongAdder8();
    final AtomicBoolean finish = new AtomicBoolean();
    // Thread that measures and outputs performance statistics.
    Thread collector = new Thread(new Runnable() {

        @SuppressWarnings({ "BusyWait", "InfiniteLoopStatement" })
        @Override
        public void run() {
            GridCumulativeAverage avgTasksPerSec = new GridCumulativeAverage();
            try {
                while (!finish.get()) {
                    Thread.sleep(UPDATE_INTERVAL_SEC * 1000);
                    long curTasksPerSec = execCnt.sumThenReset() / UPDATE_INTERVAL_SEC;
                    X.println(">>> Tasks/s: " + curTasksPerSec);
                    avgTasksPerSec.update(curTasksPerSec);
                }
            } catch (InterruptedException ignored) {
                X.println(">>> Interrupted.");
                Thread.currentThread().interrupt();
            }
        }
    });
    collector.start();
    Collection<Callable<Object>> producers = new ArrayList<>(threadCnt);
    for (int i = 0; i < threadCnt; i++) producers.add(new Callable<Object>() {

        @SuppressWarnings({ "unchecked", "InfiniteLoopStatement" })
        @Override
        public Object call() throws Exception {
            UUID id = UUID.randomUUID();
            try {
                while (!finish.get()) {
                    set.add(IgniteUuid.fromUuid(id));
                    execCnt.increment();
                }
                return null;
            } catch (Throwable t) {
                t.printStackTrace();
                throw new Exception(t);
            } finally {
                X.println("Thread finished.");
            }
        }
    });
    pool.invokeAll(producers);
}
Also used : ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) GridBoundedConcurrentLinkedHashSet(org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashSet) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteUuid(org.apache.ignite.lang.IgniteUuid) GridCumulativeAverage(org.apache.ignite.loadtests.util.GridCumulativeAverage) ExecutorService(java.util.concurrent.ExecutorService) UUID(java.util.UUID) QueuePolicy(org.jsr166.ConcurrentLinkedHashMap.QueuePolicy) LongAdder8(org.jsr166.LongAdder8)

Example 10 with LongAdder8

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

the class GridIoManagerBenchmark0 method testLatency.

/**
     * @throws Exception If failed.
     */
@SuppressWarnings("deprecation")
public void testLatency() throws Exception {
    final IgniteKernal sndKernal = (IgniteKernal) grid(0);
    final IgniteKernal rcvKernal = (IgniteKernal) grid(1);
    final ClusterNode sndNode = sndKernal.localNode();
    final ClusterNode rcvNode = rcvKernal.localNode();
    final GridIoManager snd = sndKernal.context().io();
    final GridIoManager rcv = rcvKernal.context().io();
    final LongAdder8 msgCntr = new LongAdder8();
    final Integer topic = 1;
    final Map<IgniteUuid, CountDownLatch> map = new ConcurrentHashMap8<>();
    rcv.addMessageListener(topic, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg) {
            try {
                rcv.sendToCustomTopic(sndNode, topic, (Message) msg, PUBLIC_POOL);
            } catch (IgniteCheckedException e) {
                error("Failed to send message.", e);
            }
        }
    });
    snd.addMessageListener(topic, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg) {
            map.get(((GridTestMessage) msg).id()).countDown();
        }
    });
    Timer t = new Timer("results-reporter");
    t.schedule(new TimerTask() {

        private long ts = System.currentTimeMillis();

        @Override
        public void run() {
            long newTs = System.currentTimeMillis();
            long qrys = msgCntr.sumThenReset();
            long time = newTs - ts;
            X.println("Communication benchmark [qps=" + qrys * 1000 / time + ", executed=" + qrys + ", time=" + time + ']');
            ts = newTs;
        }
    }, 10000, 10000);
    final AtomicBoolean finish = new AtomicBoolean();
    IgniteInternalFuture<?> f = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            try {
                IgniteUuid msgId = IgniteUuid.randomUuid();
                while (!finish.get()) {
                    CountDownLatch latch = new CountDownLatch(1);
                    map.put(msgId, latch);
                    snd.sendToCustomTopic(rcvNode, topic, new GridTestMessage(msgId, (String) null), PUBLIC_POOL);
                    latch.await();
                    msgCntr.increment();
                }
            } catch (IgniteCheckedException e) {
                X.println("Message send failed", e);
            } catch (InterruptedException ignored) {
            // No-op.
            }
            return null;
        }
    }, 1, "send-thread");
    Thread.sleep(TEST_TIMEOUT);
    finish.set(true);
    t.cancel();
    f.get();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) Message(org.apache.ignite.plugin.extensions.communication.Message) ConcurrentHashMap8(org.jsr166.ConcurrentHashMap8) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Timer(java.util.Timer) TimerTask(java.util.TimerTask) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager) IgniteUuid(org.apache.ignite.lang.IgniteUuid) UUID(java.util.UUID) 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