Search in sources :

Example 71 with Instant

use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.

the class PersistentChronicleMapPerformanceTest method readIterator.

private void readIterator(final APersistentMap<FDate, FDate> table) {
    final Instant readsStart = new Instant();
    for (int reads = 1; reads <= READS; reads++) {
        // FDate prevValue = null;
        final Iterator<FDate> range = table.values().iterator();
        int count = 0;
        while (true) {
            try {
                final FDate value = range.next();
                // if (prevValue != null) {
                // Assertions.checkTrue(prevValue.isBefore(value));
                // }
                // prevValue = value;
                count++;
            } catch (final NoSuchElementException e) {
                break;
            }
        }
        Assertions.checkEquals(count, VALUES);
        printProgress("Reads", readsStart, VALUES * reads, VALUES * READS);
    }
    printProgress("ReadsFinished", readsStart, VALUES * READS, VALUES * READS);
}
Also used : Instant(de.invesdwin.util.time.Instant) FDate(de.invesdwin.util.time.date.FDate) NoSuchElementException(java.util.NoSuchElementException)

Example 72 with Instant

use of de.invesdwin.util.time.Instant 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 73 with Instant

use of de.invesdwin.util.time.Instant 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 74 with Instant

use of de.invesdwin.util.time.Instant 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 75 with Instant

use of de.invesdwin.util.time.Instant 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)

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