use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.
the class QuestDBPerformanceTest method readGet.
private void readGet(final CairoEngine engine) throws InterruptedException, SqlException {
final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
final List<FDate> values = Lists.toList(newValues());
final Instant readsStart = new Instant();
final SqlExecutionContextImpl ctx = new SqlExecutionContextImpl(engine, 1);
try (SqlCompiler compiler = new SqlCompiler(engine)) {
for (int reads = 0; reads < READS; reads++) {
FDate prevValue = null;
int count = 0;
for (int i = 0; i < values.size(); i++) {
try (RecordCursorFactory factory = compiler.compile("abc WHERE key = cast(" + values.get(i).millisValue() + " AS TIMESTAMP) LIMIT 1", ctx).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(ctx)) {
final io.questdb.cairo.sql.Record record = cursor.getRecord();
Assertions.checkTrue(cursor.hasNext());
final FDate value = new FDate(record.getLong(0));
if (prevValue != null) {
Assertions.checkTrue(prevValue.isBefore(value));
}
prevValue = value;
count++;
}
}
}
Assertions.checkEquals(count, VALUES);
if (loopCheck.check()) {
printProgress("Gets", readsStart, VALUES * reads, VALUES * READS);
}
}
}
printProgress("GetsFinished", readsStart, VALUES * READS, VALUES * READS);
}
use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.
the class QuestDBPerformanceTest method readGetLatest.
private void readGetLatest(final CairoEngine engine) throws InterruptedException, SqlException {
final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
final List<FDate> values = Lists.toList(newValues());
final Instant readsStart = new Instant();
final SqlExecutionContextImpl ctx = new SqlExecutionContextImpl(engine, 1);
try (SqlCompiler compiler = new SqlCompiler(engine)) {
for (int reads = 0; reads < READS; reads++) {
FDate prevValue = null;
int count = 0;
for (int i = 0; i < values.size(); i++) {
// ORDER BY key DESC is horribly slow (90/s), SELECT max works better
try (RecordCursorFactory factory = compiler.compile("SELECT max(value) FROM abc WHERE key <= cast(" + (values.get(i).millisValue()) + " AS TIMESTAMP) LIMIT 1", ctx).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(ctx)) {
final io.questdb.cairo.sql.Record record = cursor.getRecord();
Assertions.checkTrue(cursor.hasNext());
final FDate value = new FDate(record.getLong(0));
if (prevValue != null) {
Assertions.checkTrue(prevValue.isBefore(value));
}
prevValue = value;
count++;
if (loopCheck.check()) {
printProgress("GetLatests", readsStart, VALUES * reads + count, VALUES * READS);
}
}
}
}
Assertions.checkEquals(count, VALUES);
}
}
printProgress("GetLatestsFinished", readsStart, VALUES * READS, VALUES * READS);
}
use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.
the class MapDBPerformanceTest method readGet.
private void readGet(final APersistentMap<FDate, FDate> table) throws InterruptedException {
final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
final List<FDate> values = Lists.toList(newValues());
final Instant readsStart = new Instant();
for (int reads = 1; reads <= READS; reads++) {
FDate prevValue = null;
for (int i = 0; i < values.size(); i++) {
try {
final FDate value = table.get(values.get(i));
if (prevValue != null) {
Assertions.checkTrue(prevValue.isBefore(value));
}
prevValue = value;
} catch (final NoSuchElementException e) {
break;
}
}
if (loopCheck.check()) {
printProgress("Gets", readsStart, VALUES * reads, VALUES * READS);
}
}
printProgress("GetsFinished", readsStart, VALUES * READS, VALUES * READS);
}
use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.
the class ASpinWaitTest method testNoWait.
@Test
public void testNoWait() throws IOException {
final ASpinWait waitingSpinWait = new ASpinWait() {
@Override
protected boolean isConditionFulfilled() {
return true;
}
};
final Duration maxWait = Duration.ONE_SECOND;
final Instant waitingSince = new Instant();
waitingSpinWait.awaitFulfill(waitingSince, maxWait);
Assertions.assertThat(waitingSince.toDuration()).isLessThan(maxWait);
}
use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.
the class ChannelPerformanceTest method read.
private void read(final ISynchronousWriter requestWriter, final ISynchronousReader responseReader) {
final Instant readsStart = new Instant();
FDate prevValue = null;
int count = 0;
try {
if (DEBUG) {
log.info("client open request writer");
}
requestWriter.open();
if (DEBUG) {
log.info("client open response reader");
}
responseReader.open();
final ASpinWait spinWait = new ASpinWait() {
@Override
protected boolean isConditionFulfilled() throws IOException {
return responseReader.hasNext();
}
};
Instant waitingSince = new Instant();
while (true) {
requestWriter.write(MESSAGE_TYPE, Bytes.EMPTY_ARRAY);
if (DEBUG) {
log.info("client request out");
}
Assertions.checkTrue(spinWait.awaitFulfill(waitingSince, MAX_WAIT_DURATION));
final Pair<Integer, byte[]> readMessage = responseReader.readMessage();
if (DEBUG) {
log.info("client response in");
}
final int messageType = readMessage.getFirst();
final byte[] responseBytes = readMessage.getSecond();
Assertions.checkEquals(messageType, MESSAGE_TYPE);
Assertions.checkEquals(responseBytes.length, MESSAGE_SIZE);
final FDate value = FDateSerde.GET.fromBytes(responseBytes);
if (prevValue != null) {
Assertions.checkTrue(prevValue.isBefore(value));
}
prevValue = value;
count++;
waitingSince = new Instant();
}
} catch (final EOFException e) {
// writer closed
} catch (final IOException e) {
throw new RuntimeException(e);
}
Assertions.checkEquals(count, VALUES);
try {
if (DEBUG) {
log.info("client close response reader");
}
responseReader.close();
if (DEBUG) {
log.info("client close request writer");
}
requestWriter.close();
} catch (final IOException e) {
throw new RuntimeException(e);
}
printProgress("ReadsFinished", readsStart, VALUES, VALUES);
}
Aggregations