use of org.apache.ignite.internal.util.offheap.GridByteArrayWrapper in project ignite by apache.
the class GridOffHeapPartitionedMapPerformanceAbstractTest method beforeTest.
/**
* {@inheritDoc}
*/
@Override
protected void beforeTest() throws Exception {
map = newMap();
if (keys == null) {
keys = new T3[LOAD_CNT];
wrappers = new GridByteArrayWrapper[LOAD_CNT];
AffinityFunction aff = new RendezvousAffinityFunction();
Random rnd = new Random();
for (int i = 0; i < LOAD_CNT; i++) {
byte[] key = new byte[rnd.nextInt(511) + 1];
rnd.nextBytes(key);
GridByteArrayWrapper wrap = new GridByteArrayWrapper(key);
keys[i] = new T3<>(aff.partition(wrap), wrap.hashCode(), key);
wrappers[i] = wrap;
}
}
}
use of org.apache.ignite.internal.util.offheap.GridByteArrayWrapper in project ignite by apache.
the class GridOffHeapPartitionedMapPerformanceAbstractTest method checkPutRemovesConcurrentMap.
/**
* @throws Exception If failed.
*/
private void checkPutRemovesConcurrentMap(int threadCnt, long duration) throws Exception {
final Map<GridByteArrayWrapper, byte[]> map = new ConcurrentHashMap<>();
final AtomicLong opCnt = new AtomicLong();
final AtomicLong totalOpCnt = new AtomicLong();
final AtomicBoolean done = new AtomicBoolean();
long start = System.currentTimeMillis();
IgniteInternalFuture<?> fut = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
Random rnd = new Random();
byte[] val = new byte[1024];
long locTotalOpCnt = 0;
while (!done.get()) {
for (int i = 0; i < 500; i++) {
GridByteArrayWrapper key = randomKeyWrapper(rnd);
int op = rnd.nextInt(2);
switch(op) {
case 0:
map.put(key, val);
break;
case 1:
map.remove(key);
break;
default:
assert false;
}
}
locTotalOpCnt += 500;
opCnt.addAndGet(500);
}
totalOpCnt.addAndGet(locTotalOpCnt);
return null;
}
}, threadCnt);
final int step = 2000;
while (System.currentTimeMillis() - start < duration) {
U.sleep(step);
long ops = opCnt.getAndSet(0);
info("Putting " + (ops * 1000) / step + " ops/sec");
}
done.set(true);
fut.get();
long end = System.currentTimeMillis();
info("Average random operation performance: " + (totalOpCnt.get() * 1000) / (end - start) + " ops/sec");
}
use of org.apache.ignite.internal.util.offheap.GridByteArrayWrapper in project ignite by apache.
the class GridOffHeapPartitionedMapPerformanceAbstractTest method checkPutsConcurrentMap.
/**
* @throws Exception If failed.
*/
private void checkPutsConcurrentMap(int threadCnt, long duration) throws Exception {
final Map<GridByteArrayWrapper, byte[]> map = new ConcurrentHashMap<>();
final AtomicLong opCnt = new AtomicLong();
final AtomicLong totalOpCnt = new AtomicLong();
final AtomicBoolean done = new AtomicBoolean();
long start = System.currentTimeMillis();
IgniteInternalFuture<?> fut = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
Random rnd = new Random();
long locTotalOpCnt = 0;
while (!done.get()) {
for (int i = 0; i < 500; i++) {
GridByteArrayWrapper key = randomKeyWrapper(rnd);
map.put(key, new byte[1024]);
}
locTotalOpCnt += 500;
opCnt.addAndGet(500);
}
totalOpCnt.addAndGet(locTotalOpCnt);
return null;
}
}, threadCnt);
final int step = 2000;
while (System.currentTimeMillis() - start < duration) {
U.sleep(step);
long ops = opCnt.getAndSet(0);
info("Putting " + (ops * 1000) / step + " ops/sec");
}
done.set(true);
fut.get();
long end = System.currentTimeMillis();
info("Average put performance: " + (totalOpCnt.get() * 1000) / (end - start) + " ops/sec");
}
Aggregations