Search in sources :

Example 66 with Instant

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

the class RangeTableDBPerformanceTest method readGet.

private void readGet(final ADelegateRangeTable<String, 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(HASH_KEY, 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 67 with Instant

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

the class MphTablePerformanceTest method readGet.

private void readGet(final File file) throws IOException {
    final List<FDate> values = Lists.toList(newValues());
    final Instant readsStart = new Instant();
    for (int reads = 1; reads <= READS; reads++) {
        FDate prevValue = null;
        try (TableReader<Long, Long> reader = TableReader.open(file)) {
            for (int i = 0; i < values.size(); i++) {
                final FDate value = new FDate(reader.get(values.get(i).millisValue()));
                if (prevValue != null) {
                    Assertions.checkTrue(prevValue.isBefore(value));
                }
                prevValue = value;
            }
        }
        printProgress("Gets", readsStart, VALUES * reads, VALUES * READS);
    }
    printProgress("GetsFinished", readsStart, VALUES * READS, VALUES * READS);
}
Also used : Instant(de.invesdwin.util.time.Instant) FDate(de.invesdwin.util.time.date.FDate)

Example 68 with Instant

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

the class MphTablePerformanceTest method testMphTablePerformance.

@Test
public void testMphTablePerformance() throws IOException {
    final File directory = new File(ContextProperties.getCacheDirectory(), MphTablePerformanceTest.class.getSimpleName());
    Files.deleteNative(directory);
    Files.forceMkdir(directory);
    final File file = new File(directory, "testMphTablePerformance");
    final Instant writesStart = new Instant();
    final TableConfig<Long, Long> config = new TableConfig<Long, Long>().withKeySerializer(new SmartLongSerializer()).withValueSerializer(new SmartVLongSerializer());
    final ATransformingIterable<FDate, com.indeed.util.core.Pair<Long, Long>> entries = new ATransformingIterable<FDate, com.indeed.util.core.Pair<Long, Long>>(newValues()) {

        @Override
        protected com.indeed.util.core.Pair<Long, Long> transform(final FDate value) {
            return com.indeed.util.core.Pair.of(value.millisValue(), value.millisValue());
        }
    };
    // can not append to an existing table
    TableWriter.write(file, config, entries);
    printProgress("WritesFinished", writesStart, VALUES, VALUES);
    readIterator(file);
    readGet(file);
}
Also used : ATransformingIterable(de.invesdwin.util.collections.iterable.ATransformingIterable) Instant(de.invesdwin.util.time.Instant) FDate(de.invesdwin.util.time.date.FDate) SmartLongSerializer(com.indeed.mph.serializers.SmartLongSerializer) SmartVLongSerializer(com.indeed.mph.serializers.SmartVLongSerializer) TableConfig(com.indeed.mph.TableConfig) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 69 with Instant

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

the class HsqldbPerformanceTest method readGet.

private void readGet(final Connection conn) throws Exception {
    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;
        try (PreparedStatement select = conn.prepareStatement("SELECT value FROM abc where key = ? LIMIT 1")) {
            for (int i = 0; i < values.size(); i++) {
                select.setLong(1, values.get(i).millisValue());
                try (ResultSet results = select.executeQuery()) {
                    Assertions.checkTrue(results.next());
                    final FDate value = new FDate(results.getLong(1));
                    if (prevValue != null) {
                        Assertions.checkTrue(prevValue.isBefore(value));
                    }
                    prevValue = value;
                    count++;
                    if (loopCheck.check()) {
                        printProgress("Gets", readsStart, VALUES * reads + count, VALUES * READS);
                    }
                }
            }
        }
        Assertions.checkEquals(count, VALUES);
    }
    printProgress("GetsFinished", readsStart, VALUES * READS, VALUES * READS);
}
Also used : Instant(de.invesdwin.util.time.Instant) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.FDate)

Example 70 with Instant

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

the class HsqldbPerformanceTest method readGetLatest.

private void readGetLatest(final Connection conn) throws Exception {
    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;
        try (PreparedStatement select = conn.prepareStatement("SELECT value FROM abc WHERE key <=? ORDER BY KEY DESC LIMIT 1")) {
            for (int i = 0; i < values.size(); i++) {
                select.setLong(1, values.get(i).millisValue());
                try (ResultSet results = select.executeQuery()) {
                    Assertions.checkTrue(results.next());
                    final FDate value = new FDate(results.getLong(1));
                    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 : Instant(de.invesdwin.util.time.Instant) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.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