Search in sources :

Example 21 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class JournalServerAgentTest method testIncrementalInteraction.

@Test
public void testIncrementalInteraction() throws Exception {
    try (JournalWriter<Quote> origin = getFactory().writer(Quote.class, "origin")) {
        TestUtils.generateQuoteData(origin, 200);
        server.start();
        try (JournalWriter<Quote> quoteClientWriter = getFactory().writer(Quote.class, "client")) {
            JournalDeltaConsumer quoteDeltaConsumer = new JournalDeltaConsumer(quoteClientWriter);
            // send quote journal key
            commandProducer.write(channel, Command.ADD_KEY_CMD);
            setKeyRequestProducer.write(channel, new IndexedJournalKey(0, quoteWriter.getMetadata().getKey()));
            agent.process(channel);
            charSequenceResponseConsumer.read(channel);
            TestUtils.assertEquals("OK", charSequenceResponseConsumer.getValue());
            hugeBufferConsumer.read(channel);
            // send quote state
            commandProducer.write(channel, Command.DELTA_REQUEST_CMD);
            journalClientStateProducer.write(channel, new IndexedJournal(0, quoteClientWriter));
            agent.process(channel);
            charSequenceResponseConsumer.read(channel);
            TestUtils.assertEquals("OK", charSequenceResponseConsumer.getValue());
            quoteWriter.append(origin.query().all().asResultSet().subset(0, 100));
            quoteWriter.commit();
            commandProducer.write(channel, Command.CLIENT_READY_CMD);
            agent.process(channel);
            commandConsumer.read(channel);
            Assert.assertEquals(Command.JOURNAL_DELTA_CMD, commandConsumer.getCommand());
            Assert.assertEquals(0, intResponseConsumer.getValue(channel));
            quoteDeltaConsumer.read(channel);
            Assert.assertEquals(100, quoteClientWriter.size());
            commandConsumer.read(channel);
            Assert.assertEquals(Command.SERVER_READY_CMD, commandConsumer.getCommand());
            quoteWriter.append(origin.query().all().asResultSet().subset(100, 200));
            quoteWriter.commit();
            // send quote state
            commandProducer.write(channel, Command.DELTA_REQUEST_CMD);
            journalClientStateProducer.write(channel, new IndexedJournal(0, quoteClientWriter));
            agent.process(channel);
            charSequenceResponseConsumer.read(channel);
            TestUtils.assertEquals("OK", charSequenceResponseConsumer.getValue());
            commandProducer.write(channel, Command.CLIENT_READY_CMD);
            agent.process(channel);
            commandConsumer.read(channel);
            Assert.assertEquals(Command.JOURNAL_DELTA_CMD, commandConsumer.getCommand());
            Assert.assertEquals(0, intResponseConsumer.getValue(channel));
            quoteDeltaConsumer.read(channel);
            Assert.assertEquals(200, quoteClientWriter.size());
            commandConsumer.read(channel);
            Assert.assertEquals(Command.SERVER_READY_CMD, commandConsumer.getCommand());
        }
    }
}
Also used : Quote(com.questdb.model.Quote) JournalDeltaConsumer(com.questdb.net.ha.comsumer.JournalDeltaConsumer) IndexedJournalKey(com.questdb.net.ha.model.IndexedJournalKey) IndexedJournal(com.questdb.net.ha.model.IndexedJournal) AbstractTest(com.questdb.test.tools.AbstractTest)

Example 22 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class PerformanceTest method testAllBySymbolValueOverInterval.

@Test
public void testAllBySymbolValueOverInterval() throws JournalException, NumericException {
    try (JournalWriter<Quote> w = getFactory().writer(Quote.class, null, TEST_DATA_SIZE)) {
        TestUtils.generateQuoteData(w, TEST_DATA_SIZE, DateFormatUtils.parseDateTime("2013-10-05T10:00:00.000Z"), 1000);
        w.commit();
    }
    try (Journal<Quote> journal = getFactory().reader(Quote.class)) {
        int count = 1000;
        Interval interval = new Interval(DateFormatUtils.parseDateTime("2013-10-15T10:00:00.000Z"), DateFormatUtils.parseDateTime("2013-10-05T10:00:00.000Z"));
        long t = 0;
        QueryAllBuilder<Quote> builder = journal.query().all().withKeys("LLOY.L").slice(interval);
        for (int i = -1000; i < count; i++) {
            if (i == 0) {
                t = System.nanoTime();
            }
            builder.asResultSet();
        }
        LOG.info().$("journal.query().all().withKeys(\"LLOY.L\").slice(interval) (query only) latency: ").$((System.nanoTime() - t) / count / 1000).$("μs").$();
    }
}
Also used : Quote(com.questdb.model.Quote) Interval(com.questdb.std.time.Interval) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 23 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class PerformanceTest method testAllBySymbolValueOverIntervalNew.

@SuppressWarnings("StatementWithEmptyBody")
@Test
public void testAllBySymbolValueOverIntervalNew() throws JournalException, ParserException, NumericException {
    try (JournalWriter<Quote> w = getFactory().writer(Quote.class, "quote", TEST_DATA_SIZE)) {
        TestUtils.generateQuoteData(w, TEST_DATA_SIZE, DateFormatUtils.parseDateTime("2013-10-05T10:00:00.000Z"), 1000);
        w.commit();
    }
    QueryCompiler compiler = new QueryCompiler();
    Factory factory = getFactory();
    try (RecordSource src = compiler.compile(factory, "quote where timestamp = '2013-10-05T10:00:00.000Z;10d' and sym = 'LLOY.L'")) {
        int count = 1000;
        long t = 0;
        for (int i = -count; i < count; i++) {
            if (i == 0) {
                t = System.nanoTime();
            }
            RecordCursor c = src.prepareCursor(factory);
            try {
                for (; c.hasNext(); ) {
                    c.next();
                }
            } finally {
                c.releaseCursor();
            }
        }
        LOG.info().$("NEW journal.query().all().withKeys(\"LLOY.L\").slice(interval) (query only) latency: ").$((System.nanoTime() - t) / count / 1000).$("μs").$();
    }
}
Also used : Quote(com.questdb.model.Quote) RecordSource(com.questdb.ql.RecordSource) Factory(com.questdb.store.factory.Factory) LogFactory(com.questdb.log.LogFactory) ReaderFactory(com.questdb.store.factory.ReaderFactory) QueryCompiler(com.questdb.parser.sql.QueryCompiler) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 24 with Quote

use of com.questdb.model.Quote 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)

Example 25 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class BulkTest method testDurable.

@Test
public void testDurable() throws Exception {
    final int batchSize = 100000;
    final int iterations = 10;
    try (JournalWriter<Quote> writer = getFactory().writer(Quote.class)) {
        try (Journal<Quote> reader = getFactory().reader(Quote.class)) {
            reader.setSequentialAccess(true);
            long start = System.currentTimeMillis();
            long p = 10L * 24L * 60L * 60L * 1000L;
            for (int i = 0; i < iterations; i++) {
                TestUtils.generateQuoteData(writer, batchSize, start, p / batchSize);
                writer.commitDurable();
                start += p;
            }
            Assert.assertTrue(reader.refresh());
            long count = 0;
            for (Quote q : JournalIterators.bufferedIterator(reader)) {
                assert q != null;
                count++;
            }
            Assert.assertEquals(batchSize * iterations, count);
        }
    }
}
Also used : Quote(com.questdb.model.Quote) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Aggregations

Quote (com.questdb.model.Quote)80 Test (org.junit.Test)64 AbstractTest (com.questdb.test.tools.AbstractTest)63 ClientConfig (com.questdb.net.ha.config.ClientConfig)20 CountDownLatch (java.util.concurrent.CountDownLatch)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 JournalException (com.questdb.std.ex.JournalException)11 ServerConfig (com.questdb.net.ha.config.ServerConfig)10 ArrayList (java.util.ArrayList)9 Interval (com.questdb.std.time.Interval)8 InputStream (java.io.InputStream)6 JournalConfigurationBuilder (com.questdb.store.factory.configuration.JournalConfigurationBuilder)5 File (java.io.File)5 JournalListener (com.questdb.store.JournalListener)4 ServerNode (com.questdb.net.ha.config.ServerNode)3 RecordSource (com.questdb.ql.RecordSource)3 Rnd (com.questdb.std.Rnd)3 StringSink (com.questdb.std.str.StringSink)3 Ignore (org.junit.Ignore)3 NumericException (com.questdb.common.NumericException)2