Search in sources :

Example 21 with Instant

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

the class RangeTableDBPerformanceTest method testLevelDbPerformance.

@Test
public void testLevelDbPerformance() throws InterruptedException {
    final ADelegateRangeTable<String, FDate, FDate> table = new ADelegateRangeTable<String, FDate, FDate>("testLevelDbPerformance") {

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

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

        @Override
        protected ISerde<FDate> newRangeKeySerde() {
            return FDateSerde.GET;
        }
    };
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    RangeBatch<String, FDate, FDate> batch = table.newRangeBatch();
    final Instant writesStart = new Instant();
    int i = 0;
    for (final FDate date : newValues()) {
        batch.put(HASH_KEY, date, date);
        i++;
        if (i % FLUSH_INTERVAL == 0) {
            try {
                if (loopCheck.check()) {
                    printProgress("Writes", writesStart, i, VALUES);
                }
            } catch (final InterruptedException e) {
                throw new RuntimeException(e);
            }
            try {
                batch.flush();
                batch.close();
            } catch (final IOException e) {
                throw new RuntimeException(e);
            }
            batch = table.newRangeBatch();
        }
    }
    try {
        batch.flush();
        batch.close();
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }
    printProgress("WritesFinished", writesStart, VALUES, VALUES);
    readIterator(table);
    readGet(table);
    readGetLatest(table);
}
Also used : Instant(de.invesdwin.util.time.Instant) IOException(java.io.IOException) ADelegateRangeTable(de.invesdwin.context.persistence.ezdb.table.range.ADelegateRangeTable) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.FDate) Test(org.junit.jupiter.api.Test)

Example 22 with Instant

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

the class RangeTableDBPerformanceTest method readGetLatest.

private void readGetLatest(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.getLatestValue(HASH_KEY, values.get(i));
                if (prevValue != null) {
                    Assertions.checkTrue(prevValue.isBefore(value));
                }
                prevValue = value;
            } catch (final NoSuchElementException e) {
                break;
            }
        }
        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) NoSuchElementException(java.util.NoSuchElementException)

Example 23 with Instant

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

the class RangeTableDBPerformanceTest method readIterator.

private void readIterator(final ADelegateRangeTable<String, FDate, FDate> 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 ICloseableIterator<FDate> range = table.rangeValues(HASH_KEY);
        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);
        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 24 with Instant

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

the class BlockCompressedRecordFilePerformanceTest method testBlockCompressedRecordFilePerformance.

@Test
public void testBlockCompressedRecordFilePerformance() throws IOException, InterruptedException {
    final File directory = new File(ContextProperties.getCacheDirectory(), BlockCompressedRecordFilePerformanceTest.class.getSimpleName());
    Files.deleteNative(directory);
    Files.forceMkdir(directory);
    final File file = new File(directory, "testBlockCompressedRecordFilePerformance");
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    final Instant writesStart = new Instant();
    try (BlockCompressedRecordFile.Writer<TimedDecimal> writer = new BlockCompressedRecordFile.Writer.Builder<TimedDecimal>(file, IndeedSerializer.valueOf(TimedDecimalSerde.GET)).build()) {
        int i = 0;
        for (final FDate date : newValues()) {
            writer.append(new TimedDecimal(date, date.millisValue()));
            i++;
            if (i % FLUSH_INTERVAL == 0) {
                if (loopCheck.check()) {
                    printProgress("Writes", writesStart, i, VALUES);
                }
            }
        }
        printProgress("WritesFinished", writesStart, VALUES, VALUES);
    }
    readIterator(file);
}
Also used : Instant(de.invesdwin.util.time.Instant) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) File(java.io.File) BlockCompressedRecordFile(com.indeed.lsmtree.recordlog.BlockCompressedRecordFile) RecordFile(com.indeed.lsmtree.recordlog.RecordFile) TimedDecimal(de.invesdwin.util.math.decimal.TimedDecimal) BlockCompressedRecordFile(com.indeed.lsmtree.recordlog.BlockCompressedRecordFile) FDate(de.invesdwin.util.time.date.FDate) Test(org.junit.jupiter.api.Test)

Example 25 with Instant

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

the class BlockCompressedRecordFilePerformanceTest method readIterator.

private void readIterator(final File file) throws IOException, InterruptedException {
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck();
    final Instant readsStart = new Instant();
    for (int reads = 1; reads <= READS; reads++) {
        FDate prevValue = null;
        int count = 0;
        try (BlockCompressedRecordFile<TimedDecimal> reader = new BlockCompressedRecordFile.Builder<TimedDecimal>(file, IndeedSerializer.valueOf(TimedDecimalSerde.GET), new SnappyCodec()).build()) {
            final RecordFile.Reader<TimedDecimal> iterator = reader.reader();
            while (iterator.next()) {
                final FDate value = iterator.get().getTime();
                if (prevValue != null) {
                    Assertions.checkTrue(prevValue.isBefore(value));
                }
                prevValue = value;
                count++;
            }
            Assertions.checkEquals(count, VALUES);
            if (loopCheck.check()) {
                printProgress("Reads", readsStart, VALUES * reads, VALUES * READS);
            }
        }
    }
    printProgress("ReadsFinished", readsStart, VALUES * READS, VALUES * READS);
}
Also used : BlockCompressedRecordFile(com.indeed.lsmtree.recordlog.BlockCompressedRecordFile) RecordFile(com.indeed.lsmtree.recordlog.RecordFile) Instant(de.invesdwin.util.time.Instant) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) TimedDecimal(de.invesdwin.util.math.decimal.TimedDecimal) SnappyCodec(com.indeed.util.compress.SnappyCodec) FDate(de.invesdwin.util.time.date.FDate) BlockCompressedRecordFile(com.indeed.lsmtree.recordlog.BlockCompressedRecordFile)

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