Search in sources :

Example 11 with Stopwatch

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;
}
Also used : Stopwatch(org.apache.drill.shaded.guava.com.google.common.base.Stopwatch) OperatorStats(org.apache.drill.exec.ops.OperatorStats) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException)

Example 12 with Stopwatch

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();
    }
}
Also used : Stopwatch(org.apache.drill.shaded.guava.com.google.common.base.Stopwatch)

Example 13 with Stopwatch

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);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Stopwatch(org.apache.drill.shaded.guava.com.google.common.base.Stopwatch) DruidScanResponse(org.apache.drill.exec.store.druid.druid.DruidScanResponse) IOException(java.io.IOException) UserException(org.apache.drill.common.exceptions.UserException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

Example 14 with Stopwatch

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));
}
Also used : DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) StackTrace(org.apache.drill.common.StackTrace) Stopwatch(org.apache.drill.shaded.guava.com.google.common.base.Stopwatch) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)

Example 15 with Stopwatch

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());
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) Statement(java.sql.Statement) Connection(java.sql.Connection) Stopwatch(org.apache.drill.shaded.guava.com.google.common.base.Stopwatch) ResultSet(java.sql.ResultSet) DrillResultSet(org.apache.drill.jdbc.DrillResultSet) DrillResultSet(org.apache.drill.jdbc.DrillResultSet)

Aggregations

Stopwatch (org.apache.drill.shaded.guava.com.google.common.base.Stopwatch)68 IOException (java.io.IOException)13 Path (org.apache.hadoop.fs.Path)12 ArrayList (java.util.ArrayList)8 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)8 FileStatus (org.apache.hadoop.fs.FileStatus)8 DrillBuf (io.netty.buffer.DrillBuf)7 ByteBuffer (java.nio.ByteBuffer)7 SchemaPath (org.apache.drill.common.expression.SchemaPath)7 HashMap (java.util.HashMap)5 RelNode (org.apache.calcite.rel.RelNode)5 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)4 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)4 VectorContainer (org.apache.drill.exec.record.VectorContainer)4 SelectionVector4 (org.apache.drill.exec.record.selection.SelectionVector4)4 ValueVector (org.apache.drill.exec.vector.ValueVector)4 CompressionCodecName (org.apache.parquet.hadoop.metadata.CompressionCodecName)4 File (java.io.File)3 ResultSet (java.sql.ResultSet)3 ResultSetMetaData (java.sql.ResultSetMetaData)3