Search in sources :

Example 1 with GridByteArrayWrapper

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;
        }
    }
}
Also used : GridByteArrayWrapper(org.apache.ignite.internal.util.offheap.GridByteArrayWrapper) Random(java.util.Random) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction)

Example 2 with GridByteArrayWrapper

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");
}
Also used : GridByteArrayWrapper(org.apache.ignite.internal.util.offheap.GridByteArrayWrapper) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) Random(java.util.Random) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 3 with GridByteArrayWrapper

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");
}
Also used : GridByteArrayWrapper(org.apache.ignite.internal.util.offheap.GridByteArrayWrapper) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) Random(java.util.Random) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

Random (java.util.Random)3 GridByteArrayWrapper (org.apache.ignite.internal.util.offheap.GridByteArrayWrapper)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 AffinityFunction (org.apache.ignite.cache.affinity.AffinityFunction)1 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)1