use of net.openhft.chronicle.bytes.MappedBytes in project Chronicle-Queue by OpenHFT.
the class RollEOFTest method removeEOF.
private void removeEOF(Path path) throws IOException {
long blockSize = 64 << 10;
long chunkSize = OS.pageAlign(blockSize);
long overlapSize = OS.pageAlign(blockSize / 4);
final MappedBytes mappedBytes = MappedBytes.mappedBytes(path.toFile(), chunkSize, overlapSize, false);
mappedBytes.reserve();
try {
final Wire wire = WireType.BINARY_LIGHT.apply(mappedBytes);
final Bytes<?> bytes = wire.bytes();
bytes.readLimit(bytes.capacity());
bytes.readSkip(4);
// move past header
try (final SingleChronicleQueueStore qs = loadStore(wire)) {
assertNotNull(qs);
long l = qs.writePosition();
long len = Wires.lengthOf(bytes.readVolatileInt(l));
long eofOffset = l + len + 4L;
bytes.writePosition(eofOffset);
bytes.writeInt(0);
}
} finally {
mappedBytes.release();
}
}
use of net.openhft.chronicle.bytes.MappedBytes in project Chronicle-Queue by OpenHFT.
the class RollEOFTest method removeEOF.
private void removeEOF(Path path) throws IOException {
long blockSize = 64 << 10;
long chunkSize = OS.pageAlign(blockSize);
long overlapSize = OS.pageAlign(blockSize / 4);
final MappedBytes mappedBytes = MappedBytes.mappedBytes(path.toFile(), chunkSize, overlapSize, false);
mappedBytes.reserve(test);
try {
final Wire wire = WireType.BINARY_LIGHT.apply(mappedBytes);
final Bytes<?> bytes = wire.bytes();
bytes.readLimitToCapacity();
bytes.readSkip(4);
// move past header
try (final SingleChronicleQueueStore qs = loadStore(wire)) {
assertNotNull(qs);
long l = qs.writePosition();
long len = Wires.lengthOf(bytes.readVolatileInt(l));
long eofOffset = l + len + 4L;
bytes.writePosition(eofOffset);
bytes.writeInt(0);
}
} finally {
mappedBytes.release(test);
}
}
use of net.openhft.chronicle.bytes.MappedBytes in project Chronicle-Queue by OpenHFT.
the class SingleCQFormatTest method testCompleteHeader2.
@Test
public void testCompleteHeader2() throws FileNotFoundException {
final File dir = new File(OS.getTarget(), getClass().getSimpleName() + "-" + Time.uniqueId());
dir.mkdir();
final MappedBytes bytes = MappedBytes.mappedBytes(new File(dir, "19700101-02" + SingleChronicleQueue.SUFFIX), QueueUtil.testBlockSize() * 2L);
final Wire wire = new BinaryWire(bytes);
wire.usePadding(true);
try (final SingleChronicleQueueStore store = new SingleChronicleQueueStore(RollCycles.HOURLY, WireType.BINARY, bytes, 4 << 10, 4)) {
try (DocumentContext dc = wire.writingDocument(true)) {
dc.wire().write("header").typedMarshallable(store);
}
assertEquals("--- !!meta-data #binary\n" + "header: !SCQStore {\n" + " writePosition: [\n" + " 0,\n" + " 0\n" + " ],\n" + " indexing: !SCQSIndexing {\n" + " indexCount: !short 4096,\n" + " indexSpacing: 4,\n" + " index2Index: 0,\n" + " lastIndex: 0\n" + " },\n" + " dataFormat: 1\n" + "}\n", Wires.fromSizePrefixedBlobs(bytes.readPosition(0)));
}
try (RollingChronicleQueue queue = binary(dir).testBlockSize().rollCycle(RollCycles.HOURLY).build()) {
testQueue(queue);
assertEquals(2, queue.firstCycle());
}
try {
IOTools.shallowDeleteDirWithFiles(dir.getAbsolutePath());
} catch (Exception e) {
e.printStackTrace();
}
}
use of net.openhft.chronicle.bytes.MappedBytes in project Chronicle-Queue by OpenHFT.
the class MultiQueueStressMain method main.
public static void main(String[] args) throws FileNotFoundException {
for (int t = 0; t < runs; t++) {
long start0 = System.currentTimeMillis();
int count = 0;
String baseDir = target + "/deleteme/" + Time.uniqueId();
new File(baseDir).mkdirs();
MappedBytes[] queues = new MappedBytes[queueCount];
int pagesPer10Second = (int) (10L * (throughput << 20) / queueCount / (4 << 10));
for (int i = 0; i < queueCount; i++) {
long start1 = System.currentTimeMillis();
String filename = baseDir + "/" + count++;
queues[i] = MappedBytes.mappedBytes(filename, pagesPer10Second * (4 << 10));
long time1 = System.currentTimeMillis() - start1;
// if (time1 > 20)
// System.out.printf("Creating %s took %.3f seconds%n", filename, time1 / 1e3);
}
long mid1 = System.currentTimeMillis();
for (int i = 0; i < pagesPer10Second; i++) {
for (MappedBytes bytes : queues) {
bytes.writeLong(i * (4 << 10), i);
}
}
long mid2 = System.currentTimeMillis();
for (MappedBytes bytes : queues) {
bytes.releaseLast();
}
long end0 = System.currentTimeMillis();
long time0 = end0 - start0;
System.out.printf("Took %.3f seconds to write %,d MB, create: %.3f, write: %.3f, close: %.3f%n", time0 / 1e3, throughput * 10, (mid1 - start0) / 1e3, (mid2 - mid1) / 1e3, (end0 - mid2) / 1e3);
long delay = 10000 - time0;
if (delay > 0)
Jvm.pause(delay);
}
}
use of net.openhft.chronicle.bytes.MappedBytes in project Chronicle-Queue by OpenHFT.
the class SingleCQFormat2Test method checkFileContents.
public void checkFileContents(@NotNull File file, String expected) throws FileNotFoundException {
@NotNull MappedBytes bytes = MappedBytes.mappedBytes(file, QueueUtil.testBlockSize());
bytes.readLimit(bytes.realCapacity());
assertEquals(expected, Wires.fromAlignedSizePrefixedBlobs(bytes).replaceAll("(?m)^#.+$\\n", ""));
bytes.releaseLast();
}
Aggregations