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);
}
}
}
}
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);
}
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);
}
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;
}
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());
}
}
Aggregations