Search in sources :

Example 1 with IntValue

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

the class TCPSocketReplicationIntValueTest method setup.

@Before
public void setup() throws IOException {
    value = new IntValue$$Native();
    value.bytes(new ByteBufferBytes(ByteBuffer.allocateDirect(4)), 0);
    map1 = newTcpSocketShmIntValueString((byte) 1, 8076, new InetSocketAddress("localhost", 8077));
    map2 = newTcpSocketShmIntValueString((byte) 2, 8077);
}
Also used : ByteBufferBytes(net.openhft.lang.io.ByteBufferBytes) InetSocketAddress(java.net.InetSocketAddress) IntValue$$Native(net.openhft.lang.values.IntValue$$Native) Before(org.junit.Before)

Example 2 with IntValue

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

the class SharedHashMapTest method testAcquirePerf.

@Test
@Ignore
public void testAcquirePerf() throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException, InterruptedException, ExecutionException {
    //        int runs = Integer.getInteger("runs", 10);
    for (int runs : new int[] { 10, 50, 250, 500, 1000, 2500 }) {
        final long entries = runs * 1000 * 1000L;
        final SharedHashMap<CharSequence, IntValue> map = getSharedStringIntMap(entries, 1024, 20);
        int procs = Runtime.getRuntime().availableProcessors();
        // runs > 100 ? procs / 2 : procs;
        int threads = procs * 2;
        int count = runs > 500 ? runs > 1200 ? 1 : 3 : 5;
        // Math.min(procs, runs > 500 ? 8 : 4);
        final int independence = 8;
        System.out.println("\nKey size: " + runs + " Million entries. ");
        for (int j = 0; j < count; j++) {
            long start = System.currentTimeMillis();
            ExecutorService es = Executors.newFixedThreadPool(procs);
            List<Future> futures = new ArrayList<Future>();
            for (int i = 0; i < threads; i++) {
                final int t = i;
                futures.add(es.submit(new Runnable() {

                    @Override
                    public void run() {
                        IntValue value = nativeIntValue();
                        StringBuilder sb = new StringBuilder();
                        long next = 50 * 1000 * 1000;
                        // use a factor to give up to 10 digit numbers.
                        int factor = Math.max(1, (int) ((10 * 1000 * 1000 * 1000L - 1) / entries));
                        for (long j = t % independence; j < entries + independence - 1; j += independence) {
                            sb.setLength(0);
                            sb.append("us:");
                            sb.append(j * factor);
                            map.acquireUsing(sb, value);
                            long n = value.addAtomicValue(1);
                            assert n > 0 && n < 1000 : "Counter corrupted " + n;
                            if (t == 0 && j >= next) {
                                long size = map.longSize();
                                if (size < 0)
                                    throw new AssertionError("size: " + size);
                                System.out.println(j + ", size: " + size);
                                next += 50 * 1000 * 1000;
                            }
                        }
                    }
                }));
            }
            for (Future future : futures) {
                future.get();
            }
            es.shutdown();
            es.awaitTermination(runs / 10 + 1, TimeUnit.MINUTES);
            long time = System.currentTimeMillis() - start;
            System.out.printf("Throughput %.1f M ops/sec%n", threads * entries / independence / 1000.0 / time);
        }
        printStatus();
        File file = map.file();
        map.close();
        file.delete();
    }
}
Also used : IntValue(net.openhft.lang.values.IntValue) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with IntValue

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

the class IntValueMapTest method test.

@Test
@Ignore
public void test() throws IOException {
    final SharedHashMap<IntValue, CharSequence> map = new SharedHashMapBuilder().entries(1000).entries(20000).file(getPersistenceFile()).kClass(IntValue.class).vClass(CharSequence.class).create();
    IntValue$$Native value = new IntValue$$Native();
    value.bytes(new ByteBufferBytes(ByteBuffer.allocateDirect(4)), 0);
    value.setValue(1);
    final String expected = "test";
    map.put(value, expected);
    final CharSequence actual = map.get(value);
    assertEquals(expected, actual);
    // this will fail
    map.toString();
}
Also used : ByteBufferBytes(net.openhft.lang.io.ByteBufferBytes) IntValue$$Native(net.openhft.lang.values.IntValue$$Native) IntValue(net.openhft.lang.values.IntValue) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with IntValue

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

the class TCPSocketReplicationIntValueTest method testSoakTestWithRandomData.

@Test
//todo fix this
@Ignore
public void testSoakTestWithRandomData() throws IOException, InterruptedException {
    final long start = System.currentTimeMillis();
    System.out.print("SoakTesting ");
    for (int j = 1; j < 100 * 1000; j++) {
        if (j % 5000 == 0)
            System.out.print(".");
        Random rnd = new Random(j);
        for (int i = 1; i < 10; i++) {
            final int select = rnd.nextInt(2);
            final SharedHashMap<IntValue, CharSequence> map = select > 0 ? map1 : map2;
            switch(rnd.nextInt(2)) {
                case 0:
                    map.put(set(rnd.nextInt(1000)), /* + select * 100 */
                    "test");
                    break;
                case 1:
                    map.remove(set(rnd.nextInt(1000)));
                    break;
            }
        }
    }
    waitTillEqual(5000);
    final long time = System.currentTimeMillis() - start;
    //assertTrue("timeTaken="+time, time < 2200);
    System.out.println("\ntime taken millis=" + time);
}
Also used : Random(java.util.Random) IntValue(net.openhft.lang.values.IntValue) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

IntValue (net.openhft.lang.values.IntValue)3 Ignore (org.junit.Ignore)3 Test (org.junit.Test)3 ByteBufferBytes (net.openhft.lang.io.ByteBufferBytes)2 IntValue$$Native (net.openhft.lang.values.IntValue$$Native)2 File (java.io.File)1 InetSocketAddress (java.net.InetSocketAddress)1 Random (java.util.Random)1 Before (org.junit.Before)1