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);
}
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);
}
Aggregations