Search in sources :

Example 1 with Pointer

use of org.directmemory.memory.Pointer in project DirectMemory by raffaeleguidi.

the class CacheConcurrentTests method get.

private void get(String key) {
    Pointer p = Cache.getPointer(key);
    @SuppressWarnings("unused") byte[] check = Cache.retrieveByteArray(key);
    read.incrementAndGet();
    if (p != null) {
        got.incrementAndGet();
        byte[] payload = MemoryManager.retrieve(p);
        if ((new String(payload)).startsWith(key))
            good.incrementAndGet();
        else
            bad.incrementAndGet();
    } else {
        missed.incrementAndGet();
    }
}
Also used : Pointer(org.directmemory.memory.Pointer)

Example 2 with Pointer

use of org.directmemory.memory.Pointer in project DirectMemory by raffaeleguidi.

the class CacheLightConcurrentTest method getAndRetrieve.

private void getAndRetrieve(String key) {
    Pointer p = Cache.getPointer(key);
    @SuppressWarnings("unused") byte[] check = Cache.retrieveByteArray(key);
    read.incrementAndGet();
    if (p != null) {
        got.incrementAndGet();
        byte[] payload = MemoryManager.retrieve(p);
        if ((new String(payload)).startsWith(key))
            good.incrementAndGet();
        else
            bad.incrementAndGet();
    } else {
        missed.incrementAndGet();
    }
}
Also used : Pointer(org.directmemory.memory.Pointer)

Example 3 with Pointer

use of org.directmemory.memory.Pointer in project DirectMemory by raffaeleguidi.

the class ConcurrentTests method retrieveCatchThemAll.

@BenchmarkOptions(benchmarkRounds = 1000000, warmupRounds = 0, concurrency = 100)
@Test
public void retrieveCatchThemAll() {
    String key = "test-" + (rndGen.nextInt(entries) + 1);
    Pointer p = map.get(key);
    read.incrementAndGet();
    if (p != null) {
        got.incrementAndGet();
        byte[] payload = mem.retrieve(p);
        if (key.equals(new String(payload)))
            good.incrementAndGet();
        else
            bad.incrementAndGet();
    } else {
        logger.info("did not find key " + key);
        missed.incrementAndGet();
    }
}
Also used : Pointer(org.directmemory.memory.Pointer) Test(org.junit.Test) BenchmarkOptions(com.carrotsearch.junitbenchmarks.BenchmarkOptions)

Example 4 with Pointer

use of org.directmemory.memory.Pointer in project DirectMemory by raffaeleguidi.

the class Cache method updateByteArray.

public static Pointer updateByteArray(String key, byte[] payload) {
    Pointer p = map.get(key);
    p = MemoryManager.update(p, payload);
    return p;
}
Also used : Pointer(org.directmemory.memory.Pointer)

Example 5 with Pointer

use of org.directmemory.memory.Pointer in project DirectMemory by raffaeleguidi.

the class Cache method putByteArray.

public static Pointer putByteArray(String key, byte[] payload, int expiresIn) {
    Pointer ptr = MemoryManager.store(payload, expiresIn);
    map.put(key, ptr);
    return ptr;
}
Also used : Pointer(org.directmemory.memory.Pointer)

Aggregations

Pointer (org.directmemory.memory.Pointer)21 Test (org.junit.Test)12 BenchmarkOptions (com.carrotsearch.junitbenchmarks.BenchmarkOptions)4 OffHeapMemoryBuffer (org.directmemory.memory.OffHeapMemoryBuffer)4 IOException (java.io.IOException)2 Random (java.util.Random)2 MapMaker (com.google.common.collect.MapMaker)1