use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.
the class PersistentChronicleMapPerformanceTest method readIterator.
private void readIterator(final APersistentMap<FDate, FDate> table) {
final Instant readsStart = new Instant();
for (int reads = 1; reads <= READS; reads++) {
// FDate prevValue = null;
final Iterator<FDate> range = table.values().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(count, VALUES);
printProgress("Reads", readsStart, VALUES * reads, VALUES * READS);
}
printProgress("ReadsFinished", readsStart, VALUES * READS, VALUES * READS);
}
use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.
the class CqenginePerformanceTest method readGetLatest.
private void readGetLatest(final IndexedCollection<Content> 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 = 0; reads < READS; reads++) {
FDate prevValue = null;
int count = 0;
for (int i = 0; i < values.size(); i++) {
try (ResultSet<Content> result = table.retrieve(QueryFactory.lessThanOrEqualTo(Content.KEY, values.get(i).millisValue()), QueryFactory.queryOptions(QueryFactory.orderBy(QueryFactory.descending(Content.KEY)), QueryFactory.applyThresholds(QueryFactory.threshold(EngineThresholds.INDEX_ORDERING_SELECTIVITY, 1.0))))) {
final Iterator<Content> iterator = result.iterator();
final FDate value = iterator.next().getValue();
if (prevValue != null) {
Assertions.checkTrue(prevValue.isBefore(value));
}
prevValue = value;
count++;
}
}
Assertions.checkEquals(count, VALUES);
if (loopCheck.check()) {
printProgress("GetLatests", readsStart, VALUES * reads, VALUES * READS);
}
}
printProgress("GetLatestsFinished", readsStart, VALUES * READS, VALUES * READS);
}
use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.
the class CqenginePerformanceTest method readOrderedIndex.
private void readOrderedIndex(final NavigableIndex<Long, Content> index) throws InterruptedException {
final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
final Instant readsStart = new Instant();
for (int reads = 0; reads < READS; reads++) {
FDate prevValue = null;
int count = 0;
final CloseableIterable<KeyValue<Long, Content>> result = index.getKeysAndValues(QueryFactory.noQueryOptions());
try (CloseableIterator<KeyValue<Long, Content>> it = result.iterator()) {
try {
while (it.hasNext()) {
final FDate value = it.next().getValue().getValue();
if (prevValue != null) {
Assertions.checkTrue(prevValue.isBefore(value));
}
prevValue = value;
count++;
}
} catch (final NoSuchElementException e) {
// end reached
}
}
Assertions.checkEquals(count, VALUES);
if (loopCheck.check()) {
printProgress("ReadOrderedIndexs", readsStart, VALUES * reads, VALUES * READS);
}
}
printProgress("ReadOrderedIndexsFinished", readsStart, VALUES * READS, VALUES * READS);
}
use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.
the class CqenginePerformanceTest method readGetLatestIndex.
private void readGetLatestIndex(final NavigableIndex<Long, Content> index) 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 = 0; reads < READS; reads++) {
FDate prevValue = null;
int count = 0;
for (int i = 0; i < values.size(); i++) {
final CloseableIterable<KeyValue<Long, Content>> result = index.getKeysAndValuesDescending(Long.MIN_VALUE, true, values.get(i).millisValue(), true, QueryFactory.noQueryOptions());
try (CloseableIterator<KeyValue<Long, Content>> it = result.iterator()) {
final FDate value = it.next().getValue().getValue();
if (prevValue != null) {
Assertions.checkTrue(prevValue.isBefore(value));
}
prevValue = value;
count++;
}
}
Assertions.checkEquals(count, VALUES);
if (loopCheck.check()) {
printProgress("GetLatestIndexs", readsStart, VALUES * reads, VALUES * READS);
}
}
printProgress("GetLatestIndexsFinished", readsStart, VALUES * READS, VALUES * READS);
}
use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.
the class CqenginePerformanceTest method testCqenginePerformance.
@Test
public void testCqenginePerformance() throws InterruptedException, IOException {
final File folder = new File(ContextProperties.getCacheDirectory(), CqenginePerformanceTest.class.getSimpleName());
final File file = new File(folder, "table.db");
Files.deleteNative(folder);
Files.forceMkdir(folder);
final DiskPersistence<Content, Long> persistence = DiskPersistence.onPrimaryKeyInFile(Content.KEY, file);
// final OffHeapPersistence<Content, Long> persistence = OffHeapPersistence.onPrimaryKey(Content.KEY);
// final OnHeapPersistence<Content, Long> persistence = OnHeapPersistence.onPrimaryKey(Content.KEY);
final IndexedCollection<Content> table = new ConcurrentIndexedCollection<Content>(persistence);
final NavigableIndex<Long, Content> navigableIndex = NavigableIndex.onAttribute(Content.KEY);
// NavigableIndex<Long, Content> navigableIndex = NavigableIndex.withQuantizerOnAttribute(LongQuantizer.withCompressionFactor(5), KeyValue.KEY);
table.addIndex(navigableIndex);
table.addIndex(UniqueIndex.onAttribute(Content.KEY));
final Instant writesStart = new Instant();
final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck();
int i = 0;
final List<Content> flushable = new ArrayList<>();
for (final FDate date : newValues()) {
flushable.add(new Content(date.millisValue(), date));
i++;
if (i % FLUSH_INTERVAL == 0) {
table.addAll(flushable);
flushable.clear();
if (loopCheck.check()) {
printProgress("Writes", writesStart, i, VALUES);
}
}
}
if (!flushable.isEmpty()) {
table.addAll(flushable);
}
persistence.compact();
printProgress("WritesFinished", writesStart, VALUES, VALUES);
readIterator(table);
readOrdered(table);
readOrderedIndex(navigableIndex);
readGet(table);
readGetLatest(table);
readGetLatestIndex(navigableIndex);
table.clear();
}
Aggregations