List of usage examples for java.util.concurrent TimeUnit MICROSECONDS
TimeUnit MICROSECONDS
To view the source code for java.util.concurrent TimeUnit MICROSECONDS.
Click Source Link
From source file:io.druid.benchmark.GroupByTypeInterfaceBenchmark.java
@Benchmark @BenchmarkMode(Mode.AverageTime)//from ww w .j av a2s .c o m @OutputTimeUnit(TimeUnit.MICROSECONDS) public void querySingleQueryableIndexLongThenString(Blackhole blackhole) throws Exception { QueryRunner<Row> runner = QueryBenchmarkUtil.makeQueryRunner(factory, "qIndex", new QueryableIndexSegment("qIndex", queryableIndexes.get(0))); List<Row> results = GroupByTypeInterfaceBenchmark.runQuery(factory, runner, longQuery); for (Row result : results) { blackhole.consume(result); } runner = QueryBenchmarkUtil.makeQueryRunner(factory, "qIndex", new QueryableIndexSegment("qIndex", queryableIndexes.get(0))); results = GroupByTypeInterfaceBenchmark.runQuery(factory, runner, stringQuery); for (Row result : results) { blackhole.consume(result); } }
From source file:org.jenkinsci.remoting.protocol.impl.ConnectionHeadersFilterLayerTest.java
@Theory public void headerExchange(NetworkLayerFactory serverFactory, NetworkLayerFactory clientFactory) throws Exception { Random entropy = new Random(); final SettableFuture<Map<String, String>> serverActualHeaders = SettableFuture.create(); Map<String, String> clientExpectedHeaders = new HashMap<String, String>(); for (int i = 1 + entropy.nextInt(50); i > 0; i--) { clientExpectedHeaders.put(Long.toHexString(entropy.nextLong()), Long.toHexString(entropy.nextLong())); }/*from www .ja va2 s . c om*/ ProtocolStack<IOBufferMatcher> client = ProtocolStack .on(clientFactory.create(selector.hub(), serverToClient.source(), clientToServer.sink())) .filter(new ConnectionHeadersFilterLayer(clientExpectedHeaders, new ConnectionHeadersFilterLayer.Listener() { @Override public void onReceiveHeaders(Map<String, String> headers) throws ConnectionRefusalException { serverActualHeaders.set(headers); } })) .build(new IOBufferMatcherLayer()); final SettableFuture<Map<String, String>> clientActualHeaders = SettableFuture.create(); Map<String, String> serverExpectedHeaders = new HashMap<String, String>(); for (int i = 1 + entropy.nextInt(50); i > 0; i--) { serverExpectedHeaders.put(Long.toHexString(entropy.nextLong()), Long.toHexString(entropy.nextLong())); } ProtocolStack<IOBufferMatcher> server = ProtocolStack .on(serverFactory.create(selector.hub(), clientToServer.source(), serverToClient.sink())) .filter(new ConnectionHeadersFilterLayer(serverExpectedHeaders, new ConnectionHeadersFilterLayer.Listener() { @Override public void onReceiveHeaders(Map<String, String> headers) throws ConnectionRefusalException { clientActualHeaders.set(headers); } })) .build(new IOBufferMatcherLayer()); byte[] expected = "Here is some sample data".getBytes("UTF-8"); ByteBuffer data = ByteBuffer.allocate(expected.length); data.put(expected); data.flip(); server.get().send(data); client.get().awaitByteContent(is(expected)); assertThat(client.get().asByteArray(), is(expected)); assertThat(serverActualHeaders.get(1000, TimeUnit.MICROSECONDS), is(serverExpectedHeaders)); assertThat(clientActualHeaders.get(1000, TimeUnit.MICROSECONDS), is(clientExpectedHeaders)); }
From source file:org.apache.druid.benchmark.GroupByTypeInterfaceBenchmark.java
@Benchmark @BenchmarkMode(Mode.AverageTime)// w w w. j a v a 2 s.c o m @OutputTimeUnit(TimeUnit.MICROSECONDS) public void querySingleQueryableIndexLongThenFloat(Blackhole blackhole) { QueryRunner<Row> runner = QueryBenchmarkUtil.makeQueryRunner(factory, "qIndex", new QueryableIndexSegment("qIndex", queryableIndexes.get(0))); List<Row> results = GroupByTypeInterfaceBenchmark.runQuery(factory, runner, longQuery); for (Row result : results) { blackhole.consume(result); } runner = QueryBenchmarkUtil.makeQueryRunner(factory, "qIndex", new QueryableIndexSegment("qIndex", queryableIndexes.get(0))); results = GroupByTypeInterfaceBenchmark.runQuery(factory, runner, floatQuery); for (Row result : results) { blackhole.consume(result); } }
From source file:io.druid.benchmark.GroupByTypeInterfaceBenchmark.java
@Benchmark @BenchmarkMode(Mode.AverageTime)/* w w w . ja v a2s . co m*/ @OutputTimeUnit(TimeUnit.MICROSECONDS) public void querySingleQueryableIndexLongThenFloat(Blackhole blackhole) throws Exception { QueryRunner<Row> runner = QueryBenchmarkUtil.makeQueryRunner(factory, "qIndex", new QueryableIndexSegment("qIndex", queryableIndexes.get(0))); List<Row> results = GroupByTypeInterfaceBenchmark.runQuery(factory, runner, longQuery); for (Row result : results) { blackhole.consume(result); } runner = QueryBenchmarkUtil.makeQueryRunner(factory, "qIndex", new QueryableIndexSegment("qIndex", queryableIndexes.get(0))); results = GroupByTypeInterfaceBenchmark.runQuery(factory, runner, floatQuery); for (Row result : results) { blackhole.consume(result); } }
From source file:org.apache.druid.benchmark.query.GroupByBenchmark.java
@Benchmark @BenchmarkMode(Mode.AverageTime)/*from www. jav a2s.c om*/ @OutputTimeUnit(TimeUnit.MICROSECONDS) public void querySingleIncrementalIndex(Blackhole blackhole) { QueryRunner<Row> runner = QueryBenchmarkUtil.makeQueryRunner(factory, "incIndex", new IncrementalIndexSegment(anIncrementalIndex, "incIndex")); List<Row> results = GroupByBenchmark.runQuery(factory, runner, query); for (Row result : results) { blackhole.consume(result); } }
From source file:it.staiger.jmeter.protocol.http.sampler.HTTPHC4DynamicFilePost.java
private HttpClient setupClient(URL url, SampleResult res) { Map<HttpClientKey, HttpClient> mapHttpClientPerHttpClientKey = HTTPCLIENTS_CACHE_PER_THREAD_AND_HTTPCLIENTKEY .get();// ww w. ja va 2 s . com final String host = url.getHost(); final String proxyHost = getProxyHost(); final int proxyPort = getProxyPortInt(); boolean useStaticProxy = isStaticProxy(host); boolean useDynamicProxy = isDynamicProxy(proxyHost, proxyPort); // Lookup key - must agree with all the values used to create the HttpClient. HttpClientKey key = new HttpClientKey(url, (useStaticProxy || useDynamicProxy), useDynamicProxy ? proxyHost : PROXY_HOST, useDynamicProxy ? proxyPort : PROXY_PORT, useDynamicProxy ? getProxyUser() : PROXY_USER, useDynamicProxy ? getProxyPass() : PROXY_PASS); HttpClient httpClient = mapHttpClientPerHttpClientKey.get(key); if (httpClient != null && resetSSLContext && HTTPConstants.PROTOCOL_HTTPS.equalsIgnoreCase(url.getProtocol())) { ((AbstractHttpClient) httpClient).clearRequestInterceptors(); ((AbstractHttpClient) httpClient).clearResponseInterceptors(); httpClient.getConnectionManager().closeIdleConnections(1L, TimeUnit.MICROSECONDS); httpClient = null; JsseSSLManager sslMgr = (JsseSSLManager) SSLManager.getInstance(); sslMgr.resetContext(); resetSSLContext = false; } if (httpClient == null) { // One-time init for this client HttpParams clientParams = new DefaultedHttpParams(new BasicHttpParams(), DEFAULT_HTTP_PARAMS); DnsResolver resolver = this.testElement.getDNSResolver(); if (resolver == null) { resolver = new SystemDefaultDnsResolver(); } ClientConnectionManager connManager = new MeasuringConnectionManager( SchemeRegistryFactory.createDefault(), resolver); httpClient = new DefaultHttpClient(connManager, clientParams) { @Override protected HttpRequestRetryHandler createHttpRequestRetryHandler() { return new DefaultHttpRequestRetryHandler(RETRY_COUNT, false); // set retry count } }; if (IDLE_TIMEOUT > 0) { ((AbstractHttpClient) httpClient).setKeepAliveStrategy(IDLE_STRATEGY); } ((AbstractHttpClient) httpClient).addResponseInterceptor(new ResponseContentEncoding()); ((AbstractHttpClient) httpClient).addResponseInterceptor(METRICS_SAVER); // HACK ((AbstractHttpClient) httpClient).addRequestInterceptor(METRICS_RESETTER); // Override the defualt schemes as necessary SchemeRegistry schemeRegistry = httpClient.getConnectionManager().getSchemeRegistry(); if (SLOW_HTTP != null) { schemeRegistry.register(SLOW_HTTP); } if (HTTPS_SCHEME != null) { schemeRegistry.register(HTTPS_SCHEME); } // Set up proxy details if (useDynamicProxy) { HttpHost proxy = new HttpHost(proxyHost, proxyPort); clientParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); String proxyUser = getProxyUser(); if (proxyUser.length() > 0) { ((AbstractHttpClient) httpClient).getCredentialsProvider().setCredentials( new AuthScope(proxyHost, proxyPort), new NTCredentials(proxyUser, getProxyPass(), localHost, PROXY_DOMAIN)); } } else if (useStaticProxy) { HttpHost proxy = new HttpHost(PROXY_HOST, PROXY_PORT); clientParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); if (PROXY_USER.length() > 0) { ((AbstractHttpClient) httpClient).getCredentialsProvider().setCredentials( new AuthScope(PROXY_HOST, PROXY_PORT), new NTCredentials(PROXY_USER, PROXY_PASS, localHost, PROXY_DOMAIN)); } } // Bug 52126 - we do our own cookie handling clientParams.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES); if (log.isDebugEnabled()) { log.debug("Created new HttpClient: @" + System.identityHashCode(httpClient) + " " + key.toString()); } mapHttpClientPerHttpClientKey.put(key, httpClient); // save the agent for next time round } else { if (log.isDebugEnabled()) { log.debug("Reusing the HttpClient: @" + System.identityHashCode(httpClient) + " " + key.toString()); } } MeasuringConnectionManager connectionManager = (MeasuringConnectionManager) httpClient .getConnectionManager(); connectionManager.setSample(res); // TODO - should this be done when the client is created? // If so, then the details need to be added as part of HttpClientKey setConnectionAuthorization(httpClient, url, getAuthManager(), key); return httpClient; }
From source file:com.spotify.heroic.HeroicCore.java
static boolean awaitLifeCycles(final String op, final CoreComponent primary, final Duration await, final List<LifeCycleNamedHook<AsyncFuture<Void>>> hooks) throws InterruptedException, ExecutionException { log.info("[{}] {} lifecycle(s)...", op, hooks.size()); final AsyncFramework async = primary.async(); final List<AsyncFuture<Void>> futures = new ArrayList<>(); final List<Pair<AsyncFuture<Void>, LifeCycleHook<AsyncFuture<Void>>>> pairs = new ArrayList<>(); for (final LifeCycleNamedHook<AsyncFuture<Void>> hook : hooks) { log.trace("[{}] {}", op, hook.id()); final AsyncFuture<Void> future; try {/*from w w w.j av a 2 s . co m*/ future = hook.get(); } catch (Exception e) { futures.add(async.failed(e)); break; } if (log.isTraceEnabled()) { final Stopwatch w = Stopwatch.createStarted(); future.onFinished(() -> { log.trace("[{}] {}, took {}us", op, hook.id(), w.elapsed(TimeUnit.MICROSECONDS)); }); } futures.add(future); pairs.add(Pair.of(future, hook)); } try { async.collect(futures).get(await.getDuration(), await.getUnit()); } catch (final TimeoutException e) { log.error("Operation timed out"); for (final Pair<AsyncFuture<Void>, LifeCycleHook<AsyncFuture<Void>>> pair : pairs) { if (!pair.getLeft().isDone()) { log.error("{}: did not finish in time: {}", op, pair.getRight()); } } return false; } log.info("[{}] {} lifecycle(s) done", op, hooks.size()); return true; }
From source file:org.apache.druid.benchmark.GroupByTypeInterfaceBenchmark.java
@Benchmark @BenchmarkMode(Mode.AverageTime)/* w w w.java 2s . c o m*/ @OutputTimeUnit(TimeUnit.MICROSECONDS) public void querySingleQueryableIndexStringThenNumeric(Blackhole blackhole) { QueryRunner<Row> runner = QueryBenchmarkUtil.makeQueryRunner(factory, "qIndex", new QueryableIndexSegment("qIndex", queryableIndexes.get(0))); List<Row> results = GroupByTypeInterfaceBenchmark.runQuery(factory, runner, stringQuery); for (Row result : results) { blackhole.consume(result); } runner = QueryBenchmarkUtil.makeQueryRunner(factory, "qIndex", new QueryableIndexSegment("qIndex", queryableIndexes.get(0))); results = GroupByTypeInterfaceBenchmark.runQuery(factory, runner, longFloatQuery); for (Row result : results) { blackhole.consume(result); } }
From source file:org.apache.distributedlog.BKLogHandler.java
public CompletableFuture<LogRecordWithDLSN> asyncReadLastRecord(final LogSegmentMetadata l, final boolean fence, final boolean includeControl, final boolean includeEndOfStream) { final AtomicInteger numRecordsScanned = new AtomicInteger(0); final Stopwatch stopwatch = Stopwatch.createStarted(); return ReadUtils.asyncReadLastRecord(getFullyQualifiedName(), l, fence, includeControl, includeEndOfStream, firstNumEntriesPerReadLastRecordScan, maxNumEntriesPerReadLastRecordScan, numRecordsScanned, scheduler, entryStore).whenComplete(new FutureEventListener<LogRecordWithDLSN>() { @Override/*from w ww. j a v a 2s.co m*/ public void onSuccess(LogRecordWithDLSN value) { recoverLastEntryStats.registerSuccessfulEvent( stopwatch.stop().elapsed(TimeUnit.MICROSECONDS), TimeUnit.MICROSECONDS); recoverScannedEntriesStats.registerSuccessfulValue(numRecordsScanned.get()); } @Override public void onFailure(Throwable cause) { recoverLastEntryStats.registerFailedEvent(stopwatch.stop().elapsed(TimeUnit.MICROSECONDS), TimeUnit.MICROSECONDS); } }); }
From source file:org.apache.druid.benchmark.query.GroupByBenchmark.java
@Benchmark @BenchmarkMode(Mode.AverageTime)/*from ww w . j a v a2 s . c o m*/ @OutputTimeUnit(TimeUnit.MICROSECONDS) public void querySingleQueryableIndex(Blackhole blackhole) { QueryRunner<Row> runner = QueryBenchmarkUtil.makeQueryRunner(factory, "qIndex", new QueryableIndexSegment("qIndex", queryableIndexes.get(0))); List<Row> results = GroupByBenchmark.runQuery(factory, runner, query); for (Row result : results) { blackhole.consume(result); } }