Search in sources :

Example 1 with ThreadLocalRandom8

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

the class IgniteCache150ClientsTest method test150Clients.

/**
     * @throws Exception If failed.
     */
public void test150Clients() throws Exception {
    Ignite srv = startGrid(0);
    assertFalse(srv.configuration().isClientMode());
    final int CLIENTS = 150;
    final AtomicInteger idx = new AtomicInteger(1);
    final CountDownLatch latch = new CountDownLatch(CLIENTS);
    final List<String> cacheNames = new ArrayList<>();
    for (int i = 0; i < CACHES; i++) cacheNames.add("cache-" + i);
    IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            boolean cnt = false;
            try {
                Ignite ignite = startGrid(idx.getAndIncrement());
                assertTrue(ignite.configuration().isClientMode());
                assertTrue(ignite.cluster().localNode().isClient());
                latch.countDown();
                cnt = true;
                log.info("Started [node=" + ignite.name() + ", left=" + latch.getCount() + ']');
                ThreadLocalRandom8 rnd = ThreadLocalRandom8.current();
                while (latch.getCount() > 0) {
                    Thread.sleep(1000);
                    IgniteCache<Object, Object> cache = ignite.cache(cacheNames.get(rnd.nextInt(0, CACHES)));
                    Integer key = rnd.nextInt(0, 100_000);
                    cache.put(key, 0);
                    assertNotNull(cache.get(key));
                }
                return null;
            } finally {
                if (!cnt)
                    latch.countDown();
            }
        }
    }, CLIENTS, "start-client");
    fut.get();
    log.info("Started all clients.");
    checkNodes(CLIENTS + 1);
}
Also used : ArrayList(java.util.ArrayList) IgniteCache(org.apache.ignite.IgniteCache) CountDownLatch(java.util.concurrent.CountDownLatch) ThreadLocalRandom8(org.jsr166.ThreadLocalRandom8) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Ignite(org.apache.ignite.Ignite)

Example 2 with ThreadLocalRandom8

use of org.jsr166.ThreadLocalRandom8 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 3 with ThreadLocalRandom8

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

the class IgfsSizeSelfTest method write.

/**
     * Perform write of the files.
     *
     * @return Collection of written file descriptors.
     * @throws Exception If failed.
     */
private Collection<IgfsFile> write() throws Exception {
    Collection<IgfsFile> res = new HashSet<>(FILES_CNT, 1.0f);
    ThreadLocalRandom8 rand = ThreadLocalRandom8.current();
    for (int i = 0; i < FILES_CNT; i++) {
        // Create empty file locally.
        IgfsPath path = new IgfsPath("/file-" + i);
        igfs(0).create(path, false).close();
        IgfsMetaManager meta = igfs(0).context().meta();
        IgniteUuid fileId = meta.fileId(path);
        // Calculate file blocks.
        int fileSize = rand.nextInt(MAX_FILE_SIZE);
        int fullBlocks = fileSize / BLOCK_SIZE;
        int remainderSize = fileSize % BLOCK_SIZE;
        Collection<IgfsBlock> blocks = new ArrayList<>(fullBlocks + remainderSize > 0 ? 1 : 0);
        for (int j = 0; j < fullBlocks; j++) blocks.add(new IgfsBlock(new IgfsBlockKey(fileId, null, true, j), BLOCK_SIZE));
        if (remainderSize > 0)
            blocks.add(new IgfsBlock(new IgfsBlockKey(fileId, null, true, fullBlocks), remainderSize));
        IgfsFile file = new IgfsFile(path, fileSize, blocks);
        // Actual write.
        for (IgfsBlock block : blocks) {
            IgfsOutputStream os = igfs(0).append(path, false);
            os.write(chunk(block.length()));
            os.close();
        }
        // Add written file to the result set.
        res.add(file);
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream) ThreadLocalRandom8(org.jsr166.ThreadLocalRandom8) IgfsPath(org.apache.ignite.igfs.IgfsPath) IgniteUuid(org.apache.ignite.lang.IgniteUuid) HashSet(java.util.HashSet)

Example 4 with ThreadLocalRandom8

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

the class GridContinuousOperationsLoadTest method main.

/**
     * Main method.
     *
     * @param args Command line arguments.
     * @throws Exception If error occurs.
     */
public static void main(String[] args) throws Exception {
    final String cfgPath = args.length > 0 ? args[0] : "examples/config/example-cache.xml";
    final String cacheName = getStringProperty(CACHE_NAME, "partitioned");
    final Integer valSize = getIntProperty(VALUE_SIZE, 1024);
    final Integer threadsCnt = getIntProperty(THREADS_CNT, 8);
    final Integer testDurSec = getIntProperty(TEST_DUR_SEC, 180);
    final Integer filterSkipProb = getIntProperty("FILTER_SKIP_PROBABILITY", 10, new C1<Integer, String>() {

        @Nullable
        @Override
        public String apply(Integer val) {
            if (val < 0 || val > 100)
                return "The value should be between 1 and 100.";
            return null;
        }
    });
    final boolean useQry = getBooleanProperty("IGNITE_USE_QUERIES", true);
    final int bufSize = getIntProperty("IGNITE_BUFFER_SIZE", 1);
    final long timeInterval = getLongProperty("IGNITE_TIME_INTERVAL", 0);
    final int parallelCnt = getIntProperty("IGNITE_PARALLEL_COUNT", 8);
    final int keyRange = getIntProperty("IGNITE_KEY_RANGE", 100000);
    final long updSleepMs = getLongProperty("IGNITE_UPDATE_SLEEP_MS", 0);
    final long filterSleepMs = getLongProperty("IGNITE_FILTER_SLEEP_MS", 0);
    final long cbSleepMs = getLongProperty("IGNITE_CALLBACK_SLEEP_MS", 0);
    X.println("The test will start with the following parameters:");
    dumpProperties(System.out);
    try (Ignite ignite = Ignition.start(cfgPath)) {
        final IgniteCache<Object, Object> cache = ignite.cache(cacheName);
        if (cache == null)
            throw new IgniteCheckedException("Cache is not configured: " + cacheName);
        // Continuous query manager, used to monitor queue size.
        final CacheContinuousQueryManager contQryMgr = ((IgniteKernal) ignite).context().cache().cache(cacheName).context().continuousQueries();
        if (contQryMgr == null)
            throw new IgniteCheckedException("Could not access CacheContinuousQueryManager");
        // Stop flag.
        final AtomicBoolean stop = new AtomicBoolean();
        // Callback counter.
        final AtomicLong cbCntr = new AtomicLong();
        // Update counter.
        final AtomicLong updCntr = new AtomicLong();
        for (int i = 0; i < parallelCnt; i++) {
            if (useQry) {
                ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
                qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {

                    @Override
                    public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
                        if (cbSleepMs > 0) {
                            try {
                                U.sleep(cbSleepMs);
                            } catch (IgniteInterruptedCheckedException e) {
                                throw new IgniteException(e);
                            }
                        }
                        for (CacheEntryEvent<?, ?> ignored : evts) cbCntr.incrementAndGet();
                    }
                });
                qry.setRemoteFilter(new CacheEntryEventSerializableFilter<Object, Object>() {

                    @Override
                    public boolean evaluate(CacheEntryEvent<?, ?> evt) {
                        if (filterSleepMs > 0) {
                            try {
                                U.sleep(filterSleepMs);
                            } catch (IgniteInterruptedCheckedException e) {
                                throw new IgniteException(e);
                            }
                        }
                        return Math.random() * 100 >= filterSkipProb;
                    }
                });
                qry.setPageSize(bufSize);
                qry.setTimeInterval(timeInterval);
                cache.query(qry);
            } else {
                ignite.events().remoteListen(bufSize, timeInterval, true, new PX2<UUID, Event>() {

                    @Override
                    public boolean applyx(UUID uuid, Event evt) throws IgniteInterruptedCheckedException {
                        if (cbSleepMs > 0)
                            U.sleep(cbSleepMs);
                        cbCntr.incrementAndGet();
                        // Continue listening.
                        return true;
                    }
                }, new PX1<Event>() {

                    @Override
                    public boolean applyx(Event evt) throws IgniteInterruptedCheckedException {
                        if (filterSleepMs > 0)
                            U.sleep(filterSleepMs);
                        return Math.random() * 100 >= filterSkipProb;
                    }
                }, EVT_CACHE_OBJECT_PUT);
            }
        }
        // Start collector thread.
        startDaemon(new Runnable() {

            @Override
            public void run() {
                try {
                    while (!stop.get() && !Thread.currentThread().isInterrupted()) {
                        long cbCntr0 = cbCntr.get();
                        long updCntr0 = updCntr.get();
                        U.sleep(1000);
                        long cbDelta = cbCntr.get() - cbCntr0;
                        long updDelta = updCntr.get() - updCntr0;
                        X.println("Stats [entriesPerSec=" + cbDelta + ", updatesPerSec=" + updDelta + ']');
                    }
                } catch (IgniteInterruptedCheckedException ignored) {
                // No-op.
                }
            }
        });
        X.println("Starting " + threadsCnt + " generator thread(s).");
        // Start generator threads.
        IgniteInternalFuture<Long> genFut = runMultiThreadedAsync(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                byte[] val = new byte[valSize];
                ThreadLocalRandom8 rnd = ThreadLocalRandom8.current();
                while (!stop.get() && !Thread.currentThread().isInterrupted()) {
                    Integer key = rnd.nextInt(keyRange);
                    cache.put(key, val);
                    updCntr.incrementAndGet();
                    if (updSleepMs > 0)
                        U.sleep(updSleepMs);
                }
                return true;
            }
        }, threadsCnt, "load-test-generator");
        U.sleep(testDurSec * 1000);
        stop.set(true);
        genFut.get();
    }
}
Also used : CacheEntryEvent(javax.cache.event.CacheEntryEvent) CacheContinuousQueryManager(org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryManager) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteException(org.apache.ignite.IgniteException) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ThreadLocalRandom8(org.jsr166.ThreadLocalRandom8) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) Event(org.apache.ignite.events.Event) CacheEntryEvent(javax.cache.event.CacheEntryEvent) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ThreadLocalRandom8 (org.jsr166.ThreadLocalRandom8)4 Ignite (org.apache.ignite.Ignite)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 CacheEntryEvent (javax.cache.event.CacheEntryEvent)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)1 Event (org.apache.ignite.events.Event)1 IgfsOutputStream (org.apache.ignite.igfs.IgfsOutputStream)1 IgfsPath (org.apache.ignite.igfs.IgfsPath)1 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)1 IgniteKernal (org.apache.ignite.internal.IgniteKernal)1 CacheContinuousQueryManager (org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryManager)1