Search in sources :

Example 51 with ChronicleQueue

use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.

the class Queue30Test method testST.

@SuppressWarnings("InfiniteLoopStatement")
@Ignore("Stress test - doesn't finish")
@Test
public void testST() throws IOException {
    try (final ChronicleQueue queue = new SingleChronicleQueueBuilder(getTmpDir()).wireType(WireType.TEXT).blockSize(640_000).build()) {
        final String name = Thread.currentThread().getName();
        final ExcerptAppender appender = queue.acquireAppender();
        for (int count = 0; ; count++) {
            final int c = count;
            appender.writeDocument(w -> w.write(() -> "thread").text(name).write(() -> "count").int32(c));
            if (count % 50_000 == 0) {
                LOGGER.info(name + "> " + count);
            }
        }
    }
}
Also used : SingleChronicleQueueBuilder(net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 52 with ChronicleQueue

use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.

the class InternalBenchmarkMain method benchmark.

static void benchmark(int messageSize) {
    Histogram writeTime = new Histogram(32, 7);
    Histogram transportTime = new Histogram(32, 7);
    Histogram readTime = new Histogram(32, 7);
    String path = basePath + "/test-q-" + messageSize;
    ChronicleQueue queue = createQueue(path);
    Thread pretoucher = new Thread(() -> {
        ExcerptAppender appender = queue.acquireAppender();
        Thread thread = Thread.currentThread();
        while (!thread.isInterrupted()) {
            appender.pretouch();
            Jvm.pause(10);
        }
    });
    pretoucher.setDaemon(true);
    pretoucher.start();
    Histogram loopTime = new Histogram();
    Thread reader = new Thread(() -> {
        // try (ChronicleQueue queue2 = createQueue(path))
        ExcerptTailer tailer = queue.createTailer().toEnd();
        long endLoop = System.nanoTime();
        while (running) {
            loopTime.sample((double) (System.nanoTime() - endLoop));
            Jvm.safepoint();
            // readerLoopTime = System.nanoTime();
            // if (readerLoopTime - readerEndLoopTime > 1000)
            // System.out.println("r " + (readerLoopTime - readerEndLoopTime));
            // try {
            runInner(transportTime, readTime, tailer);
            runInner(transportTime, readTime, tailer);
            runInner(transportTime, readTime, tailer);
            runInner(transportTime, readTime, tailer);
            // } finally {
            // readerEndLoopTime = System.nanoTime();
            // }
            Jvm.safepoint();
            endLoop = System.nanoTime();
        }
    });
    reader.start();
    // give the reader time to start
    Jvm.pause(250);
    long next = System.nanoTime();
    long end = (long) (next + runtime * 1e9);
    ExcerptAppender appender = queue.acquireAppender();
    while (end > System.nanoTime()) {
        long start = System.nanoTime();
        try (DocumentContext dc = appender.writingDocument(false)) {
            writeMessage(dc.wire(), messageSize);
        }
        long written = System.nanoTime();
        long time = written - start;
        // System.out.println(time);
        writeTime.sample(time);
        long diff = writeTime.totalCount() - readTime.totalCount();
        Thread.yield();
        if (diff >= 200) {
            // long rlt = readerLoopTime;
            // long delay = System.nanoTime() - rlt;
            System.out.println("diff=" + diff);
            StringBuilder sb = new StringBuilder();
            sb.append("Reader: profile of the thread");
            Jvm.trimStackTrace(sb, reader.getStackTrace());
            System.out.println(sb);
        }
        next += messageSize * 1e9 / (throughput * 1e6);
        long delay = next - System.nanoTime();
        if (delay > 0)
            LockSupport.parkNanos(delay);
    }
    while (readTime.totalCount() < writeTime.totalCount()) Jvm.pause(50);
    pretoucher.interrupt();
    reader.interrupt();
    running = false;
    // monitor.interrupt();
    System.out.println("Loop times " + loopTime.toMicrosFormat());
    System.out.println("messageSize " + messageSize);
    System.out.println("messages " + writeTime.totalCount());
    System.out.println("write histogram: " + writeTime.toMicrosFormat());
    System.out.println("transport histogram: " + transportTime.toMicrosFormat());
    System.out.println("read histogram: " + readTime.toMicrosFormat());
    IOTools.deleteDirWithFiles(path, 2);
    Jvm.pause(1000);
}
Also used : Histogram(net.openhft.chronicle.core.util.Histogram) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) DocumentContext(net.openhft.chronicle.wire.DocumentContext) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer)

Example 53 with ChronicleQueue

use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.

the class InternalPingPongMain method pingPong.

static void pingPong(int size) {
    String path = InternalPingPongMain.basePath + "/test-q-" + Time.uniqueId();
    Histogram readDelay = new Histogram();
    Histogram readDelay2 = new Histogram();
    try (ChronicleQueue queue = createQueue(path)) {
        Thread reader = new Thread(() -> {
            ExcerptTailer tailer = queue.createTailer();
            while (running.get()) {
                // noinspection StatementWithEmptyBody
                while (readCount.get() == writeCount.get()) ;
                long wakeTime = System.nanoTime();
                while (running.get()) {
                    try (DocumentContext dc = tailer.readingDocument(true)) {
                        if (!dc.isPresent())
                            continue;
                    }
                    break;
                }
                final long delay = wakeTime - writeTime.get();
                final long time = System.nanoTime() - wakeTime;
                readDelay2.sample(time);
                readDelay.sample(delay);
                if (time + delay > 20_000)
                    System.out.println("td " + delay + " + " + time);
                if (readCount.get() == 100000) {
                    System.out.println("reset");
                    readDelay.reset();
                    readDelay2.reset();
                }
                readCount.incrementAndGet();
            }
        });
        reader.setDaemon(true);
        reader.start();
        Jvm.pause(100);
        final long finish = System.currentTimeMillis() + runtime * 1000L;
        final ExcerptAppender appender = queue.acquireAppender();
        while (System.currentTimeMillis() < finish) {
            if (readCount.get() < writeCount.get()) {
                Thread.yield();
                continue;
            }
            try (DocumentContext dc = appender.writingDocument(false)) {
                dc.wire().bytes().writeSkip(size);
            }
            writeCount.incrementAndGet();
            writeTime.set(System.nanoTime());
        }
        running.set(false);
    }
    System.out.println("read delay: " + readDelay.toMicrosFormat());
    System.out.println("read delay2: " + readDelay2.toMicrosFormat());
    IOTools.deleteDirWithFiles(path, 2);
}
Also used : Histogram(net.openhft.chronicle.core.util.Histogram) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) DocumentContext(net.openhft.chronicle.wire.DocumentContext) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer)

Example 54 with ChronicleQueue

use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.

the class ChronicleHistoryReader method readChronicle.

@Override
public Map<String, Histogram> readChronicle() {
    try (final ChronicleQueue q = createQueue()) {
        final ExcerptTailer tailer = q.createTailer();
        final WireParselet parselet = parselet();
        final FieldNumberParselet fieldNumberParselet = (methodId, wire) -> parselet.accept(Long.toString(methodId), wire.read());
        MessageHistory.set(new VanillaMessageHistory());
        try (final MethodReader mr = new VanillaMethodReader(tailer, true, parselet, fieldNumberParselet, null, parselet)) {
            while (!Thread.currentThread().isInterrupted() && mr.readOne()) {
                ++counter;
                if (this.progress && counter % 1_000_000L == 0) {
                    Jvm.debug().on(getClass(), "Progress: " + counter);
                }
            }
        }
    }
    return histos;
}
Also used : MethodReader(net.openhft.chronicle.bytes.MethodReader) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) Histogram(net.openhft.chronicle.core.util.Histogram) Files(java.nio.file.Files) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) Collectors(java.util.stream.Collectors) Jvm(net.openhft.chronicle.core.Jvm) LinkedHashMap(java.util.LinkedHashMap) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) SingleChronicleQueueBuilder(net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder) net.openhft.chronicle.wire(net.openhft.chronicle.wire) Map(java.util.Map) ToolsUtil(net.openhft.chronicle.queue.util.ToolsUtil) NotNull(org.jetbrains.annotations.NotNull) Path(java.nio.file.Path) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) MethodReader(net.openhft.chronicle.bytes.MethodReader) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer)

Example 55 with ChronicleQueue

use of net.openhft.chronicle.queue.ChronicleQueue in project Chronicle-Queue by OpenHFT.

the class SingleChronicleQueueBuilderTest method tryOverrideSourceId.

@Test
public void tryOverrideSourceId() {
    expectException("Overriding sourceId from existing metadata");
    final File tmpDir = getTmpDir();
    final int firstSourceId = 1;
    try (ChronicleQueue ignored = SingleChronicleQueueBuilder.single(tmpDir).sourceId(firstSourceId).build()) {
    // just create the queue
    }
    try (ChronicleQueue q = SingleChronicleQueueBuilder.single(tmpDir).sourceId(firstSourceId + 1).build()) {
        assertEquals(firstSourceId, q.sourceId());
    }
}
Also used : ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) File(java.io.File) Test(org.junit.Test)

Aggregations

ChronicleQueue (net.openhft.chronicle.queue.ChronicleQueue)80 Test (org.junit.Test)59 ExcerptAppender (net.openhft.chronicle.queue.ExcerptAppender)37 ExcerptTailer (net.openhft.chronicle.queue.ExcerptTailer)37 File (java.io.File)36 DocumentContext (net.openhft.chronicle.wire.DocumentContext)21 ArrayList (java.util.ArrayList)16 SingleChronicleQueueBuilder (net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder)14 MethodReader (net.openhft.chronicle.bytes.MethodReader)12 List (java.util.List)11 IOException (java.io.IOException)9 MappedFile (net.openhft.chronicle.bytes.MappedFile)8 Path (java.nio.file.Path)7 Bytes (net.openhft.chronicle.bytes.Bytes)7 Collections (java.util.Collections)6 RollCycles (net.openhft.chronicle.queue.RollCycles)6 NotNull (org.jetbrains.annotations.NotNull)6 ByteBuffer (java.nio.ByteBuffer)5 MappedBytes (net.openhft.chronicle.bytes.MappedBytes)5 Histogram (net.openhft.chronicle.core.util.Histogram)5