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;
}
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);
}
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);
}
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();
}
}
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);
}
Aggregations