Search in sources :

Example 26 with Instant

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

the class MphTablePerformanceTest method readIterator.

private void readIterator(final File file) throws IOException {
    final Instant readsStart = new Instant();
    for (int reads = 1; reads <= READS; reads++) {
        FDate prevValue = null;
        int count = 0;
        try (TableReader<Long, Long> reader = TableReader.open(file)) {
            final Iterator<com.indeed.util.core.Pair<Long, Long>> iterator = reader.iterator();
            while (iterator.hasNext()) {
                final FDate value = new FDate(iterator.next().getSecond());
                // if (prevValue != null) {
                // Assertions.checkTrue(prevValue.isBefore(value));
                // }
                prevValue = value;
                count++;
            }
            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)

Example 27 with Instant

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

the class ADelegateDailyDownloadTableRequest method maybeUpdate.

protected void maybeUpdate() {
    if (shouldUpdate()) {
        synchronized (this) {
            try {
                if (shouldUpdate()) {
                    beforeUpdate();
                    final ICloseableIterator<V> reader = getIterator();
                    final Instant start = new Instant();
                    log.info("Starting indexing [%s] ...", getDownloadFileName());
                    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
                    try (Batch<K, V> batch = table.newBatch()) {
                        int count = 0;
                        try {
                            while (true) {
                                final V value = reader.next();
                                final K key = extractKey(value);
                                batch.put(key, value);
                                count++;
                                if (count >= ADelegateRangeTable.BATCH_FLUSH_INTERVAL) {
                                    batch.flush();
                                    if (loopCheck.check()) {
                                        printProgress("Indexing [" + getDownloadFileName() + "]", start, count);
                                    }
                                }
                            }
                        } catch (final NoSuchElementException e) {
                        // end reached
                        }
                        if (count > 0) {
                            batch.flush();
                        }
                    }
                    afterUpdate();
                    log.info("Finished indexing [%s] after: %s", getDownloadFileName(), start);
                }
            } catch (final Throwable t) {
                deleteDownloadedFile();
                table.deleteTable();
                throw Throwables.propagate(t);
            }
        }
    }
}
Also used : Instant(de.invesdwin.util.time.Instant) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) NoSuchElementException(java.util.NoSuchElementException)

Example 28 with Instant

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

the class ADelegateDailyDownloadTableRequest method getIterator.

public ICloseableIterator<V> getIterator() {
    try {
        final Instant start = new Instant();
        log.info("Starting download [%s] ...", getDownloadFileName());
        final InputStream content = dailyDownloadCache.downloadStream(getDownloadFileName(), new Consumer<OutputStream>() {

            @Override
            public void accept(final OutputStream t) {
                try (InputStream in = download()) {
                    IOUtils.copy(in, t);
                } catch (final Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }, getNow());
        final ICloseableIterator<V> reader = newReader(content);
        log.info("Finished download [%s] after: %s", getDownloadFileName(), start);
        return reader;
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : InputStream(java.io.InputStream) Instant(de.invesdwin.util.time.Instant) OutputStream(java.io.OutputStream) NoSuchElementException(java.util.NoSuchElementException)

Example 29 with Instant

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

the class ChronicleQueuePerformanceTest method testChronicleQueuePerformance.

@Test
public void testChronicleQueuePerformance() {
    final ChronicleQueue queue = SingleChronicleQueueBuilder.binary(new File(ContextProperties.TEMP_CLASSPATH_DIRECTORY, "testLevelDbPerformance")).build();
    final Instant writesStart = new Instant();
    try (ExcerptAppender acquireAppender = queue.acquireAppender()) {
        int i = 0;
        for (final FDate date : newValues()) {
            try (DocumentContext doc = acquireAppender.writingDocument()) {
                doc.wire().bytes().writeLong(date.millisValue());
            }
            i++;
            if (i % FLUSH_INTERVAL == 0) {
                printProgress("Writes", writesStart, i, VALUES);
            }
        }
    }
    printProgress("WritesFinished", writesStart, VALUES, VALUES);
    final Instant readsStart = new Instant();
    for (int reads = 1; reads <= READS; reads++) {
        FDate prevValue = null;
        int count = 0;
        try (ExcerptTailer tailer = queue.createTailer()) {
            final net.openhft.chronicle.bytes.Bytes<java.nio.ByteBuffer> bytes = net.openhft.chronicle.bytes.Bytes.elasticByteBuffer();
            while (tailer.readBytes(bytes)) {
                final FDate value = FDate.valueOf(bytes.readLong());
                if (prevValue != null) {
                    Assertions.checkTrue(prevValue.isBefore(value));
                }
                prevValue = value;
                count++;
            }
            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) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) DocumentContext(net.openhft.chronicle.wire.DocumentContext) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 30 with Instant

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

the class PersistentChronicleMapPerformanceTest method readGet.

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

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