use of io.questdb.mp.WorkerPool in project questdb by bluestreak01.
the class IODispatcherTest method testImportMultipleOnSameConnectionSlow.
@Test
public void testImportMultipleOnSameConnectionSlow() throws Exception {
assertMemoryLeak(() -> {
final String baseDir = temp.getRoot().getAbsolutePath();
final DefaultHttpServerConfiguration httpConfiguration = createHttpServerConfiguration(baseDir, false);
final WorkerPool workerPool = new WorkerPool(new WorkerPoolConfiguration() {
@Override
public int[] getWorkerAffinity() {
return new int[] { -1, -1, -1 };
}
@Override
public int getWorkerCount() {
return 3;
}
@Override
public boolean haltOnError() {
return false;
}
});
try (CairoEngine engine = new CairoEngine(new DefaultCairoConfiguration(baseDir));
HttpServer httpServer = new HttpServer(httpConfiguration, workerPool, false)) {
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 new TextImportProcessor(engine);
}
@Override
public String getUrl() {
return "/upload";
}
});
workerPool.start(LOG);
// send multipart request to server
final String request = "POST /upload HTTP/1.1\r\n" + "Host: localhost:9001\r\n" + "User-Agent: curl/7.64.0\r\n" + "Accept: */*\r\n" + "Content-Length: 437760673\r\n" + "Content-Type: multipart/form-data; boundary=------------------------27d997ca93d2689d\r\n" + "Expect: 100-continue\r\n" + "\r\n" + "--------------------------27d997ca93d2689d\r\n" + "Content-Disposition: form-data; name=\"schema\"; filename=\"schema.json\"\r\n" + "Content-Type: application/octet-stream\r\n" + "\r\n" + "[\r\n" + " {\r\n" + " \"name\": \"date\",\r\n" + " \"type\": \"DATE\",\r\n" + " \"pattern\": \"d MMMM y.\",\r\n" + " \"locale\": \"ru-RU\"\r\n" + " }\r\n" + "]\r\n" + "\r\n" + "--------------------------27d997ca93d2689d\r\n" + "Content-Disposition: form-data; name=\"data\"; filename=\"fhv_tripdata_2017-02.csv\"\r\n" + "Content-Type: application/octet-stream\r\n" + "\r\n" + "Dispatching_base_num,Pickup_DateTime,DropOff_datetime,PUlocationID,DOlocationID\r\n" + "B00008,2017-02-01 00:30:00,,,\r\n" + "B00008,2017-02-01 00:40:00,,,\r\n" + "B00009,2017-02-01 00:30:00,,,\r\n" + "B00013,2017-02-01 00:11:00,,,\r\n" + "B00013,2017-02-01 00:41:00,,,\r\n" + "B00013,2017-02-01 00:00:00,,,\r\n" + "B00013,2017-02-01 00:53:00,,,\r\n" + "B00013,2017-02-01 00:44:00,,,\r\n" + "B00013,2017-02-01 00:05:00,,,\r\n" + "B00013,2017-02-01 00:54:00,,,\r\n" + "B00014,2017-02-01 00:45:00,,,\r\n" + "B00014,2017-02-01 00:45:00,,,\r\n" + "B00014,2017-02-01 00:46:00,,,\r\n" + "B00014,2017-02-01 00:54:00,,,\r\n" + "B00014,2017-02-01 00:45:00,,,\r\n" + "B00014,2017-02-01 00:45:00,,,\r\n" + "B00014,2017-02-01 00:45:00,,,\r\n" + "B00014,2017-02-01 00:26:00,,,\r\n" + "B00014,2017-02-01 00:55:00,,,\r\n" + "B00014,2017-02-01 00:47:00,,,\r\n" + "B00014,2017-02-01 00:05:00,,,\r\n" + "B00014,2017-02-01 00:58:00,,,\r\n" + "B00014,2017-02-01 00:33:00,,,\r\n" + "B00014,2017-02-01 00:45:00,,,\r\n" + "\r\n" + "--------------------------27d997ca93d2689d--";
NetworkFacade nf = new NetworkFacadeImpl() {
int totalSent = 0;
@Override
public int send(long fd, long buffer, int bufferLen) {
if (bufferLen > 0) {
int result = super.send(fd, buffer, 1);
totalSent += result;
if (totalSent > 20) {
LockSupport.parkNanos(10000);
totalSent = 0;
}
return result;
}
return 0;
}
};
try {
sendAndReceive(nf, request, ValidImportResponse, 3, 0, false);
} finally {
workerPool.halt();
}
}
});
}
use of io.questdb.mp.WorkerPool in project questdb by bluestreak01.
the class IODispatcherTest method testJsonQueryWithCompressedResults1.
@Test
public void testJsonQueryWithCompressedResults1() throws Exception {
Zip.init();
assertMemoryLeak(() -> {
final NetworkFacade nf = NetworkFacadeImpl.INSTANCE;
final String baseDir = temp.getRoot().getAbsolutePath();
final DefaultHttpServerConfiguration httpConfiguration = createHttpServerConfiguration(nf, baseDir, 256, false, true);
final WorkerPool workerPool = new WorkerPool(new WorkerPoolConfiguration() {
@Override
public int[] getWorkerAffinity() {
return new int[] { -1, -1 };
}
@Override
public int getWorkerCount() {
return 2;
}
@Override
public boolean haltOnError() {
return false;
}
});
try (CairoEngine engine = new CairoEngine(new DefaultCairoConfiguration(baseDir));
HttpServer httpServer = new HttpServer(httpConfiguration, workerPool, false)) {
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 new JsonQueryProcessor(httpConfiguration.getJsonQueryProcessorConfiguration(), engine, workerPool.getWorkerCount(), metrics);
}
@Override
public String getUrl() {
return "/query";
}
});
workerPool.start(LOG);
try {
// create table with all column types
CairoTestUtils.createTestTable(engine.getConfiguration(), 30, new Rnd(), new TestRecord.ArrayBinarySequence());
// send multipart request to server
final String request = "GET /query?query=x HTTP/1.1\r\n" + "Host: localhost:9001\r\n" + "Connection: keep-alive\r\n" + "Cache-Control: max-age=0\r\n" + "Upgrade-Insecure-Requests: 1\r\n" + "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36\r\n" + "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3\r\n" + "Accept-Encoding: gzip, deflate, br\r\n" + "Accept-Language: en-GB,en-US;q=0.9,en;q=0.8\r\n" + "\r\n";
ByteArrayResponse expectedResponse;
try (InputStream is = getClass().getResourceAsStream(getClass().getSimpleName() + ".testJsonQueryWithCompressedResults1.bin")) {
Assert.assertNotNull(is);
byte[] bytes = new byte[20 * 1024];
int len = is.read(bytes);
expectedResponse = new ByteArrayResponse(bytes, len);
}
sendAndReceive(nf, request, expectedResponse, 10, 100L, false);
} finally {
workerPool.halt();
}
}
});
}
use of io.questdb.mp.WorkerPool in project questdb by bluestreak01.
the class IODispatcherTest method testSCPFullDownload.
@Test
public void testSCPFullDownload() throws Exception {
assertMemoryLeak(() -> {
final String baseDir = temp.getRoot().getAbsolutePath();
final DefaultHttpServerConfiguration httpConfiguration = createHttpServerConfiguration(baseDir, false);
final WorkerPool workerPool = new WorkerPool(new WorkerPoolConfiguration() {
@Override
public int[] getWorkerAffinity() {
return new int[] { -1, -1 };
}
@Override
public int getWorkerCount() {
return 2;
}
@Override
public boolean haltOnError() {
return false;
}
});
try (HttpServer httpServer = new HttpServer(httpConfiguration, workerPool, false)) {
httpServer.bind(new HttpRequestProcessorFactory() {
@Override
public HttpRequestProcessor newInstance() {
return new StaticContentProcessor(httpConfiguration);
}
@Override
public String getUrl() {
return HttpServerConfiguration.DEFAULT_PROCESSOR_URL;
}
});
workerPool.start(LOG);
// create 20Mb file in /tmp directory
try (Path path = new Path().of(baseDir).concat("questdb-temp.txt").$()) {
try {
Rnd rnd = new Rnd();
final int diskBufferLen = 1024 * 1024;
writeRandomFile(path, rnd, 122299092L);
long fd = Net.socketTcp(true);
try {
long sockAddr = Net.sockaddr("127.0.0.1", 9001);
try {
TestUtils.assertConnect(fd, sockAddr);
int netBufferLen = 4 * 1024;
long buffer = Unsafe.calloc(netBufferLen, MemoryTag.NATIVE_DEFAULT);
try {
// send request to server to download file we just created
final String request = "GET /questdb-temp.txt HTTP/1.1\r\n" + "Host: localhost:9000\r\n" + "Connection: keep-alive\r\n" + "Cache-Control: max-age=0\r\n" + "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n" + "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.48 Safari/537.36\r\n" + "Accept-Encoding: gzip,deflate,sdch\r\n" + "Accept-Language: en-US,en;q=0.8\r\n" + "Cookie: textwrapon=false; textautoformat=false; wysiwyg=textarea\r\n" + "\r\n";
String expectedResponseHeader = "HTTP/1.1 200 OK\r\n" + "Server: questDB/1.0\r\n" + "Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n" + "Content-Length: 20971520\r\n" + "Content-Type: text/plain\r\n" + // this is last modified timestamp on the file, we set this value when we created file
"ETag: \"122299092\"\r\n" + "\r\n";
for (int j = 0; j < 10; j++) {
sendRequest(request, fd, buffer);
assertDownloadResponse(fd, rnd, buffer, netBufferLen, diskBufferLen, expectedResponseHeader, 20971667);
}
// send few requests to receive 304
final String request2 = "GET /questdb-temp.txt HTTP/1.1\r\n" + "Host: localhost:9000\r\n" + "Connection: keep-alive\r\n" + "Cache-Control: max-age=0\r\n" + "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n" + "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.48 Safari/537.36\r\n" + "Accept-Encoding: gzip,deflate,sdch\r\n" + "Accept-Language: en-US,en;q=0.8\r\n" + // this header should make static processor return 304
"If-None-Match: \"122299092\"\r\n" + "Cookie: textwrapon=false; textautoformat=false; wysiwyg=textarea\r\n" + "\r\n";
String expectedResponseHeader2 = "HTTP/1.1 304 Not Modified\r\n" + "Server: questDB/1.0\r\n" + "Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n" + "Content-Type: text/html; charset=utf-8\r\n" + "\r\n";
for (int i = 0; i < 3; i++) {
sendRequest(request2, fd, buffer);
assertDownloadResponse(fd, rnd, buffer, netBufferLen, 0, expectedResponseHeader2, 126);
}
// couple more full downloads after 304
for (int j = 0; j < 2; j++) {
sendRequest(request, fd, buffer);
assertDownloadResponse(fd, rnd, buffer, netBufferLen, diskBufferLen, expectedResponseHeader, 20971667);
}
// get a 404 now
final String request3 = "GET /questdb-temp_!.txt HTTP/1.1\r\n" + "Host: localhost:9000\r\n" + "Connection: keep-alive\r\n" + "Cache-Control: max-age=0\r\n" + "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n" + "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.48 Safari/537.36\r\n" + "Accept-Encoding: gzip,deflate,sdch\r\n" + "Accept-Language: en-US,en;q=0.8\r\n" + "Cookie: textwrapon=false; textautoformat=false; wysiwyg=textarea\r\n" + "\r\n";
String expectedResponseHeader3 = "HTTP/1.1 404 Not Found\r\n" + "Server: questDB/1.0\r\n" + "Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n" + "Transfer-Encoding: chunked\r\n" + "Content-Type: text/plain; charset=utf-8\r\n" + "\r\n" + "0b\r\n" + "Not Found\r\n" + "\r\n" + "00\r\n" + "\r\n";
sendAndReceive(NetworkFacadeImpl.INSTANCE, request3, expectedResponseHeader3, 4, 0, false);
// and few more 304s
sendAndReceive(NetworkFacadeImpl.INSTANCE, request2, expectedResponseHeader2, 4, 0, false);
} finally {
Unsafe.free(buffer, netBufferLen, MemoryTag.NATIVE_DEFAULT);
}
} finally {
Net.freeSockAddr(sockAddr);
}
} finally {
Net.close(fd);
LOG.info().$("closed [fd=").$(fd).$(']').$();
}
} finally {
workerPool.halt();
Files.remove(path);
}
}
}
});
}
use of io.questdb.mp.WorkerPool in project questdb by bluestreak01.
the class IODispatcherTest method testJsonQueryDataError.
@Test
public void testJsonQueryDataError() throws Exception {
assertMemoryLeak(() -> {
final String baseDir = temp.getRoot().getAbsolutePath();
final DefaultHttpServerConfiguration httpConfiguration = createHttpServerConfiguration(baseDir, false);
final WorkerPool workerPool = new WorkerPool(new WorkerPoolConfiguration() {
@Override
public int[] getWorkerAffinity() {
return new int[] { -1 };
}
@Override
public int getWorkerCount() {
return 1;
}
@Override
public boolean haltOnError() {
return false;
}
});
try (CairoEngine engine = new CairoEngine(new DefaultCairoConfiguration(baseDir));
HttpServer httpServer = new HttpServer(httpConfiguration, workerPool, false)) {
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 new JsonQueryProcessor(httpConfiguration.getJsonQueryProcessorConfiguration(), engine, workerPool.getWorkerCount(), metrics);
}
@Override
public String getUrl() {
return "/query";
}
});
workerPool.start(LOG);
try {
// send multipart request to server
final String request = "GET /query?limit=0%2C1000&count=true&src=con&query=select%20npe()%20from%20long_sequence(1)&timings=true HTTP/1.1\r\n" + "Host: localhost:9000\r\n" + "Connection: keep-alive\r\n" + "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36\r\n" + "Accept: */*\r\n" + "Sec-Fetch-Site: same-origin\r\n" + "Sec-Fetch-Mode: cors\r\n" + "Sec-Fetch-Dest: empty\r\n" + "Referer: http://localhost:9000/index.html\r\n" + "Accept-Encoding: gzip, deflate, br\r\n" + "Accept-Language: en-GB,en-US;q=0.9,en;q=0.8\r\n" + "Cookie: _ga=GA1.1.2124932001.1573824669; _hjid=f2db90b2-18cf-4956-8870-fcdcde56f3ca; _hjIncludedInSample=1; _gid=GA1.1.697400188.1591597903\r\n" + "\r\n";
long fd = NetworkFacadeImpl.INSTANCE.socketTcp(true);
try {
long sockAddr = NetworkFacadeImpl.INSTANCE.sockaddr("127.0.0.1", 9001);
try {
TestUtils.assertConnect(fd, sockAddr);
Assert.assertEquals(0, NetworkFacadeImpl.INSTANCE.setTcpNoDelay(fd, true));
final int len = request.length() * 2;
long ptr = Unsafe.malloc(len, MemoryTag.NATIVE_DEFAULT);
try {
int sent = 0;
int reqLen = request.length();
Chars.asciiStrCpy(request, reqLen, ptr);
while (sent < reqLen) {
int n = NetworkFacadeImpl.INSTANCE.send(fd, ptr + sent, reqLen - sent);
Assert.assertTrue(n > -1);
sent += n;
}
Os.sleep(1);
NetworkFacadeImpl.INSTANCE.configureNonBlocking(fd);
long t = System.currentTimeMillis();
boolean disconnected = true;
while (NetworkFacadeImpl.INSTANCE.recv(fd, ptr, 1) > -1) {
if (t + 20000 < System.currentTimeMillis()) {
disconnected = false;
break;
}
}
Assert.assertTrue("disconnect expected", disconnected);
} finally {
Unsafe.free(ptr, len, MemoryTag.NATIVE_DEFAULT);
}
} finally {
NetworkFacadeImpl.INSTANCE.freeSockAddr(sockAddr);
}
} finally {
NetworkFacadeImpl.INSTANCE.close(fd);
}
} finally {
workerPool.halt();
}
}
});
}
use of io.questdb.mp.WorkerPool in project questdb by bluestreak01.
the class AbstractO3Test method executeWithPool.
protected static void executeWithPool(int workerCount, O3Runnable runnable, FilesFacade ff) throws Exception {
executeVanilla(() -> {
if (workerCount > 0) {
int[] affinity = new int[workerCount];
for (int i = 0; i < workerCount; i++) {
affinity[i] = -1;
}
WorkerPool pool = new WorkerPool(new WorkerPoolAwareConfiguration() {
@Override
public int[] getWorkerAffinity() {
return affinity;
}
@Override
public int getWorkerCount() {
return workerCount;
}
@Override
public boolean haltOnError() {
return false;
}
@Override
public boolean isEnabled() {
return true;
}
});
final CairoConfiguration configuration = new DefaultCairoConfiguration(root) {
@Override
public FilesFacade getFilesFacade() {
return ff;
}
};
execute(pool, runnable, configuration);
} else {
// we need to create entire engine
final CairoConfiguration configuration = new DefaultCairoConfiguration(root) {
@Override
public int getO3PurgeDiscoveryQueueCapacity() {
return 0;
}
@Override
public int getO3PurgeQueueCapacity() {
return 0;
}
@Override
public FilesFacade getFilesFacade() {
return ff;
}
@Override
public int getO3CallbackQueueCapacity() {
return 0;
}
@Override
public int getO3PartitionQueueCapacity() {
return 0;
}
@Override
public int getO3OpenColumnQueueCapacity() {
return 0;
}
@Override
public int getO3CopyQueueCapacity() {
return 0;
}
@Override
public int getO3PartitionUpdateQueueCapacity() {
return 0;
}
};
execute(null, runnable, configuration);
}
});
}
Aggregations