Search in sources :

Example 1 with LongValue

use of net.openhft.lang.values.LongValue in project HugeCollections-OLD by peter-lawrey.

the class SharedHashMapTest method testAcquireWithNullContainer.

@Test
public void testAcquireWithNullContainer() throws Exception {
    SharedHashMap<CharSequence, LongValue> map = getSharedMap(10 * 1000, 128, 24);
    map.acquireUsing("key", new LongValue$$Native());
    assertEquals(0, map.acquireUsing("key", null).getValue());
    map.close();
}
Also used : LongValue(net.openhft.lang.values.LongValue) LongValue$$Native(net.openhft.lang.values.LongValue$$Native) Test(org.junit.Test)

Example 2 with LongValue

use of net.openhft.lang.values.LongValue in project HugeCollections-OLD by peter-lawrey.

the class SharedHashMapTest method testAcquireAndGet.

public void testAcquireAndGet(SharedHashMap<CharSequence, LongValue> map, int entries) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException {
    LongValue value = new LongValue$$Native();
    LongValue value2 = new LongValue$$Native();
    LongValue value3 = new LongValue$$Native();
    for (int j = 1; j <= 3; j++) {
        for (int i = 0; i < entries; i++) {
            CharSequence userCS = getUserCharSequence(i);
            if (j > 1) {
                assertNotNull(map.getUsing(userCS, value));
            } else {
                map.acquireUsing(userCS, value);
            }
            assertEquals(j - 1, value.getValue());
            value.addAtomicValue(1);
            assertEquals(value2, map.acquireUsing(userCS, value2));
            assertEquals(j, value2.getValue());
            assertEquals(value3, map.getUsing(userCS, value3));
            assertEquals(j, value3.getValue());
        }
    }
    map.close();
}
Also used : LongValue(net.openhft.lang.values.LongValue) LongValue$$Native(net.openhft.lang.values.LongValue$$Native)

Example 3 with LongValue

use of net.openhft.lang.values.LongValue in project HugeCollections-OLD by peter-lawrey.

the class SHMLatencyTestMain method main.

// TODO test passes but is under development.
public static void main(String... ignored) throws IOException {
    AffinityLock lock = AffinityLock.acquireCore();
    File file = File.createTempFile("testSHMLatency", "deleteme");
    // File file = new File("testSHMLatency.deleteme");
    file.delete();
    SharedHashMap<LongValue, LongValue> countersMap = new SharedHashMapBuilder().entries(KEYS).entrySize(24).generatedKeyType(true).generatedValueType(true).file(file).kClass(LongValue.class).vClass(LongValue.class).create();
    // add keys
    LongValue key = DataValueClasses.newInstance(LongValue.class);
    LongValue value = DataValueClasses.newInstance(LongValue.class);
    for (long i = 0; i < KEYS; i++) {
        key.setValue(i);
        value.setValue(0);
        countersMap.put(key, value);
    }
    System.out.println("Keys created");
    // Monitor monitor = new Monitor();
    LongValue value2 = DataValueClasses.newDirectReference(LongValue.class);
    for (int t = 0; t < 5; t++) {
        for (int rate : new int[] { 2 * 1000 * 1000, 1000 * 1000, 500 * 1000 /*, 250 * 1000, 100 * 1000, 50 * 1000*/
        }) {
            Histogram times = new Histogram();
            int u = 0;
            long start = System.nanoTime();
            long delay = 1000 * 1000 * 1000L / rate;
            long next = start + delay;
            for (long j = 0; j < RUN_TIME * rate; j += KEYS) {
                int stride = Math.max(1, KEYS / (RUN_TIME * rate));
                // the timed part
                for (int i = 0; i < KEYS && u < RUN_TIME * rate; i += stride) {
                    // busy wait for next time.
                    while (System.nanoTime() < next - 12) ;
                    // monitor.sample = System.nanoTime();
                    long start0 = next;
                    // start the update.
                    key.setValue(i);
                    LongValue using = countersMap.getUsing(key, value2);
                    if (using == null)
                        assertNotNull(using);
                    value2.addAtomicValue(1);
                    // calculate the time using the time it should have started, not when it was able.
                    long elapse = System.nanoTime() - start0;
                    times.sample(elapse);
                    next += delay;
                }
            // monitor.sample = Long.MAX_VALUE;
            }
            System.out.printf("run %d %,9d : ", t, rate);
            times.printPercentiles(" micro-seconds.");
        }
        System.out.println();
    }
    // monitor.running = false;
    countersMap.close();
    file.delete();
}
Also used : LongValue(net.openhft.lang.values.LongValue) File(java.io.File) AffinityLock(net.openhft.affinity.AffinityLock)

Example 4 with LongValue

use of net.openhft.lang.values.LongValue in project HugeCollections-OLD by peter-lawrey.

the class SharedHashMapTest method testAcquireFromMultipleThreads.

public void testAcquireFromMultipleThreads(SharedHashMap<CharSequence, LongValue> map) throws Exception {
    CharSequence key = getUserCharSequence(0);
    map.acquireUsing(key, new LongValue$$Native());
    int iterations = 1000;
    int noOfThreads = 10;
    CyclicBarrier barrier = new CyclicBarrier(noOfThreads);
    Thread[] threads = new Thread[noOfThreads];
    for (int t = 0; t < noOfThreads; t++) {
        threads[t] = new Thread(new IncrementRunnable(map, key, iterations, barrier));
        threads[t].start();
    }
    for (int t = 0; t < noOfThreads; t++) {
        threads[t].join();
    }
    assertEquals(noOfThreads * iterations, map.acquireUsing(key, new LongValue$$Native()).getValue());
    map.close();
}
Also used : LongValue$$Native(net.openhft.lang.values.LongValue$$Native)

Example 5 with LongValue

use of net.openhft.lang.values.LongValue in project HugeCollections-OLD by peter-lawrey.

the class SharedHashMapTest method testGetWithNullContainer.

@Test
public void testGetWithNullContainer() throws Exception {
    SharedHashMap<CharSequence, LongValue> map = getSharedMap(10 * 1000, 128, 24);
    map.acquireUsing("key", new LongValue$$Native());
    assertEquals(0, map.getUsing("key", null).getValue());
    map.close();
}
Also used : LongValue(net.openhft.lang.values.LongValue) LongValue$$Native(net.openhft.lang.values.LongValue$$Native) Test(org.junit.Test)

Aggregations

LongValue (net.openhft.lang.values.LongValue)4 LongValue$$Native (net.openhft.lang.values.LongValue$$Native)4 Test (org.junit.Test)2 File (java.io.File)1 AffinityLock (net.openhft.affinity.AffinityLock)1