Search in sources :

Example 86 with Stopwatch

use of com.google.common.base.Stopwatch in project drill by apache.

the class PriorityQueueTemplate method add.

@SuppressWarnings("resource")
@Override
public void add(FragmentContext context, RecordBatchData batch) throws SchemaChangeException {
    Stopwatch watch = Stopwatch.createStarted();
    if (hyperBatch == null) {
        hyperBatch = new ExpandableHyperContainer(batch.getContainer());
    } else {
        hyperBatch.addBatch(batch.getContainer());
    }
    // may not need to do this every time
    doSetup(context, hyperBatch, null);
    int count = 0;
    SelectionVector2 sv2 = null;
    if (hasSv2) {
        sv2 = batch.getSv2();
    }
    for (; queueSize < limit && count < batch.getRecordCount(); count++) {
        heapSv4.set(queueSize, batchCount, hasSv2 ? sv2.getIndex(count) : count);
        queueSize++;
        siftUp();
    }
    for (; count < batch.getRecordCount(); count++) {
        heapSv4.set(limit, batchCount, hasSv2 ? sv2.getIndex(count) : count);
        if (compare(limit, 0) < 0) {
            swap(limit, 0);
            siftDown();
        }
    }
    batchCount++;
    if (hasSv2) {
        sv2.clear();
    }
    logger.debug("Took {} us to add {} records", watch.elapsed(TimeUnit.MICROSECONDS), count);
}
Also used : ExpandableHyperContainer(org.apache.drill.exec.record.ExpandableHyperContainer) Stopwatch(com.google.common.base.Stopwatch) SelectionVector2(org.apache.drill.exec.record.selection.SelectionVector2)

Example 87 with Stopwatch

use of com.google.common.base.Stopwatch in project drill by apache.

the class ImplCreator method getExec.

/**
   * Create and return fragment RootExec for given FragmentRoot. RootExec has one or more RecordBatches as children
   * (which may contain child RecordBatches and so on).
   *
   * @param context
   *          FragmentContext.
   * @param root
   *          FragmentRoot.
   * @return RootExec of fragment.
   * @throws ExecutionSetupException
   */
public static RootExec getExec(FragmentContext context, FragmentRoot root) throws ExecutionSetupException {
    Preconditions.checkNotNull(root);
    Preconditions.checkNotNull(context);
    if (AssertionUtil.isAssertionsEnabled() || context.getOptionSet().getOption(ExecConstants.ENABLE_ITERATOR_VALIDATOR) || context.getConfig().getBoolean(ExecConstants.ENABLE_ITERATOR_VALIDATION)) {
        root = IteratorValidatorInjector.rewritePlanWithIteratorValidator(context, root);
    }
    final ImplCreator creator = new ImplCreator();
    Stopwatch watch = Stopwatch.createStarted();
    try {
        final RootExec rootExec = creator.getRootExec(root, context);
        // skip over this for SimpleRootExec (testing)
        if (rootExec instanceof BaseRootExec) {
            ((BaseRootExec) rootExec).setOperators(creator.getOperators());
        }
        logger.debug("Took {} ms to create RecordBatch tree", watch.elapsed(TimeUnit.MILLISECONDS));
        if (rootExec == null) {
            throw new ExecutionSetupException("The provided fragment did not have a root node that correctly created a RootExec value.");
        }
        return rootExec;
    } catch (Exception e) {
        AutoCloseables.close(e, creator.getOperators());
        context.fail(e);
    }
    return null;
}
Also used : ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException) ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException)

Example 88 with Stopwatch

use of com.google.common.base.Stopwatch in project drill by apache.

the class PriorityQueueTemplate method generate.

@Override
public void generate() throws SchemaChangeException {
    Stopwatch watch = Stopwatch.createStarted();
    @SuppressWarnings("resource") final DrillBuf drillBuf = allocator.buffer(4 * queueSize);
    finalSv4 = new SelectionVector4(drillBuf, queueSize, 4000);
    for (int i = queueSize - 1; i >= 0; i--) {
        finalSv4.set(i, pop());
    }
    logger.debug("Took {} us to generate output of {}", watch.elapsed(TimeUnit.MICROSECONDS), finalSv4.getTotalCount());
}
Also used : Stopwatch(com.google.common.base.Stopwatch) DrillBuf(io.netty.buffer.DrillBuf) SelectionVector4(org.apache.drill.exec.record.selection.SelectionVector4)

Example 89 with Stopwatch

use of com.google.common.base.Stopwatch in project drill by apache.

the class TopNBatch method purgeAndResetPriorityQueue.

/**
   * Handle schema changes during execution.
   * 1. Purge existing batches
   * 2. Promote newly created container for new schema.
   * 3. Recreate priority queue and reset with coerced container.
   * @throws SchemaChangeException
   */
public void purgeAndResetPriorityQueue() throws SchemaChangeException, ClassTransformationException, IOException {
    final Stopwatch watch = Stopwatch.createStarted();
    final VectorContainer c = priorityQueue.getHyperBatch();
    final VectorContainer newContainer = new VectorContainer(oContext);
    @SuppressWarnings("resource") final SelectionVector4 selectionVector4 = priorityQueue.getHeapSv4();
    final SimpleRecordBatch batch = new SimpleRecordBatch(c, selectionVector4, context);
    final SimpleRecordBatch newBatch = new SimpleRecordBatch(newContainer, null, context);
    copier = RemovingRecordBatch.getGenerated4Copier(batch, context, oContext.getAllocator(), newContainer, newBatch, null);
    @SuppressWarnings("resource") SortRecordBatchBuilder builder = new SortRecordBatchBuilder(oContext.getAllocator());
    try {
        do {
            final int count = selectionVector4.getCount();
            final int copiedRecords = copier.copyRecords(0, count);
            assert copiedRecords == count;
            for (VectorWrapper<?> v : newContainer) {
                ValueVector.Mutator m = v.getValueVector().getMutator();
                m.setValueCount(count);
            }
            newContainer.buildSchema(BatchSchema.SelectionVectorMode.NONE);
            newContainer.setRecordCount(count);
            builder.add(newBatch);
        } while (selectionVector4.next());
        selectionVector4.clear();
        c.clear();
        final VectorContainer oldSchemaContainer = new VectorContainer(oContext);
        builder.canonicalize();
        builder.build(context, oldSchemaContainer);
        oldSchemaContainer.setRecordCount(builder.getSv4().getCount());
        final VectorContainer newSchemaContainer = SchemaUtil.coerceContainer(oldSchemaContainer, this.schema, oContext);
        // Canonicalize new container since we canonicalize incoming batches before adding to queue.
        final VectorContainer canonicalizedContainer = VectorContainer.canonicalize(newSchemaContainer);
        canonicalizedContainer.buildSchema(SelectionVectorMode.FOUR_BYTE);
        priorityQueue.cleanup();
        priorityQueue = createNewPriorityQueue(context, config.getOrderings(), canonicalizedContainer, MAIN_MAPPING, LEFT_MAPPING, RIGHT_MAPPING);
        priorityQueue.resetQueue(canonicalizedContainer, builder.getSv4().createNewWrapperCurrent());
    } finally {
        builder.clear();
        builder.close();
    }
    logger.debug("Took {} us to purge and recreate queue for new schema", watch.elapsed(TimeUnit.MICROSECONDS));
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) Stopwatch(com.google.common.base.Stopwatch) SortRecordBatchBuilder(org.apache.drill.exec.physical.impl.sort.SortRecordBatchBuilder) VectorContainer(org.apache.drill.exec.record.VectorContainer) SelectionVector4(org.apache.drill.exec.record.selection.SelectionVector4)

Example 90 with Stopwatch

use of 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.");
    coord.start(10000);
    storeProvider.start();
    if (profileStoreProvider != storeProvider) {
        profileStoreProvider.start();
    }
    final 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);
    registrationHandle = coord.register(md);
    webServer.start();
    Runtime.getRuntime().addShutdownHook(new ShutdownThread(this, new StackTrace()));
    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(com.google.common.base.Stopwatch)

Aggregations

Stopwatch (com.google.common.base.Stopwatch)314 IOException (java.io.IOException)81 ArrayList (java.util.ArrayList)29 ExecutionException (java.util.concurrent.ExecutionException)28 File (java.io.File)19 Map (java.util.Map)18 Test (org.junit.Test)18 DocumentStoreException (org.apache.jackrabbit.oak.plugins.document.DocumentStoreException)15 HashMap (java.util.HashMap)14 Path (org.apache.hadoop.fs.Path)14 List (java.util.List)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)11 DBCollection (com.mongodb.DBCollection)9 ISE (io.druid.java.util.common.ISE)9 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)8 OptionsParser (com.google.devtools.common.options.OptionsParser)8 MongoException (com.mongodb.MongoException)8 Connection (java.sql.Connection)8 CountDownLatch (java.util.concurrent.CountDownLatch)8