use of org.apache.drill.shaded.guava.com.google.common.base.Stopwatch in project drill by apache.
the class AsyncPageReader method nextPageFromQueue.
/**
* Blocks for a page to become available in the queue then takes it and schedules a new page
* read task if the queue was full.
* @returns ReadStatus the page taken from the queue
*/
private ReadStatus nextPageFromQueue() throws InterruptedException, ExecutionException {
ReadStatus readStatus;
Stopwatch timer = Stopwatch.createStarted();
OperatorStats opStats = parentColumnReader.parentReader.getOperatorContext().getStats();
opStats.startWait();
try {
// get the result of execution
waitForExecutionResult();
synchronized (pageQueueSyncronize) {
boolean pageQueueFull = pageQueue.remainingCapacity() == 0;
// get the data if no exception has been thrown
readStatus = pageQueue.take();
if (readStatus == ReadStatus.EMPTY) {
throw new DrillRuntimeException("Unexpected end of data");
}
// have been no new read tasks scheduled. In that case, schedule a new read.
if (!parentColumnReader.isShuttingDown && pageQueueFull) {
asyncPageRead.offer(ExecutorServiceUtil.submit(threadPool, new AsyncPageReaderTask(debugName, pageQueue)));
}
}
} finally {
opStats.stopWait();
}
long timeBlocked = timer.elapsed(TimeUnit.NANOSECONDS);
stats.timeDiskScanWait.addAndGet(timeBlocked);
stats.timeDiskScan.addAndGet(readStatus.getDiskScanTime());
if (readStatus.isDictionaryPage) {
stats.numDictPageLoads.incrementAndGet();
stats.timeDictPageLoads.addAndGet(timeBlocked + readStatus.getDiskScanTime());
} else {
stats.numDataPageLoads.incrementAndGet();
stats.timeDataPageLoads.addAndGet(timeBlocked + readStatus.getDiskScanTime());
}
return readStatus;
}
use of org.apache.drill.shaded.guava.com.google.common.base.Stopwatch in project drill by apache.
the class RuntimeFilterSink method add.
public void add(RuntimeFilterWritable runtimeFilterWritable) {
if (!running.get()) {
runtimeFilterWritable.close();
return;
}
runtimeFilterWritable.retainBuffers(1);
int joinMjId = runtimeFilterWritable.getRuntimeFilterBDef().getMajorFragmentId();
if (joinMjId2Stopwatch.get(joinMjId) == null) {
Stopwatch stopwatch = Stopwatch.createStarted();
joinMjId2Stopwatch.put(joinMjId, stopwatch);
}
synchronized (rfQueue) {
if (!running.get()) {
runtimeFilterWritable.close();
return;
}
rfQueue.add(runtimeFilterWritable);
rfQueue.notify();
}
}
use of org.apache.drill.shaded.guava.com.google.common.base.Stopwatch in project drill by apache.
the class DruidRecordReader method next.
@Override
public int next() {
writer.allocate();
writer.reset();
Stopwatch watch = Stopwatch.createStarted();
try {
String query = getQuery();
DruidScanResponse druidScanResponse = druidQueryClient.executeQuery(query);
setNextOffset(druidScanResponse);
int docCount = 0;
for (ObjectNode eventNode : druidScanResponse.getEvents()) {
writer.setPosition(docCount);
jsonReader.setSource(eventNode);
try {
jsonReader.write(writer);
} catch (IOException e) {
throw UserException.dataReadError(e).message("Failure while reading document").addContext("Failed Query", query).addContext("Parser was at record", eventNode.toString()).addContext(e.getMessage()).build(logger);
}
docCount++;
}
writer.setValueCount(docCount);
logger.debug("Took {} ms to get {} records", watch.elapsed(TimeUnit.MILLISECONDS), docCount);
return docCount;
} catch (Exception e) {
throw UserException.dataReadError(e).message("Failure while executing druid query").addContext(e.getMessage()).build(logger);
}
}
use of org.apache.drill.shaded.guava.com.google.common.base.Stopwatch in project drill by apache.
the class Drillbit method run.
public void run() throws Exception {
final Stopwatch w = Stopwatch.createStarted();
logger.debug("Startup begun.");
gracefulShutdownThread = new GracefulShutdownThread(this, new StackTrace());
coord.start(10000);
stateManager.setState(DrillbitState.ONLINE);
storeProvider.start();
if (profileStoreProvider != storeProvider) {
profileStoreProvider.start();
}
DrillbitEndpoint md = engine.start();
manager.start(md, engine.getController(), engine.getDataConnectionCreator(), coord, storeProvider, profileStoreProvider);
final DrillbitContext drillbitContext = manager.getContext();
storageRegistry = drillbitContext.getStorage();
storageRegistry.init();
drillbitContext.getOptionManager().init();
javaPropertiesToSystemOptions();
manager.getContext().getRemoteFunctionRegistry().init(context.getConfig(), storeProvider, coord);
webServer.start();
// Discovering HTTP port (in case of port hunting)
if (webServer.isRunning()) {
int httpPort = getWebServerPort();
md = md.toBuilder().setHttpPort(httpPort).build();
}
registrationHandle = coord.register(md);
// Must start the RM after the above since it needs to read system options.
drillbitContext.startRM();
shutdownHook = new ShutdownThread(this, new StackTrace());
Runtime.getRuntime().addShutdownHook(shutdownHook);
gracefulShutdownThread.start();
logger.info("Startup completed ({} ms).", w.elapsed(TimeUnit.MILLISECONDS));
}
use of org.apache.drill.shaded.guava.com.google.common.base.Stopwatch in project drill by apache.
the class JdbcTestQueryBase method testQuery.
protected static void testQuery(String sql) throws Exception {
final StringBuilder sb = new StringBuilder();
boolean success = false;
try (Connection conn = connect()) {
for (int x = 0; x < 1; x++) {
Stopwatch watch = Stopwatch.createStarted();
Statement s = conn.createStatement();
ResultSet r = s.executeQuery(sql);
sb.append(String.format("QueryId: %s\n", r.unwrap(DrillResultSet.class).getQueryId()));
boolean first = true;
while (r.next()) {
ResultSetMetaData md = r.getMetaData();
if (first == true) {
for (int i = 1; i <= md.getColumnCount(); i++) {
sb.append(md.getColumnName(i));
sb.append('\t');
}
sb.append('\b');
first = false;
}
for (int i = 1; i <= md.getColumnCount(); i++) {
sb.append(r.getObject(i));
sb.append('\t');
}
sb.append('\n');
}
sb.append(String.format("Query completed in %d millis.\n", watch.elapsed(TimeUnit.MILLISECONDS)));
}
sb.append("\n\n\n");
success = true;
} finally {
if (!success) {
Thread.sleep(2000);
}
}
logger.info(sb.toString());
}
Aggregations