Search in sources :

Example 71 with Rnd

use of io.questdb.std.Rnd in project questdb by bluestreak01.

the class MinFloatGroupByFunctionFactoryTest method testFirstNull.

@Test
public void testFirstNull() throws SqlException {
    compiler.compile("create table tab (f float)", sqlExecutionContext);
    final Rnd rnd = new Rnd();
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
        TableWriter.Row r = w.newRow();
        r.append();
        for (int i = 100; i > 10; i--) {
            r = w.newRow();
            r.putFloat(0, rnd.nextFloat());
            r.append();
        }
        w.commit();
    }
    try (RecordCursorFactory factory = compiler.compile("select min(f) from tab", sqlExecutionContext).getRecordCursorFactory()) {
        try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
            Record record = cursor.getRecord();
            Assert.assertEquals(1, cursor.size());
            Assert.assertTrue(cursor.hasNext());
            Assert.assertEquals(0.0011075139045715332, record.getFloat(0), 0.0001);
        }
    }
}
Also used : TableWriter(io.questdb.cairo.TableWriter) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Rnd(io.questdb.std.Rnd) Record(io.questdb.cairo.sql.Record) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Example 72 with Rnd

use of io.questdb.std.Rnd in project questdb by bluestreak01.

the class PerformanceTest method testCairoPerformance.

@Test
public void testCairoPerformance() throws NumericException {
    int count = 10;
    long t = 0;
    long result;
    String[] symbols = { "AGK.L", "BP.L", "TLW.L", "ABF.L", "LLOY.L", "BT-A.L", "WTB.L", "RRS.L", "ADM.L", "GKN.L", "HSBA.L" };
    try (TableModel model = new TableModel(configuration, "quote", PartitionBy.NONE).timestamp().col("sym", ColumnType.SYMBOL).col("bid", ColumnType.DOUBLE).col("ask", ColumnType.DOUBLE).col("bidSize", ColumnType.INT).col("askSize", ColumnType.INT).col("mode", ColumnType.SYMBOL).symbolCapacity(2).col("ex", ColumnType.SYMBOL).symbolCapacity(2)) {
        CairoTestUtils.create(model);
    }
    try (TableWriter w = new TableWriter(configuration, "quote")) {
        for (int i = -count; i < count; i++) {
            if (i == 0) {
                t = System.nanoTime();
            }
            w.truncate();
            long timestamp = DateFormatUtils.parseUTCDate("2013-10-05T10:00:00.000Z");
            Rnd r = new Rnd();
            int n = symbols.length - 1;
            for (int i1 = 0; i1 < TEST_DATA_SIZE; i1++) {
                TableWriter.Row row = w.newRow(timestamp);
                row.putSym(1, symbols[Math.abs(r.nextInt() % n)]);
                row.putDouble(2, Math.abs(r.nextDouble()));
                row.putDouble(3, Math.abs(r.nextDouble()));
                row.putInt(4, Math.abs(r.nextInt()));
                row.putInt(5, Math.abs(r.nextInt()));
                row.putSym(6, "LXE");
                row.putSym(7, "Fast trading");
                row.append();
                timestamp += 1000;
            }
            w.commit();
        }
        result = System.nanoTime() - t;
    }
    long appendDuration = result / count;
    try (TableReader reader = new TableReader(configuration, "quote")) {
        for (int i = -count; i < count; i++) {
            if (i == 0) {
                t = System.nanoTime();
            }
            RecordCursor cursor = reader.getCursor();
            Record record = cursor.getRecord();
            while (cursor.hasNext()) {
                record.getDate(0);
                record.getSym(1);
                record.getDouble(2);
                record.getDouble(3);
                record.getInt(4);
                record.getInt(5);
                record.getSym(6);
                record.getSym(7);
            }
        }
        result = (System.nanoTime() - t) / count;
    }
    LOG.info().$("Cairo append (1M): ").$(TimeUnit.NANOSECONDS.toMillis(appendDuration)).$("ms").$();
    LOG.info().$("Cairo read (1M): ").$(TimeUnit.NANOSECONDS.toMillis(result)).$("ms").$();
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) Rnd(io.questdb.std.Rnd) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Example 73 with Rnd

use of io.questdb.std.Rnd in project questdb by bluestreak01.

the class PerformanceTest method measureReloadSpeed.

private double measureReloadSpeed(int reloadTableRowCount, int reloadCount, int txCount) throws InterruptedException {
    String[] symbols = { "AGK.L", "BP.L", "TLW.L", "ABF.L", "LLOY.L", "BT-A.L", "WTB.L", "RRS.L", "ADM.L", "GKN.L", "HSBA.L" };
    try (TableModel model = new TableModel(configuration, "quote", PartitionBy.DAY).timestamp().col("sym", ColumnType.SYMBOL).col("bid", ColumnType.DOUBLE).col("ask", ColumnType.DOUBLE).col("bidSize", ColumnType.INT).col("askSize", ColumnType.INT).col("mode", ColumnType.SYMBOL).symbolCapacity(2).col("ex", ColumnType.SYMBOL).symbolCapacity(2)) {
        CairoTestUtils.create(model);
    }
    CountDownLatch stopLatch = new CountDownLatch(2);
    CountDownLatch startLatch = new CountDownLatch(2);
    try (TableWriter w = new TableWriter(configuration, "quote");
        TableReader reader = new TableReader(configuration, "quote")) {
        // Writing
        new Thread(() -> {
            try {
                long timestamp = DateFormatUtils.parseUTCDate("2013-10-05T10:00:00.000Z");
                Rnd r = new Rnd();
                int n = symbols.length - 1;
                int txSize = reloadTableRowCount / txCount;
                startLatch.countDown();
                startLatch.await();
                for (int i = 0; i < txCount; i++) {
                    for (int i1 = 0; i1 < txSize; i1++) {
                        TableWriter.Row row = w.newRow(timestamp);
                        row.putSym(1, symbols[Math.abs(r.nextInt() % n)]);
                        row.putDouble(2, Math.abs(r.nextDouble()));
                        row.putDouble(3, Math.abs(r.nextDouble()));
                        row.putInt(4, Math.abs(r.nextInt()));
                        row.putInt(5, Math.abs(r.nextInt()));
                        row.putSym(6, "LXE");
                        row.putSym(7, "Fast trading");
                        row.append();
                        timestamp += 1000;
                    }
                    LOG.info().$("committing transaction ").$(i).$();
                    w.commit();
                }
            } catch (NumericException | InterruptedException e) {
                e.printStackTrace();
            }
            stopLatch.countDown();
            LOG.info().$("Stopped writing").$();
        }).start();
        // Reload reader
        new Thread(() -> {
            long result = System.nanoTime();
            try {
                startLatch.countDown();
                startLatch.await();
                for (int i = 0; i < reloadCount; i++) {
                    reader.reload();
                    if (reader.getPartitionCount() > 0) {
                        reader.openPartition(0);
                    }
                }
                result = System.nanoTime() - result;
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                stopLatch.countDown();
            }
            timeoutResult = result;
            LOG.info().$("reload done").$();
        }).start();
        if (!stopLatch.await(5000, TimeUnit.MILLISECONDS)) {
            Assert.fail("Wait limit exceeded");
        }
    }
    int million = 1_000_000;
    LOG.info().$("Cairo reload (").$(reloadCount / million).$("M) per operation: ").$(timeoutResult / reloadCount).$("ns").$();
    return (double) timeoutResult / reloadCount;
}
Also used : Rnd(io.questdb.std.Rnd) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 74 with Rnd

use of io.questdb.std.Rnd in project questdb by bluestreak01.

the class LatestByParallelTest method setUp.

@Before
public void setUp() {
    SharedRandom.RANDOM.set(new Rnd());
    TestUtils.createTestPath(root);
}
Also used : Rnd(io.questdb.std.Rnd)

Example 75 with Rnd

use of io.questdb.std.Rnd in project questdb by bluestreak01.

the class O3CommitLagTest method testBigUncommittedMove1.

private void testBigUncommittedMove1(CairoEngine engine, SqlCompiler compiler, SqlExecutionContext sqlExecutionContext, TableModel tableModel) throws NumericException, SqlException {
    // Create empty tables of same structure
    TestUtils.createPopulateTable("o3", compiler, sqlExecutionContext, tableModel, 0, "2021-04-27", 0);
    TestUtils.createPopulateTable("ordered", compiler, sqlExecutionContext, tableModel, 0, "2021-04-27", 0);
    int longColIndex = -1;
    int flotColIndex = -1;
    int strColIndex = -1;
    for (int i = 0; i < tableModel.getColumnCount(); i++) {
        switch(ColumnType.tagOf(tableModel.getColumnType(i))) {
            case ColumnType.LONG:
                longColIndex = i;
                break;
            case ColumnType.FLOAT:
                flotColIndex = i;
                break;
            case ColumnType.STRING:
                strColIndex = i;
                break;
        }
    }
    long start = IntervalUtils.parseFloorPartialDate("2021-04-27T08:00:00");
    long[] testCounts = new long[] { 2 * 1024 * 1024, 16 * 8 * 1024 * 5, 2_000_000 };
    for (int c = 0; c < testCounts.length; c++) {
        long idCount = testCounts[c];
        // Create big commit with has big part before OOO starts
        // which exceed default MAMemoryImpl size in one or all columns
        int iterations = 2;
        String[] varCol = new String[] { "abc", "aldfjkasdlfkj", "as", "2021-04-27T12:00:00", "12345678901234578" };
        // Add 2 batches
        try (TableWriter o3 = engine.getWriter(AllowAllCairoSecurityContext.INSTANCE, "o3", "testing");
            TableWriter ordered = engine.getWriter(AllowAllCairoSecurityContext.INSTANCE, "ordered", "testing")) {
            for (int i = 0; i < iterations; i++) {
                long backwards = iterations - i - 1;
                final Rnd rnd = new Rnd();
                for (int id = 0; id < idCount; id++) {
                    long timestamp = start + backwards * idCount + id;
                    Row row = o3.newRow(timestamp);
                    if (longColIndex > -1) {
                        row.putLong(longColIndex, timestamp);
                    }
                    if (flotColIndex > -1) {
                        row.putFloat(flotColIndex, rnd.nextFloat());
                    }
                    if (strColIndex > -1) {
                        row.putStr(strColIndex, varCol[id % varCol.length]);
                    }
                    row.append();
                    timestamp = start + i * idCount + id;
                    row = ordered.newRow(timestamp);
                    if (longColIndex > -1) {
                        row.putLong(longColIndex, timestamp);
                    }
                    if (flotColIndex > -1) {
                        row.putFloat(flotColIndex, rnd.nextFloat());
                    }
                    if (strColIndex > -1) {
                        row.putStr(strColIndex, varCol[id % varCol.length]);
                    }
                    row.append();
                }
            }
            o3.commit();
            ordered.commit();
        }
        TestUtils.assertSqlCursors(compiler, sqlExecutionContext, "ordered", "o3", LOG);
        engine.releaseAllReaders();
        try (TableWriter o3 = engine.getWriter(AllowAllCairoSecurityContext.INSTANCE, "o3", "testing");
            TableWriter ordered = engine.getWriter(AllowAllCairoSecurityContext.INSTANCE, "ordered", "testing")) {
            o3.truncate();
            ordered.truncate();
        }
    }
}
Also used : Rnd(io.questdb.std.Rnd) Row(io.questdb.cairo.TableWriter.Row)

Aggregations

Rnd (io.questdb.std.Rnd)76 Test (org.junit.Test)49 Record (io.questdb.cairo.sql.Record)32 RecordCursor (io.questdb.cairo.sql.RecordCursor)29 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)28 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)24 TableWriter (io.questdb.cairo.TableWriter)23 Path (io.questdb.std.str.Path)10 RuntimeIntervalModel (io.questdb.griffin.model.RuntimeIntervalModel)4 CyclicBarrier (java.util.concurrent.CyclicBarrier)3 DataFrameCursor (io.questdb.cairo.sql.DataFrameCursor)2 ReaderOutOfDateException (io.questdb.cairo.sql.ReaderOutOfDateException)2 RowCursor (io.questdb.cairo.sql.RowCursor)2 StaticSymbolTable (io.questdb.cairo.sql.StaticSymbolTable)2 LineTcpSender (io.questdb.cutlass.line.LineTcpSender)2 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)2 AbstractFunctionFactoryTest (io.questdb.griffin.engine.AbstractFunctionFactoryTest)2 BinarySequence (io.questdb.std.BinarySequence)2 BytecodeAssembler (io.questdb.std.BytecodeAssembler)2 FilesFacade (io.questdb.std.FilesFacade)2