Search in sources :

Example 1 with SnapTreeMap

use of org.apache.ignite.internal.util.snaptree.SnapTreeMap in project ignite by apache.

the class GridIndexFillTest method testSnaptreeParallelBuild.

public void testSnaptreeParallelBuild() throws Exception {
    final AtomicBoolean stop = new AtomicBoolean();
    IgniteInternalFuture<?> fut = multithreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            ThreadLocalRandom rnd = ThreadLocalRandom.current();
            while (!stop.get()) {
                int k = rnd.nextInt(100);
                long v = rnd.nextLong(10);
                if (rnd.nextBoolean())
                    put(k, v);
                else
                    remove(k);
            }
            return null;
        }
    }, 12, "put");
    Thread.sleep(500);
    Idx newIdx = new Idx(false);
    idxs.add(newIdx);
    SnapTreeMap<Integer, Long> snap = idxs.get(0).tree.clone();
    for (Map.Entry<Integer, Long> entry : snap.entrySet()) newIdx.addX(entry.getKey(), entry.getValue());
    newIdx.finish();
    stop.set(true);
    fut.get();
    assertEquals(idxs.get(0).tree, idxs.get(1).tree);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) SnapTreeMap(org.apache.ignite.internal.util.snaptree.SnapTreeMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 2 with SnapTreeMap

use of org.apache.ignite.internal.util.snaptree.SnapTreeMap in project ignite by apache.

the class GridTreeBenchmark method doTestMaps.

/**
 * @throws BrokenBarrierException If failed.
 * @throws InterruptedException If failed.
 */
private static void doTestMaps() throws BrokenBarrierException, InterruptedException {
    final UUID[] data = generate();
    @SuppressWarnings("unchecked") final Map<UUID, UUID>[] maps = new Map[4];
    for (int i = 0; i < maps.length; i++) maps[i] = new SnapTreeMap<>();
    final Thread[] ths = new Thread[THREADS];
    final CyclicBarrier barrier = new CyclicBarrier(THREADS + 1);
    final AtomicInteger cnt = new AtomicInteger();
    for (int i = 0; i < ths.length; i++) {
        ths[i] = new Thread(new Runnable() {

            @Override
            public void run() {
                int idx = cnt.getAndIncrement();
                int off = idx * ITERATIONS;
                Map<UUID, UUID> map = maps[idx % maps.length];
                try {
                    barrier.await();
                } catch (Exception e) {
                    throw new IllegalStateException(e);
                }
                for (int i = 0; i < ITERATIONS; i++) {
                    UUID id = data[off + i];
                    id = map.put(id, id);
                    assert id == null;
                }
            }
        });
        ths[i].start();
    }
    System.out.println("Sleep");
    Thread.sleep(10000);
    System.out.println("Go");
    barrier.await();
    long start = System.currentTimeMillis();
    for (Thread t : ths) t.join();
    long time = System.currentTimeMillis() - start;
    System.out.println(time);
}
Also used : SnapTreeMap(org.apache.ignite.internal.util.snaptree.SnapTreeMap) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) CyclicBarrier(java.util.concurrent.CyclicBarrier) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UUID(java.util.UUID) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) SnapTreeMap(org.apache.ignite.internal.util.snaptree.SnapTreeMap) Map(java.util.Map) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap)

Aggregations

Map (java.util.Map)2 SnapTreeMap (org.apache.ignite.internal.util.snaptree.SnapTreeMap)2 UUID (java.util.UUID)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentNavigableMap (java.util.concurrent.ConcurrentNavigableMap)1 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1