Search in sources :

Example 1 with ConcurrentIndexedCollection

use of com.googlecode.cqengine.ConcurrentIndexedCollection 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();
}
Also used : ConcurrentIndexedCollection(com.googlecode.cqengine.ConcurrentIndexedCollection) Instant(de.invesdwin.util.time.Instant) ArrayList(java.util.ArrayList) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.FDate) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

ConcurrentIndexedCollection (com.googlecode.cqengine.ConcurrentIndexedCollection)1 LoopInterruptedCheck (de.invesdwin.util.concurrent.loop.LoopInterruptedCheck)1 Instant (de.invesdwin.util.time.Instant)1 FDate (de.invesdwin.util.time.date.FDate)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1