Search in sources :

Example 56 with Instant

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

the class ALoggingTimeSeriesUpdater method logFlush.

private void logFlush() {
    Assertions.assertThat(lastFlushIndex).isNotNull();
    // if we are too fast, only print status once a second
    if (lastFlushTime == null || lastFlushTime.isGreaterThan(Duration.ONE_SECOND)) {
        final Duration flushDuration = updateStart.toDuration();
        final Percent progress = getProgress();
        if (progress != null) {
            log.info("Persisted %s. %s batch for [%s]. Reached [%s] at time [%s]. Processed [%s] during %s", lastFlushIndex, getElementsName(), keyToString(getKey()), progress.asScale(PercentScale.PERCENT), lastFlushMaxTime, new ProcessedEventsRateString(flushElementCount, flushDuration), flushDuration);
        } else {
            log.info("Persisted %s. %s batch for [%s]. Reached time [%s]. Processed [%s] during %s", lastFlushIndex, getElementsName(), keyToString(getKey()), lastFlushMaxTime, new ProcessedEventsRateString(flushElementCount, flushDuration), flushDuration);
        }
        lastFlushTime = new Instant();
    }
    lastFlushIndex = null;
    lastFlushMaxTime = null;
}
Also used : ProcessedEventsRateString(de.invesdwin.util.lang.ProcessedEventsRateString) Percent(de.invesdwin.util.math.decimal.scaled.Percent) Instant(de.invesdwin.util.time.Instant) Duration(de.invesdwin.util.time.duration.Duration)

Example 57 with Instant

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

the class TimeseriesDBPerformanceTest method readIterator.

private void readIterator(final ATimeSeriesDB<String, FDate> table, final String suffix, final long maxReads) throws InterruptedException {
    final Instant readsStart = new Instant();
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    for (long reads = 1; reads <= maxReads; reads++) {
        FDate prevValue = null;
        final ICloseableIterator<? extends FDate> range = table.rangeValues(HASH_KEY, null, null).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(VALUES, count);
        if (loopCheck.check()) {
            printProgress("Reads" + suffix, readsStart, VALUES * reads, VALUES * maxReads);
        }
    }
    printProgress("ReadsFinished" + suffix, readsStart, VALUES * maxReads, VALUES * maxReads);
}
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 58 with Instant

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

the class TimeseriesDBPerformanceTest method testTimeSeriesDbPerformance.

@Test
public void testTimeSeriesDbPerformance() throws IncompleteUpdateFoundException, InterruptedException {
    final ATimeSeriesDB<String, FDate> table = new ATimeSeriesDB<String, FDate>("testTimeSeriesDbPerformance") {

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

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

        @Override
        protected Integer newValueFixedLength() {
            return FDateSerde.FIXED_LENGTH;
        }

        @Override
        protected String innerHashKeyToString(final String key) {
            return "testTimeSeriesDbPerformance_" + key;
        }

        @Override
        protected FDate extractEndTime(final FDate value) {
            return value;
        }
    };
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    final Instant writesStart = new Instant();
    final ATimeSeriesUpdater<String, FDate> updater = new ATimeSeriesUpdater<String, FDate>(HASH_KEY, table) {

        @Override
        protected ICloseableIterable<FDate> getSource(final FDate updateFrom) {
            return newValues();
        }

        @Override
        protected void onUpdateFinished(final Instant updateStart) {
            printProgress("WritesFinished", writesStart, VALUES, VALUES);
        }

        @Override
        protected void onUpdateStart() {
        }

        @Override
        protected FDate extractEndTime(final FDate element) {
            return element;
        }

        @Override
        protected void onFlush(final int flushIndex, final ATimeSeriesUpdater<String, FDate>.UpdateProgress updateProgress) {
            try {
                if (loopCheck.check()) {
                    printProgress("Writes", writesStart, updateProgress.getValueCount() * flushIndex, VALUES);
                }
            } catch (final InterruptedException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public Percent getProgress() {
            return null;
        }
    };
    Assertions.checkTrue(updater.update());
    readIterator(table, "Cold", 1);
    readIterator(table, "Warm", READS);
    readGetLatest(table, "Cold", 1);
    readGetLatest(table, "Warm", READS);
}
Also used : ATimeSeriesUpdater(de.invesdwin.context.persistence.timeseriesdb.updater.ATimeSeriesUpdater) ATimeSeriesDB(de.invesdwin.context.persistence.timeseriesdb.ATimeSeriesDB) Instant(de.invesdwin.util.time.Instant) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.FDate) Test(org.junit.jupiter.api.Test)

Example 59 with Instant

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

the class InfluxDBPerformanceTest method testInfluxDbPerformanceSync.

@Test
public void testInfluxDbPerformanceSync() throws Exception {
    final int freeHttpPort = Network.getFreeServerPort();
    final int freeUdpPort = Network.getFreeServerPort();
    final InfluxServer server = startInfluxDB(freeHttpPort, freeUdpPort);
    server.start();
    try {
        Thread.sleep(10 * 1000);
        final String dbname = "influxDbPerformance";
        final String policyname = "defaultPolicy";
        final String measurementName = "measurementsPerformance";
        final InfluxDB influxDB = InfluxDBFactory.connect("http://localhost:" + freeHttpPort);
        influxDB.createDatabase(dbname);
        influxDB.createRetentionPolicy(policyname, dbname, "9999d", 1, true);
        BatchPoints batch = BatchPoints.database(dbname).retentionPolicy(policyname).build();
        final Instant writesStart = new Instant();
        int i = 0;
        for (final FDate date : newValues()) {
            final Point point = Point.measurement(measurementName).time(date.millisValue(), TimeUnit.MILLISECONDS).tag("hashKey", HASH_KEY).addField("value", date.millisValue()).build();
            batch.point(point);
            i++;
            if (i % FLUSH_INTERVAL == 0) {
                printProgress("Writes", writesStart, i, VALUES);
                influxDB.write(batch);
                batch = BatchPoints.database(dbname).retentionPolicy(policyname).build();
            }
        }
        influxDB.write(batch);
        batch = null;
        printProgress("WritesFinished", writesStart, VALUES, VALUES);
        readIterator(dbname, measurementName, influxDB);
    } finally {
        server.stop();
    }
}
Also used : BatchPoints(org.influxdb.dto.BatchPoints) InfluxDB(org.influxdb.InfluxDB) Instant(de.invesdwin.util.time.Instant) InfluxServer(io.apisense.embed.influx.InfluxServer) ProcessedEventsRateString(de.invesdwin.util.lang.ProcessedEventsRateString) Point(org.influxdb.dto.Point) Point(org.influxdb.dto.Point) FDate(de.invesdwin.util.time.date.FDate) ATest(de.invesdwin.context.test.ATest) Test(org.junit.jupiter.api.Test)

Example 60 with Instant

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

the class DerbyPerformanceTest 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 v FROM abc WHERE k <=? ORDER BY k DESC fetch first 1 rows only")) {
            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