Search in sources :

Example 31 with LoopInterruptedCheck

use of de.invesdwin.util.concurrent.loop.LoopInterruptedCheck 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 32 with LoopInterruptedCheck

use of de.invesdwin.util.concurrent.loop.LoopInterruptedCheck 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 33 with LoopInterruptedCheck

use of de.invesdwin.util.concurrent.loop.LoopInterruptedCheck 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 34 with LoopInterruptedCheck

use of de.invesdwin.util.concurrent.loop.LoopInterruptedCheck in project invesdwin-context-persistence by subes.

the class ChronicleMapPerformanceTest method readIterator.

private void readIterator(final ChronicleMap<Long, Long> table) throws InterruptedException {
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    final Instant readsStart = new Instant();
    for (int reads = 1; reads <= READS; reads++) {
        // FDate prevValue = null;
        final Iterator<Long> range = table.values().iterator();
        int count = 0;
        while (true) {
            try {
                final FDate value = new FDate(range.next());
                // if (prevValue != null) {
                // Assertions.checkTrue(prevValue.isBefore(value));
                // }
                // prevValue = value;
                count++;
            } catch (final NoSuchElementException e) {
                break;
            }
        }
        Assertions.checkEquals(count, VALUES);
        if (loopCheck.check()) {
            printProgress("Reads", readsStart, VALUES * reads, VALUES * READS);
        }
    }
    printProgress("ReadsFinished", 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 35 with LoopInterruptedCheck

use of de.invesdwin.util.concurrent.loop.LoopInterruptedCheck in project invesdwin-context-persistence by subes.

the class PersistentChronicleMapPerformanceTest method testChronicleMapPerformance.

@Test
public void testChronicleMapPerformance() throws InterruptedException {
    @SuppressWarnings("resource") final APersistentMap<FDate, FDate> table = new APersistentMap<FDate, FDate>("testChronicleMapPerformance") {

        @Override
        public File getBaseDirectory() {
            return ContextProperties.TEMP_DIRECTORY;
        }

        @Override
        public ISerde<FDate> newKeySerde() {
            return FDateSerde.GET;
        }

        @Override
        public ISerde<FDate> newValueSerde() {
            return FDateSerde.GET;
        }

        @Override
        protected IPersistentMapFactory<FDate, FDate> newFactory() {
            return new PersistentChronicleMapFactory<FDate, FDate>() {

                @SuppressWarnings("rawtypes")
                @Override
                protected ChronicleMapBuilder configureChronicleMap(final IPersistentMapConfig<FDate, FDate> config, final ChronicleMapBuilder builder) {
                    return builder.averageKeySize(FDate.BYTES).averageValueSize(FDate.BYTES).entries(VALUES);
                }
            };
        }
    };
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    final Instant writesStart = new Instant();
    int i = 0;
    for (final FDate date : newValues()) {
        table.put(date, date);
        i++;
        if (i % FLUSH_INTERVAL == 0) {
            if (loopCheck.check()) {
                printProgress("Writes", writesStart, i, VALUES);
            }
        }
    }
    printProgress("WritesFinished", writesStart, VALUES, VALUES);
    readIterator(table);
    readGet(table);
    table.deleteTable();
}
Also used : APersistentMap(de.invesdwin.context.integration.persistentmap.APersistentMap) ChronicleMapBuilder(net.openhft.chronicle.map.ChronicleMapBuilder) Instant(de.invesdwin.util.time.Instant) IPersistentMapConfig(de.invesdwin.context.integration.persistentmap.IPersistentMapConfig) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.FDate) PersistentChronicleMapFactory(de.invesdwin.context.persistence.chronicle.PersistentChronicleMapFactory) Test(org.junit.jupiter.api.Test)

Aggregations

LoopInterruptedCheck (de.invesdwin.util.concurrent.loop.LoopInterruptedCheck)65 Instant (de.invesdwin.util.time.Instant)65 FDate (de.invesdwin.util.time.date.FDate)63 NoSuchElementException (java.util.NoSuchElementException)22 Test (org.junit.jupiter.api.Test)19 PreparedStatement (java.sql.PreparedStatement)16 ResultSet (java.sql.ResultSet)15 File (java.io.File)12 Statement (java.sql.Statement)12 RecordFile (com.indeed.lsmtree.recordlog.RecordFile)6 TimedDecimal (de.invesdwin.util.math.decimal.TimedDecimal)6 Connection (java.sql.Connection)5 APersistentMap (de.invesdwin.context.integration.persistentmap.APersistentMap)4 SqlCompiler (io.questdb.griffin.SqlCompiler)4 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)4 SnappyCodec (com.indeed.util.compress.SnappyCodec)3 RecordCursor (io.questdb.cairo.sql.RecordCursor)3 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)3 KeyValue (com.googlecode.cqengine.index.support.KeyValue)2 BasicRecordFile (com.indeed.lsmtree.recordlog.BasicRecordFile)2