Search in sources :

Example 61 with ThreadLocalRandom

use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.

the class IgniteReplaceIndexedValue1Benchmark method test.

/**
 * {@inheritDoc}
 */
@Override
public boolean test(Map<Object, Object> ctx) throws Exception {
    ThreadLocalRandom rnd = ThreadLocalRandom.current();
    IgniteCache<Integer, Object> cache = cacheForOperation();
    cache.replace(rnd.nextInt(args.range()), new Person1(rnd.nextInt(args.range())));
    return true;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Person1(org.apache.ignite.yardstick.cache.model.Person1) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom)

Example 62 with ThreadLocalRandom

use of java.util.concurrent.ThreadLocalRandom 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 LongAdder addedCnt = new LongAdder();
    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) LongAdder(java.util.concurrent.atomic.LongAdder) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Example 63 with ThreadLocalRandom

use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.

the class IgniteSqlMergeQueryBenchmark method test.

/**
 * {@inheritDoc}
 */
@Override
public boolean test(Map<Object, Object> ctx) throws Exception {
    ThreadLocalRandom rnd = ThreadLocalRandom.current();
    if (rnd.nextBoolean()) {
        double salary = rnd.nextDouble() * args.range() * 1000;
        double maxSalary = salary + 1000;
        Collection<Cache.Entry<Integer, Object>> entries = executeQuery(salary, maxSalary);
        for (Cache.Entry<Integer, Object> entry : entries) {
            Object o = entry.getValue();
            double s = o instanceof Person ? ((Person) o).getSalary() : ((BinaryObject) o).<Double>field("salary");
            if (s < salary || s > maxSalary)
                throw new Exception("Invalid person retrieved [min=" + salary + ", max=" + maxSalary + ", person=" + o + ']');
        }
        qryCnt.getAndIncrement();
    } else {
        int i = rnd.nextInt(args.range());
        cache.query(new SqlFieldsQuery("merge into Person(_key, id, firstName, lastName, salary) " + "values (?, ?, ?, ?, ?)").setArgs(i, i, "firstName" + i, "lastName" + i, (double) i * 1000));
        putCnt.getAndIncrement();
    }
    return true;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) BinaryObject(org.apache.ignite.binary.BinaryObject) Person(org.apache.ignite.yardstick.cache.model.Person) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) IgniteCache(org.apache.ignite.IgniteCache) Cache(javax.cache.Cache)

Example 64 with ThreadLocalRandom

use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.

the class QueryFactory method randomCsvLine.

/**
 * Generates CSV line containing specified id and random values.
 * This line corresponds 1 row of the test table,
 * which will be inserted in the end.
 *
 * @param id key in the test table.
 * @return generated comma-separated line.
 */
public String randomCsvLine(long id) {
    ThreadLocalRandom rnd = ThreadLocalRandom.current();
    StringBuilder line = new StringBuilder().append(id);
    for (int vi = 1; vi <= valFieldsCnt; vi++) {
        line.append(',');
        if (vi % 2 == 1)
            line.append(rnd.nextLong());
        else
            line.append('"').append(rnd.nextLong()).append('"');
    }
    return line.toString();
}
Also used : ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom)

Example 65 with ThreadLocalRandom

use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.

the class InlineIndexHelperTest method testCompareMixed2.

/**
 */
public void testCompareMixed2() throws Exception {
    int strCnt = 1000;
    int symbCnt = 20;
    int inlineSize = symbCnt * 4 + 3;
    ThreadLocalRandom rnd = ThreadLocalRandom.current();
    String[] strings = new String[strCnt];
    for (int i = 0; i < strings.length; i++) strings[i] = randomString(symbCnt);
    Arrays.sort(strings);
    for (int i = 0; i < 100; i++) {
        int i1 = rnd.nextInt(strings.length);
        int i2 = rnd.nextInt(strings.length);
        assertEquals(Integer.compare(i1, i2), putAndCompare(strings[i1], strings[i2], inlineSize));
    }
}
Also used : ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ValueString(org.h2.value.ValueString)

Aggregations

ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)236 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)73 Ignite (org.apache.ignite.Ignite)65 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)53 IgniteCache (org.apache.ignite.IgniteCache)44 ArrayList (java.util.ArrayList)34 Test (org.junit.Test)30 IgniteException (org.apache.ignite.IgniteException)27 Transaction (org.apache.ignite.transactions.Transaction)26 CacheException (javax.cache.CacheException)24 HashMap (java.util.HashMap)22 Map (java.util.Map)20 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)17 LongAdder (java.util.concurrent.atomic.LongAdder)15 TreeMap (java.util.TreeMap)14 IgniteTransactions (org.apache.ignite.IgniteTransactions)13 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)13 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)12 Callable (java.util.concurrent.Callable)11 CountDownLatch (java.util.concurrent.CountDownLatch)11