Search in sources :

Example 1 with ReaderFactory

use of com.questdb.store.factory.ReaderFactory in project questdb by bluestreak01.

the class PerformanceTest method testJournalAppendAndReadSpeed.

@Test
public void testJournalAppendAndReadSpeed() throws JournalException, ParserException, NumericException {
    int count = 10;
    long t = 0;
    long result;
    try (JournalWriter<Quote> w = getFactory().writer(Quote.class, "quote", TEST_DATA_SIZE)) {
        for (int i = -count; i < count; i++) {
            w.truncate();
            if (i == 0) {
                t = System.nanoTime();
            }
            TestUtils.generateQuoteData(w, TEST_DATA_SIZE, DateFormatUtils.parseDateTime("2013-10-05T10:00:00.000Z"), 1000);
            w.commit();
        }
        result = System.nanoTime() - t;
        LOG.info().$("append (1M): ").$(TimeUnit.NANOSECONDS.toMillis(result / count)).$("ms").$();
        if (enabled) {
            Assert.assertTrue("Append speed must be under 400ms (" + TimeUnit.NANOSECONDS.toMillis(result) + ")", TimeUnit.NANOSECONDS.toMillis(result) < 400);
        }
        for (int i = -count; i < count; i++) {
            if (i == 0) {
                t = System.nanoTime();
            }
            Iterator<Quote> iterator = JournalIterators.bufferedIterator(w);
            int cnt = 0;
            while (iterator.hasNext()) {
                iterator.next();
                cnt++;
            }
            Assert.assertEquals(TEST_DATA_SIZE, cnt);
        }
        result = System.nanoTime() - t;
        LOG.info().$("read (1M): ").$(TimeUnit.NANOSECONDS.toMillis(result / count)).$("ms").$();
        if (enabled) {
            Assert.assertTrue("Read speed must be under 120ms (" + TimeUnit.NANOSECONDS.toMillis(result) + ")", TimeUnit.NANOSECONDS.toMillis(result) < 120);
        }
    }
    ReaderFactory readerFactory = getFactory();
    try (RecordSource rs = compile("quote")) {
        for (int i = -count; i < count; i++) {
            if (i == 0) {
                t = System.nanoTime();
            }
            RecordCursor s = rs.prepareCursor(readerFactory);
            try {
                int cnt = 0;
                for (Record r : s) {
                    r.getLong(0);
                    r.getSym(1);
                    r.getDouble(2);
                    r.getDouble(3);
                    r.getInt(4);
                    r.getInt(5);
                    r.getSym(6);
                    r.getSym(7);
                    cnt++;
                }
                Assert.assertEquals(TEST_DATA_SIZE, cnt);
            } finally {
                s.releaseCursor();
            }
        }
    }
    result = System.nanoTime() - t;
    LOG.info().$("generic read (1M): ").$(TimeUnit.NANOSECONDS.toMillis(result / count)).$("ms").$();
    if (enabled) {
        Assert.assertTrue("Read speed must be under 60ms (" + TimeUnit.NANOSECONDS.toMillis(result) + ")", TimeUnit.NANOSECONDS.toMillis(result) < 60);
    }
}
Also used : Quote(com.questdb.model.Quote) RecordSource(com.questdb.ql.RecordSource) ReaderFactory(com.questdb.store.factory.ReaderFactory) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Aggregations

Quote (com.questdb.model.Quote)1 RecordSource (com.questdb.ql.RecordSource)1 ReaderFactory (com.questdb.store.factory.ReaderFactory)1 AbstractTest (com.questdb.test.tools.AbstractTest)1 Test (org.junit.Test)1