Example usage for java.util.concurrent TimeUnit MICROSECONDS

List of usage examples for java.util.concurrent TimeUnit MICROSECONDS

Introduction

In this page you can find the example usage for java.util.concurrent TimeUnit MICROSECONDS.

Prototype

TimeUnit MICROSECONDS

To view the source code for java.util.concurrent TimeUnit MICROSECONDS.

Click Source Link

Document

Time unit representing one thousandth of a millisecond.

Usage

From source file:com.linkedin.pinot.perf.BenchmarkOfflineIndexReader.java

@Benchmark
@BenchmarkMode(Mode.AverageTime)/*  ww w.j  a va 2 s . com*/
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public int sortedForwardIndexReaderSequential() {
    SortedIndexReader.Context context = _sortedForwardIndexReader.createContext();
    int ret = 0;
    for (int i = 0; i < _numDocs; i++) {
        ret += _sortedForwardIndexReader.getInt(i, context);
    }
    return ret;
}

From source file:org.apache.tinkerpop.gremlin.process.traversal.step.map.ProfileTest.java

private void validate_g_V_out_out_profile_grateful(TraversalMetrics traversalMetrics) {
    traversalMetrics.toString(); // ensure no exceptions are thrown

    Metrics metrics = traversalMetrics.getMetrics(0);
    assertEquals(808, metrics.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());
    assertEquals(808, metrics.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());
    assertTrue("Percent duration should be positive.",
            (Double) metrics.getAnnotation(TraversalMetrics.PERCENT_DURATION_KEY) >= 0);
    assertTrue("Times should be positive.", metrics.getDuration(TimeUnit.MICROSECONDS) >= 0);

    metrics = traversalMetrics.getMetrics(1);
    assertEquals(8049, metrics.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());
    assertNotEquals(0, metrics.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());
    assertTrue("Percent duration should be positive.",
            (Double) metrics.getAnnotation(TraversalMetrics.PERCENT_DURATION_KEY) >= 0);
    assertTrue("Times should be positive.", metrics.getDuration(TimeUnit.MICROSECONDS) >= 0);

    metrics = traversalMetrics.getMetrics(2);
    assertEquals(327370, metrics.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());
    assertNotEquals(0, metrics.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());
    assertTrue("Percent duration should be positive.",
            (Double) metrics.getAnnotation(TraversalMetrics.PERCENT_DURATION_KEY) >= 0);
    assertTrue("Times should be positive.", metrics.getDuration(TimeUnit.MICROSECONDS) >= 0);

    double totalPercentDuration = 0;
    for (Metrics m : traversalMetrics.getMetrics()) {
        totalPercentDuration += (Double) m.getAnnotation(TraversalMetrics.PERCENT_DURATION_KEY);
    }/*ww  w .  ja v  a 2  s . com*/
    assertEquals(100, totalPercentDuration, 0.000001);
}

From source file:com.linkedin.pinot.perf.BenchmarkOfflineIndexReader.java

@Benchmark
@BenchmarkMode(Mode.AverageTime)//from  w  w  w . j av a2 s.  c o  m
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public int sortedForwardIndexReaderRandom() {
    SortedIndexReader.Context context = _sortedForwardIndexReader.createContext();
    int ret = 0;
    for (int i = 0; i < _numDocs; i++) {
        ret += _sortedForwardIndexReader.getInt(RANDOM.nextInt(_numDocs), context);
    }
    return ret;
}

From source file:org.wso2.andes.server.virtualhost.plugins.SlowConsumerDetectionConfigurationTest.java

/**
 * Failure Testing://from  www.j a  v a 2 s . c om
 *
 *  Test that delay cannot be 0.
 *
 * A zero delay means run constantly. This is not how VirtualHostTasks
 * are designed to be run so we dis-allow the use of 0 delay.
 *
 * Same test as 'testConfigLoadingInValidDelayNegative' but with a 0 value.
 *
 */
public void testConfigLoadingInValidDelayZero() {
    SlowConsumerDetectionConfiguration config = new SlowConsumerDetectionConfiguration();

    XMLConfiguration xmlconfig = new XMLConfiguration();

    xmlconfig.addProperty("delay", "0");
    xmlconfig.addProperty("timeunit", TimeUnit.MICROSECONDS.toString());

    // Create a CompositeConfiguration as this is what the broker uses
    CompositeConfiguration composite = new CompositeConfiguration();
    composite.addConfiguration(xmlconfig);

    try {
        config.setConfiguration("", composite);
        fail("Configuration should fail to validate");
    } catch (ConfigurationException e) {
        Throwable cause = e.getCause();

        assertNotNull("Configuration Exception must not be null.", cause);
        assertEquals("Cause not correct", ConfigurationException.class, cause.getClass());
        assertEquals("Incorrect message.",
                "SlowConsumerDetectionConfiguration: 'delay' must be a Positive Long value.",
                cause.getMessage());
    }
}

From source file:org.apache.druid.benchmark.FilterPartitionBenchmark.java

@Benchmark
@BenchmarkMode(Mode.AverageTime)//ww w.j  av  a  2 s .c  o m
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void stringRead(Blackhole blackhole) {
    StorageAdapter sa = new QueryableIndexStorageAdapter(qIndex);
    Sequence<Cursor> cursors = makeCursors(sa, null);
    readCursors(cursors, blackhole);
}

From source file:org.apache.hadoop.hbase.client.RpcRetryingCallerWithReadReplicas.java

/**
 * <p>//ww w.j  a v  a 2s .  c o  m
 * Algo:
 * - we put the query into the execution pool.
 * - after x ms, if we don't have a result, we add the queries for the secondary replicas
 * - we take the first answer
 * - when done, we cancel what's left. Cancelling means:
 * - removing from the pool if the actual call was not started
 * - interrupting the call if it has started
 * Client side, we need to take into account
 * - a call is not executed immediately after being put into the pool
 * - a call is a thread. Let's not multiply the number of thread by the number of replicas.
 * Server side, if we can cancel when it's still in the handler pool, it's much better, as a call
 * can take some i/o.
 * </p>
 * Globally, the number of retries, timeout and so on still applies, but it's per replica,
 * not global. We continue until all retries are done, or all timeouts are exceeded.
 */
public synchronized Result call()
        throws DoNotRetryIOException, InterruptedIOException, RetriesExhaustedException {
    boolean isTargetReplicaSpecified = (get.getReplicaId() >= 0);

    RegionLocations rl = getRegionLocations(true,
            (isTargetReplicaSpecified ? get.getReplicaId() : RegionReplicaUtil.DEFAULT_REPLICA_ID), cConnection,
            tableName, get.getRow());
    ResultBoundedCompletionService<Result> cs = new ResultBoundedCompletionService<Result>(
            this.rpcRetryingCallerFactory, pool, rl.size());

    if (isTargetReplicaSpecified) {
        addCallsForReplica(cs, rl, get.getReplicaId(), get.getReplicaId());
    } else {
        addCallsForReplica(cs, rl, 0, 0);
        try {
            // wait for the timeout to see whether the primary responds back
            Future<Result> f = cs.poll(timeBeforeReplicas, TimeUnit.MICROSECONDS); // Yes, microseconds
            if (f != null) {
                return f.get(); //great we got a response
            }
        } catch (ExecutionException e) {
            throwEnrichedException(e, retries);
        } catch (CancellationException e) {
            throw new InterruptedIOException();
        } catch (InterruptedException e) {
            throw new InterruptedIOException();
        }

        // submit call for the all of the secondaries at once
        addCallsForReplica(cs, rl, 1, rl.size() - 1);
    }

    try {
        try {
            Future<Result> f = cs.take();
            return f.get();
        } catch (ExecutionException e) {
            throwEnrichedException(e, retries);
        }
    } catch (CancellationException e) {
        throw new InterruptedIOException();
    } catch (InterruptedException e) {
        throw new InterruptedIOException();
    } finally {
        // We get there because we were interrupted or because one or more of the
        // calls succeeded or failed. In all case, we stop all our tasks.
        cs.cancelAll();
    }

    return null; // unreachable
}

From source file:io.druid.benchmark.FilterPartitionBenchmark.java

@Benchmark
@BenchmarkMode(Mode.AverageTime)//from w ww  . j ava 2  s  .  co m
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void longRead(Blackhole blackhole) throws Exception {
    StorageAdapter sa = new QueryableIndexStorageAdapter(qIndex);
    Sequence<Cursor> cursors = makeCursors(sa, null);

    Sequence<List<Long>> longListSeq = readCursorsLong(cursors, blackhole);
    List<Long> strings = Sequences.toList(Sequences.limit(longListSeq, 1), Lists.<List<Long>>newArrayList())
            .get(0);
    for (Long st : strings) {
        blackhole.consume(st);
    }
}

From source file:org.apache.druid.benchmark.FilterPartitionBenchmark.java

@Benchmark
@BenchmarkMode(Mode.AverageTime)//from w  w  w .  j  av  a  2  s .co m
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void longRead(Blackhole blackhole) {
    StorageAdapter sa = new QueryableIndexStorageAdapter(qIndex);
    Sequence<Cursor> cursors = makeCursors(sa, null);

    readCursorsLong(cursors, blackhole);
}

From source file:com.linkedin.pinot.perf.BenchmarkOfflineIndexReader.java

@Benchmark
@BenchmarkMode(Mode.AverageTime)/*from  w ww.j  av  a  2 s.  c  o m*/
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public int fixedBitMultiValueReaderSequential() {
    FixedBitMultiValueReader.Context context = _fixedBitMultiValueReader.createContext();
    int ret = 0;
    for (int i = 0; i < _numDocs; i++) {
        ret += _fixedBitMultiValueReader.getIntArray(i, _buffer, context);
    }
    return ret;
}

From source file:com.stainlesscode.mediapipeline.videoout.DefaultVideoPlayer.java

/**
 * @param sleep/*from  ww  w.  j a v  a2s .  co  m*/
 */
protected void doSync(boolean sleep) {
    long vpts = engineRuntime.getSynchronizer().getStreamTime();
    long epts = ((CircularFifoMediaBuffer) videoFrameBuffer).getStartTimestamp();
    long lpts = videoOutput.getLastPts();
    long audioClock = engineRuntime.getSynchronizer().getAudioClock();
    long delay = epts - lpts;
    long diff = epts - audioClock;
    long threshold = 60000;
    long frameTimer = engineRuntime.getSynchronizer().getFrameTimer();

    if (LogUtil.isDebugEnabled()) {
        LogUtil.debug("vpts=" + vpts);
        LogUtil.debug("epts=" + epts);
        LogUtil.debug("lpts=" + lpts);
        LogUtil.debug("audioClock=" + audioClock);
        LogUtil.debug("vpts-epts=" + (vpts - epts) + "us");
        LogUtil.debug("vpts-audioClock=" + (vpts - audioClock) + "us");
        LogUtil.debug("frameTimer=" + frameTimer + "us");
        LogUtil.debug("epts-lpts=" + delay + "us");
        LogUtil.debug("epts-audioClock (diff)=" + diff + "us");
        LogUtil.debug("threshold=" + threshold + "us");
    }

    if (audioClock > 0) {
        if (diff < -threshold) { // too far behind, catch up
            delay = 0;
        } else if (diff >= threshold) { // too far ahead, hold up frame longer
            delay = diff - threshold;
            LogUtil.debug("delay=" + delay + "us");
            // long sleepTimeMillis = 0;
            // long sleepTimeMillis = ((epts - vpts) / 1000);
            // if (LogUtil.isDebugEnabled())
            // LogUtil.debug("sleeping " + sleepTimeMillis);

            // System.out.println("video seeping "+sleepTimeMillis);
            // double sleepTimeMillisD = (1.0d /
            // engineRuntime.getVideoCoder()
            // .getFrameRate().getValue()) * 1000.0d;
            // long sleepTimeMillis = new
            // Double(sleepTimeMillisD).longValue();
        }
    }

    engineRuntime.getSynchronizer().setFrameTimer(frameTimer + delay);

    // long actualDelay = (long) (frameTimer - (audioClock / 1000l));
    long actualDelay = delay;

    if (LogUtil.isDebugEnabled()) {
        //         LogUtil.debug("delay=" + delay + "us");
        //         LogUtil.debug("actualDelay=" + actualDelay + "us");
    }

    if (actualDelay > 0) {
        try {
            // if (actualDelay < 0.010) {
            // return;
            // } else {
            TimeUnit.MICROSECONDS.sleep(delay);
            // }
        } catch (InterruptedException e) {
            // seeking will fire an interrupt, and it's ok
            // e.printStackTrace();
            if (LogUtil.isDebugEnabled())
                LogUtil.debug("sleep interrupted");
        }
    }
}