Search in sources :

Example 6 with CairoEngine

use of io.questdb.cairo.CairoEngine in project questdb by bluestreak01.

the class TelemetryTest method testTelemetryStoresUpAndDownEvents.

@Test
public void testTelemetryStoresUpAndDownEvents() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (CairoEngine engine = new CairoEngine(configuration)) {
            TelemetryJob telemetryJob = new TelemetryJob(engine);
            Misc.free(telemetryJob);
            final String expectedEvent = "100\n" + "101\n";
            assertColumn(expectedEvent, 1);
            final String expectedOrigin = "1\n" + "1\n";
            assertColumn(expectedOrigin, 2);
        }
    });
}
Also used : CairoEngine(io.questdb.cairo.CairoEngine) Test(org.junit.Test) AbstractCairoTest(io.questdb.cairo.AbstractCairoTest)

Example 7 with CairoEngine

use of io.questdb.cairo.CairoEngine in project questdb by bluestreak01.

the class LatestByParallelTest method execute.

protected static void execute(@Nullable WorkerPool pool, LatestByRunnable runnable, CairoConfiguration configuration) throws Exception {
    final int workerCount = pool == null ? 1 : pool.getWorkerCount();
    try (final CairoEngine engine = new CairoEngine(configuration);
        final SqlCompiler compiler = new SqlCompiler(engine)) {
        try (final SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, workerCount)) {
            try {
                if (pool != null) {
                    pool.assignCleaner(Path.CLEANER);
                    pool.assign(new LatestByAllIndexedJob(engine.getMessageBus()));
                    pool.start(LOG);
                }
                runnable.run(engine, compiler, sqlExecutionContext);
                Assert.assertEquals(0, engine.getBusyWriterCount());
                Assert.assertEquals(0, engine.getBusyReaderCount());
            } finally {
                if (pool != null) {
                    pool.halt();
                }
            }
        }
    }
}
Also used : CairoEngine(io.questdb.cairo.CairoEngine) LatestByAllIndexedJob(io.questdb.griffin.engine.table.LatestByAllIndexedJob)

Example 8 with CairoEngine

use of io.questdb.cairo.CairoEngine in project invesdwin-context-persistence by subes.

the class QuestDBPerformanceTest method testQuestDbPerformance.

@Test
public void testQuestDbPerformance() throws InterruptedException, SqlException, IOException {
    final File directory = new File(ContextProperties.getCacheDirectory(), QuestDBPerformanceTest.class.getSimpleName());
    Files.deleteNative(directory);
    Files.forceMkdir(directory);
    final CairoConfiguration configuration = new DefaultCairoConfiguration(directory.getAbsolutePath());
    final Instant writesStart = new Instant();
    int i = 0;
    final CairoEngine engine = new CairoEngine(configuration);
    final SqlExecutionContextImpl ctx = new SqlExecutionContextImpl(engine, 1);
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    try (SqlCompiler compiler = new SqlCompiler(engine)) {
        compiler.compile("create table abc (value long, key timestamp) timestamp(key)", ctx);
        try (TableWriter writer = engine.getWriter(ctx.getCairoSecurityContext(), "abc", "insert")) {
            for (final FDate date : newValues()) {
                final TableWriter.Row row = writer.newRow(date.millisValue());
                row.putLong(0, date.millisValue());
                row.append();
                i++;
                if (i % FLUSH_INTERVAL == 0) {
                    if (loopCheck.check()) {
                        printProgress("Writes", writesStart, i, VALUES);
                    }
                    writer.commit();
                }
            }
            writer.commit();
        }
        printProgress("WritesFinished", writesStart, VALUES, VALUES);
    }
    readIterator(engine);
    readGet(engine);
    readGetLatest(engine);
    try (SqlCompiler compiler = new SqlCompiler(engine)) {
        compiler.compile("dtop table 'abc';", ctx);
    }
    engine.close();
    Files.deleteNative(directory);
}
Also used : SqlCompiler(io.questdb.griffin.SqlCompiler) Instant(de.invesdwin.util.time.Instant) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.FDate) SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) TableWriter(io.questdb.cairo.TableWriter) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) CairoEngine(io.questdb.cairo.CairoEngine) File(java.io.File) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) CairoConfiguration(io.questdb.cairo.CairoConfiguration) Test(org.junit.jupiter.api.Test)

Example 9 with CairoEngine

use of io.questdb.cairo.CairoEngine in project questdb by bluestreak01.

the class HttpMinTestBuilder method run.

public void run(HttpQueryTestBuilder.HttpClientCode code) throws Exception {
    final int[] workerAffinity = new int[1];
    Arrays.fill(workerAffinity, -1);
    assertMemoryLeak(() -> {
        final String baseDir = temp.getRoot().getAbsolutePath();
        final DefaultHttpServerConfiguration httpConfiguration = new HttpServerConfigurationBuilder().withBaseDir(temp.getRoot().getAbsolutePath()).build();
        final WorkerPool workerPool = new WorkerPool(new WorkerPoolConfiguration() {

            @Override
            public int[] getWorkerAffinity() {
                return workerAffinity;
            }

            @Override
            public int getWorkerCount() {
                return workerAffinity.length;
            }

            @Override
            public boolean haltOnError() {
                return false;
            }
        });
        DefaultCairoConfiguration cairoConfiguration = new DefaultCairoConfiguration(baseDir);
        try (CairoEngine engine = new CairoEngine(cairoConfiguration);
            HttpServer httpServer = new HttpServer(httpConfiguration, workerPool, false)) {
            httpServer.bind(new HttpRequestProcessorFactory() {

                @Override
                public HttpRequestProcessor newInstance() {
                    return new PrometheusMetricsProcessor(metrics);
                }

                @Override
                public String getUrl() {
                    return "/metrics";
                }
            });
            QueryCache.configure(httpConfiguration);
            workerPool.start(LOG);
            try {
                code.run(engine);
            } finally {
                workerPool.halt();
            }
        }
    });
}
Also used : WorkerPool(io.questdb.mp.WorkerPool) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) PrometheusMetricsProcessor(io.questdb.cutlass.http.processors.PrometheusMetricsProcessor) CairoEngine(io.questdb.cairo.CairoEngine) WorkerPoolConfiguration(io.questdb.mp.WorkerPoolConfiguration)

Example 10 with CairoEngine

use of io.questdb.cairo.CairoEngine in project questdb by bluestreak01.

the class HttpQueryTestBuilder method run.

public void run(CairoConfiguration configuration, HttpClientCode code) throws Exception {
    final int[] workerAffinity = new int[workerCount];
    Arrays.fill(workerAffinity, -1);
    assertMemoryLeak(() -> {
        final String baseDir = temp.getRoot().getAbsolutePath();
        final DefaultHttpServerConfiguration httpConfiguration = serverConfigBuilder.withBaseDir(baseDir).build();
        final WorkerPool workerPool = new WorkerPool(new WorkerPoolConfiguration() {

            @Override
            public int[] getWorkerAffinity() {
                return workerAffinity;
            }

            @Override
            public int getWorkerCount() {
                return workerCount;
            }

            @Override
            public boolean haltOnError() {
                return false;
            }
        });
        if (workerCount > 1) {
            workerPool.assignCleaner(Path.CLEANER);
        }
        CairoConfiguration cairoConfiguration = configuration;
        if (cairoConfiguration == null) {
            cairoConfiguration = new DefaultCairoConfiguration(baseDir);
        }
        try (CairoEngine engine = new CairoEngine(cairoConfiguration);
            HttpServer httpServer = new HttpServer(httpConfiguration, workerPool, false)) {
            TelemetryJob telemetryJob = null;
            if (telemetry) {
                telemetryJob = new TelemetryJob(engine);
            }
            httpServer.bind(new HttpRequestProcessorFactory() {

                @Override
                public HttpRequestProcessor newInstance() {
                    return new StaticContentProcessor(httpConfiguration);
                }

                @Override
                public String getUrl() {
                    return HttpServerConfiguration.DEFAULT_PROCESSOR_URL;
                }
            });
            httpServer.bind(new HttpRequestProcessorFactory() {

                @Override
                public HttpRequestProcessor newInstance() {
                    return textImportProcessor != null ? textImportProcessor.create(httpConfiguration.getJsonQueryProcessorConfiguration(), engine, workerPool.getWorkerCount()) : new TextImportProcessor(engine);
                }

                @Override
                public String getUrl() {
                    return "/upload";
                }
            });
            httpServer.bind(new HttpRequestProcessorFactory() {

                @Override
                public HttpRequestProcessor newInstance() {
                    return new JsonQueryProcessor(httpConfiguration.getJsonQueryProcessorConfiguration(), engine, workerPool.getWorkerCount(), Metrics.enabled());
                }

                @Override
                public String getUrl() {
                    return "/query";
                }
            });
            httpServer.bind(new HttpRequestProcessorFactory() {

                @Override
                public HttpRequestProcessor newInstance() {
                    return new TextQueryProcessor(httpConfiguration.getJsonQueryProcessorConfiguration(), engine, workerPool.getWorkerCount());
                }

                @Override
                public String getUrl() {
                    return "/exp";
                }
            });
            httpServer.bind(new HttpRequestProcessorFactory() {

                @Override
                public HttpRequestProcessor newInstance() {
                    return new TableStatusCheckProcessor(engine, httpConfiguration.getJsonQueryProcessorConfiguration());
                }

                @Override
                public String getUrl() {
                    return "/chk";
                }
            });
            httpServer.bind(new HttpRequestProcessorFactory() {

                @Override
                public HttpRequestProcessor newInstance() {
                    return new JsonQueryProcessor(httpConfiguration.getJsonQueryProcessorConfiguration(), engine, 1, Metrics.enabled());
                }

                @Override
                public String getUrl() {
                    return "/exec";
                }
            });
            QueryCache.configure(httpConfiguration);
            workerPool.start(LOG);
            try {
                code.run(engine);
            } finally {
                workerPool.halt();
                if (telemetryJob != null) {
                    Misc.free(telemetryJob);
                }
            }
        }
    });
}
Also used : TelemetryJob(io.questdb.TelemetryJob) WorkerPool(io.questdb.mp.WorkerPool) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) CairoEngine(io.questdb.cairo.CairoEngine) WorkerPoolConfiguration(io.questdb.mp.WorkerPoolConfiguration) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) CairoConfiguration(io.questdb.cairo.CairoConfiguration)

Aggregations

CairoEngine (io.questdb.cairo.CairoEngine)15 DefaultCairoConfiguration (io.questdb.cairo.DefaultCairoConfiguration)9 CairoConfiguration (io.questdb.cairo.CairoConfiguration)7 SqlCompiler (io.questdb.griffin.SqlCompiler)7 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)7 Test (org.junit.Test)7 AbstractCairoTest (io.questdb.cairo.AbstractCairoTest)5 TableWriter (io.questdb.cairo.TableWriter)3 SqlExecutionContext (io.questdb.griffin.SqlExecutionContext)3 WorkerPool (io.questdb.mp.WorkerPool)3 WorkerPoolConfiguration (io.questdb.mp.WorkerPoolConfiguration)3 Record (io.questdb.cairo.sql.Record)2 RecordCursor (io.questdb.cairo.sql.RecordCursor)2 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)2 File (java.io.File)2 IOException (java.io.IOException)2 BeforeClass (org.junit.BeforeClass)2 LoopInterruptedCheck (de.invesdwin.util.concurrent.loop.LoopInterruptedCheck)1 Instant (de.invesdwin.util.time.Instant)1 FDate (de.invesdwin.util.time.date.FDate)1