use of de.invesdwin.util.concurrent.loop.LoopInterruptedCheck 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.concurrent.loop.LoopInterruptedCheck 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.concurrent.loop.LoopInterruptedCheck 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);
}
use of de.invesdwin.util.concurrent.loop.LoopInterruptedCheck in project invesdwin-context-persistence by subes.
the class ADelegateDailyDownloadRangeTableRequest 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);
}
}
}
}
use of de.invesdwin.util.concurrent.loop.LoopInterruptedCheck in project invesdwin-context-persistence by subes.
the class PersistentEzdbPerformanceTest method testPersistentEzdbPerformance.
@Test
public void testPersistentEzdbPerformance() throws InterruptedException {
@SuppressWarnings("resource") final APersistentMap<FDate, FDate> table = new APersistentMap<FDate, FDate>("testPersistentEzdbPerformance") {
@Override
public File getBaseDirectory() {
return ContextProperties.TEMP_DIRECTORY;
}
@Override
public ISerde<FDate> newKeySerde() {
return FDateSerde.GET;
}
@Override
public ISerde<FDate> newValueSerde() {
return FDateSerde.GET;
}
@Override
protected IPersistentMapFactory<FDate, FDate> newFactory() {
return new PersistentEzdbMapFactory<>();
}
};
final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
final Instant writesStart = new Instant();
int i = 0;
for (final FDate date : newValues()) {
table.put(date, date);
i++;
if (i % FLUSH_INTERVAL == 0) {
if (loopCheck.check()) {
printProgress("Writes", writesStart, i, VALUES);
}
}
}
printProgress("WritesFinished", writesStart, VALUES, VALUES);
readIterator(table);
readGet(table);
table.deleteTable();
}
Aggregations