Search in sources :

Example 46 with LoopInterruptedCheck

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

the class CqenginePerformanceTest method readGetLatest.

private void readGetLatest(final IndexedCollection<Content> 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 = 0; reads < READS; reads++) {
        FDate prevValue = null;
        int count = 0;
        for (int i = 0; i < values.size(); i++) {
            try (ResultSet<Content> result = table.retrieve(QueryFactory.lessThanOrEqualTo(Content.KEY, values.get(i).millisValue()), QueryFactory.queryOptions(QueryFactory.orderBy(QueryFactory.descending(Content.KEY)), QueryFactory.applyThresholds(QueryFactory.threshold(EngineThresholds.INDEX_ORDERING_SELECTIVITY, 1.0))))) {
                final Iterator<Content> iterator = result.iterator();
                final FDate value = iterator.next().getValue();
                if (prevValue != null) {
                    Assertions.checkTrue(prevValue.isBefore(value));
                }
                prevValue = value;
                count++;
            }
        }
        Assertions.checkEquals(count, VALUES);
        if (loopCheck.check()) {
            printProgress("GetLatests", readsStart, VALUES * reads, VALUES * READS);
        }
    }
    printProgress("GetLatestsFinished", 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)

Example 47 with LoopInterruptedCheck

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

the class CqenginePerformanceTest method readOrderedIndex.

private void readOrderedIndex(final NavigableIndex<Long, Content> index) throws InterruptedException {
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    final Instant readsStart = new Instant();
    for (int reads = 0; reads < READS; reads++) {
        FDate prevValue = null;
        int count = 0;
        final CloseableIterable<KeyValue<Long, Content>> result = index.getKeysAndValues(QueryFactory.noQueryOptions());
        try (CloseableIterator<KeyValue<Long, Content>> it = result.iterator()) {
            try {
                while (it.hasNext()) {
                    final FDate value = it.next().getValue().getValue();
                    if (prevValue != null) {
                        Assertions.checkTrue(prevValue.isBefore(value));
                    }
                    prevValue = value;
                    count++;
                }
            } catch (final NoSuchElementException e) {
            // end reached
            }
        }
        Assertions.checkEquals(count, VALUES);
        if (loopCheck.check()) {
            printProgress("ReadOrderedIndexs", readsStart, VALUES * reads, VALUES * READS);
        }
    }
    printProgress("ReadOrderedIndexsFinished", readsStart, VALUES * READS, VALUES * READS);
}
Also used : KeyValue(com.googlecode.cqengine.index.support.KeyValue) 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 48 with LoopInterruptedCheck

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

the class CqenginePerformanceTest method readGetLatestIndex.

private void readGetLatestIndex(final NavigableIndex<Long, Content> index) 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 = 0; reads < READS; reads++) {
        FDate prevValue = null;
        int count = 0;
        for (int i = 0; i < values.size(); i++) {
            final CloseableIterable<KeyValue<Long, Content>> result = index.getKeysAndValuesDescending(Long.MIN_VALUE, true, values.get(i).millisValue(), true, QueryFactory.noQueryOptions());
            try (CloseableIterator<KeyValue<Long, Content>> it = result.iterator()) {
                final FDate value = it.next().getValue().getValue();
                if (prevValue != null) {
                    Assertions.checkTrue(prevValue.isBefore(value));
                }
                prevValue = value;
                count++;
            }
        }
        Assertions.checkEquals(count, VALUES);
        if (loopCheck.check()) {
            printProgress("GetLatestIndexs", readsStart, VALUES * reads, VALUES * READS);
        }
    }
    printProgress("GetLatestIndexsFinished", readsStart, VALUES * READS, VALUES * READS);
}
Also used : KeyValue(com.googlecode.cqengine.index.support.KeyValue) Instant(de.invesdwin.util.time.Instant) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.FDate)

Example 49 with LoopInterruptedCheck

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

the class CqenginePerformanceTest method testCqenginePerformance.

@Test
public void testCqenginePerformance() throws InterruptedException, IOException {
    final File folder = new File(ContextProperties.getCacheDirectory(), CqenginePerformanceTest.class.getSimpleName());
    final File file = new File(folder, "table.db");
    Files.deleteNative(folder);
    Files.forceMkdir(folder);
    final DiskPersistence<Content, Long> persistence = DiskPersistence.onPrimaryKeyInFile(Content.KEY, file);
    // final OffHeapPersistence<Content, Long> persistence = OffHeapPersistence.onPrimaryKey(Content.KEY);
    // final OnHeapPersistence<Content, Long> persistence = OnHeapPersistence.onPrimaryKey(Content.KEY);
    final IndexedCollection<Content> table = new ConcurrentIndexedCollection<Content>(persistence);
    final NavigableIndex<Long, Content> navigableIndex = NavigableIndex.onAttribute(Content.KEY);
    // NavigableIndex<Long, Content> navigableIndex = NavigableIndex.withQuantizerOnAttribute(LongQuantizer.withCompressionFactor(5), KeyValue.KEY);
    table.addIndex(navigableIndex);
    table.addIndex(UniqueIndex.onAttribute(Content.KEY));
    final Instant writesStart = new Instant();
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck();
    int i = 0;
    final List<Content> flushable = new ArrayList<>();
    for (final FDate date : newValues()) {
        flushable.add(new Content(date.millisValue(), date));
        i++;
        if (i % FLUSH_INTERVAL == 0) {
            table.addAll(flushable);
            flushable.clear();
            if (loopCheck.check()) {
                printProgress("Writes", writesStart, i, VALUES);
            }
        }
    }
    if (!flushable.isEmpty()) {
        table.addAll(flushable);
    }
    persistence.compact();
    printProgress("WritesFinished", writesStart, VALUES, VALUES);
    readIterator(table);
    readOrdered(table);
    readOrderedIndex(navigableIndex);
    readGet(table);
    readGetLatest(table);
    readGetLatestIndex(navigableIndex);
    table.clear();
}
Also used : ConcurrentIndexedCollection(com.googlecode.cqengine.ConcurrentIndexedCollection) Instant(de.invesdwin.util.time.Instant) ArrayList(java.util.ArrayList) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.FDate) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 50 with LoopInterruptedCheck

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

the class CqenginePerformanceTest method readGet.

private void readGet(final IndexedCollection<Content> 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 = 0; reads < READS; reads++) {
        FDate prevValue = null;
        int count = 0;
        for (int i = 0; i < values.size(); i++) {
            try (ResultSet<Content> result = table.retrieve(QueryFactory.equal(Content.KEY, values.get(i).millisValue()))) {
                final FDate value = result.uniqueResult().getValue();
                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 : Instant(de.invesdwin.util.time.Instant) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.FDate)

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