Search in sources :

Example 1 with NanoSampler

use of net.openhft.chronicle.core.util.NanoSampler in project Chronicle-Queue by OpenHFT.

the class QueueMultiThreadedJLBHBenchmark method init.

@Override
public void init(JLBH jlbh) {
    this.jlbh = jlbh;
    IOTools.deleteDirWithFiles(path, 10);
    sourceQueue = createQueueInstance();
    sinkQueue = useSingleQueueInstance ? sourceQueue : createQueueInstance();
    appender = sourceQueue.acquireAppender().disableThreadSafetyCheck(true);
    tailer = sinkQueue.createTailer().disableThreadSafetyCheck(true);
    NanoSampler readProbe = jlbh.addProbe("read");
    writeProbe = jlbh.addProbe("write");
    if (usePretoucher) {
        pretoucherExecutorService = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("pretoucher", true));
        pretoucherExecutorService.scheduleAtFixedRate(() -> sourceQueue.acquireAppender().pretouch(), 1, 200, TimeUnit.MILLISECONDS);
    }
    tailerThread = new Thread(() -> {
        try (final AffinityLock affinityLock = AffinityLock.acquireLock(tailerAffinity)) {
            Datum datum2 = new Datum(messageSize);
            while (!stopped) {
                long beforeReadNs = System.nanoTime();
                try (DocumentContext dc = tailer.readingDocument()) {
                    if (!dc.isPresent())
                        continue;
                    datum2.readMarshallable(dc.wire().bytes());
                    long now = System.nanoTime();
                    jlbh.sample(now - datum2.ts);
                    readProbe.sampleNanos(now - beforeReadNs);
                }
            }
        }
    });
    tailerThread.start();
}
Also used : NamedThreadFactory(net.openhft.chronicle.threads.NamedThreadFactory) NanoSampler(net.openhft.chronicle.core.util.NanoSampler) DocumentContext(net.openhft.chronicle.wire.DocumentContext) AffinityLock(net.openhft.affinity.AffinityLock)

Aggregations

AffinityLock (net.openhft.affinity.AffinityLock)1 NanoSampler (net.openhft.chronicle.core.util.NanoSampler)1 NamedThreadFactory (net.openhft.chronicle.threads.NamedThreadFactory)1 DocumentContext (net.openhft.chronicle.wire.DocumentContext)1