use of io.questdb.cairo.DefaultCairoConfiguration 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);
}
use of io.questdb.cairo.DefaultCairoConfiguration 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();
}
}
});
}
use of io.questdb.cairo.DefaultCairoConfiguration 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);
}
}
}
});
}
use of io.questdb.cairo.DefaultCairoConfiguration in project questdb by bluestreak01.
the class SecurityTest method setUpReadOnlyExecutionContext.
@BeforeClass
public static void setUpReadOnlyExecutionContext() {
CairoConfiguration readOnlyConfiguration = new DefaultCairoConfiguration(root) {
@Override
public int getSqlMapPageSize() {
return 64;
}
@Override
public int getSqlMapMaxResizes() {
return 2;
}
@Override
public long getSqlSortKeyPageSize() {
return 64;
}
@Override
public int getSqlSortKeyMaxPages() {
return 2;
}
@Override
public int getSqlJoinMetadataPageSize() {
return 64;
}
@Override
public int getSqlJoinMetadataMaxResizes() {
return 10;
}
@Override
public long getSqlSortLightValuePageSize() {
return 1024;
}
@Override
public int getSqlSortLightValueMaxPages() {
return 11;
}
};
memoryRestrictedEngine = new CairoEngine(readOnlyConfiguration);
SqlExecutionInterruptor dummyInterruptor = () -> {
int nCalls = nCheckInterruptedCalls.incrementAndGet();
int max = maxNCheckInterruptedCalls;
if (nCalls > max) {
throw CairoException.instance(0).put("Interrupting SQL processing, max calls is ").put(max);
}
};
readOnlyExecutionContext = new SqlExecutionContextImpl(memoryRestrictedEngine, 1).with(new CairoSecurityContextImpl(false), bindVariableService, null, -1, dummyInterruptor);
memoryRestrictedCompiler = new SqlCompiler(memoryRestrictedEngine);
}
use of io.questdb.cairo.DefaultCairoConfiguration in project questdb by bluestreak01.
the class TelemetryTest method testTelemetryCanDeleteTableWhenDisabled.
@Test
public void testTelemetryCanDeleteTableWhenDisabled() throws Exception {
CairoConfiguration configuration = new DefaultCairoConfiguration(root) {
@Override
public TelemetryConfiguration getTelemetryConfiguration() {
return new DefaultTelemetryConfiguration() {
@Override
public boolean getEnabled() {
return false;
}
};
}
};
TestUtils.assertMemoryLeak(() -> {
try (CairoEngine engine = new CairoEngine(configuration);
SqlCompiler compiler = new SqlCompiler(engine, null);
TelemetryJob ignored = new TelemetryJob(engine);
SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1)) {
try {
compiler.compile("drop table telemetry", sqlExecutionContext);
Assert.fail();
} catch (SqlException e) {
TestUtils.assertContains(e.getFlyweightMessage(), "table 'telemetry' does not exist");
}
}
});
}
Aggregations