Search in sources :

Example 46 with Instant

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);
}
Also used : SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlCompiler(io.questdb.griffin.SqlCompiler) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Instant(de.invesdwin.util.time.Instant) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.FDate)

Example 47 with Instant

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);
}
Also used : SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlCompiler(io.questdb.griffin.SqlCompiler) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Instant(de.invesdwin.util.time.Instant) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.FDate)

Example 48 with Instant

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);
}
Also used : Instant(de.invesdwin.util.time.Instant) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.FDate) NoSuchElementException(java.util.NoSuchElementException)

Example 49 with Instant

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);
}
Also used : Instant(de.invesdwin.util.time.Instant) Duration(de.invesdwin.util.time.duration.Duration) ATest(de.invesdwin.context.test.ATest) Test(org.junit.Test)

Example 50 with Instant

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);
}
Also used : Instant(de.invesdwin.util.time.Instant) EOFException(java.io.EOFException) IOException(java.io.IOException) FDate(de.invesdwin.util.time.fdate.FDate)

Aggregations

Instant (de.invesdwin.util.time.Instant)93 FDate (de.invesdwin.util.time.date.FDate)78 LoopInterruptedCheck (de.invesdwin.util.concurrent.loop.LoopInterruptedCheck)65 NoSuchElementException (java.util.NoSuchElementException)30 Test (org.junit.jupiter.api.Test)25 File (java.io.File)16 PreparedStatement (java.sql.PreparedStatement)16 ResultSet (java.sql.ResultSet)15 Statement (java.sql.Statement)12 ATest (de.invesdwin.context.test.ATest)8 RecordFile (com.indeed.lsmtree.recordlog.RecordFile)6 ProcessedEventsRateString (de.invesdwin.util.lang.ProcessedEventsRateString)6 TimedDecimal (de.invesdwin.util.math.decimal.TimedDecimal)5 FDate (de.invesdwin.util.time.fdate.FDate)5 IOException (java.io.IOException)5 Connection (java.sql.Connection)5 APersistentMap (de.invesdwin.context.integration.persistentmap.APersistentMap)4 ATimeSeriesUpdater (de.invesdwin.context.persistence.timeseriesdb.updater.ATimeSeriesUpdater)4 Test (org.junit.Test)4 SnappyCodec (com.indeed.util.compress.SnappyCodec)3