Java Code Examples for net.openhft.chronicle.core.values.LongValue#addAtomicValue()
The following examples show how to use
net.openhft.chronicle.core.values.LongValue#addAtomicValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChronicleMapTest.java From Chronicle-Map with Apache License 2.0 | 5 votes |
@Override public void run() { try { LongValue value = Values.newNativeReference(LongValue.class); barrier.await(); for (int i = 0; i < iterations; i++) { map.acquireUsing(key, value); value.addAtomicValue(1); } } catch (Exception e) { e.printStackTrace(); } }
Example 2
Source File: CHMLatencyTestMain.java From Chronicle-Map with Apache License 2.0 | 4 votes |
public static void main(String... ignored) throws IOException { AffinityLock lock = AffinityLock.acquireCore(); File file = File.createTempFile("testCHMLatency", "deleteme"); // File file = new File("testCHMLatency.deleteme"); file.delete(); ChronicleMap<LongValue, LongValue> countersMap = ChronicleMapBuilder.of(LongValue.class, LongValue.class) .entries(KEYS) .createPersistedTo(file); // add keys LongValue key = Values.newHeapInstance(LongValue.class); LongValue value = Values.newNativeReference(LongValue.class); for (long i = 0; i < KEYS; i++) { key.setValue(i); countersMap.acquireUsing(key, value); value.setValue(0); } System.out.println("Keys created"); // Monitor monitor = new Monitor(); LongValue value2 = Values.newNativeReference(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(); }