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:com.netflix.dyno.jedis.DynoJedisPipeline.java
@Override public Response<Map<String, String>> hgetAll(final String key) { return new PipelineOperation<Map<String, String>>() { @Override//from w ww.java2 s. c o m Response<Map<String, String>> execute(Pipeline jedisPipeline) throws DynoException { long startTime = System.nanoTime() / 1000; try { return jedisPipeline.hgetAll(key); } finally { long duration = System.nanoTime() / 1000 - startTime; opMonitor.recordSendLatency(OpName.HGETALL.name(), duration, TimeUnit.MICROSECONDS); } } }.execute(key, OpName.HGETALL); }
From source file:com.landenlabs.all_devtool.GpsFragment.java
/** * Format time interval//from w w w .j a v a 2 s . com * * @param elapsedMillis * @return */ private static String formatInterval(final long elapsedMillis) { final long day = TimeUnit.MICROSECONDS.toHours(elapsedMillis) / 24; final long hr = TimeUnit.MILLISECONDS.toHours(elapsedMillis) % 24; final long min = TimeUnit.MILLISECONDS.toMinutes(elapsedMillis) % 60; final long sec = TimeUnit.MILLISECONDS.toSeconds(elapsedMillis) % 60; final long ms = TimeUnit.MILLISECONDS.toMillis(elapsedMillis) % 1000; return String.format("%s %02d:%02d:%02d.%03d", (day == 0 ? "" : String.valueOf(day)), hr, min, sec, ms); }
From source file:org.apache.giraph.graph.GraphTaskManager.java
@Override public void newSuperstep(SuperstepMetricsRegistry superstepMetrics) { superstepTimer = new GiraphTimer(superstepMetrics, TIMER_SUPERSTEP_TIME, TimeUnit.MILLISECONDS); computeAll = new GiraphTimer(superstepMetrics, TIMER_COMPUTE_ALL, TimeUnit.MILLISECONDS); timeToFirstMessage = new GiraphTimer(superstepMetrics, TIMER_TIME_TO_FIRST_MSG, TimeUnit.MICROSECONDS); communicationTimer = new GiraphTimer(superstepMetrics, TIMER_COMMUNICATION_TIME, TimeUnit.MILLISECONDS); gcTimeMetric = superstepMetrics.getCounter(TIMER_SUPERSTEP_GC_TIME); wcPreSuperstepTimer = new GiraphTimer(superstepMetrics, "worker-context-pre-superstep", TimeUnit.MILLISECONDS); }
From source file:com.netflix.dyno.jedis.DynoJedisPipeline.java
public Response<Map<byte[], byte[]>> hgetAll(final byte[] key) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { return new PipelineOperation<Map<byte[], byte[]>>() { @Override//w w w . ja v a2s . c o m Response<Map<byte[], byte[]>> execute(Pipeline jedisPipeline) throws DynoException { long startTime = System.nanoTime() / 1000; try { return jedisPipeline.hgetAll(key); } finally { long duration = System.nanoTime() / 1000 - startTime; opMonitor.recordSendLatency(OpName.HGETALL.name(), duration, TimeUnit.MICROSECONDS); } } }.execute(key, OpName.HGETALL); } else { return new PipelineCompressionOperation<Map<byte[], byte[]>>() { @Override Response<Map<byte[], byte[]>> execute(final Pipeline jedisPipeline) throws DynoException { return new PipelineBinaryMapResponse(null).apply(new Func0<Response<Map<byte[], byte[]>>>() { @Override public Response<Map<byte[], byte[]>> call() { return jedisPipeline.hgetAll(key); } }); } }.execute(key, OpName.HGETALL); } }
From source file:org.solmix.datax.support.BaseDataService.java
protected void createAndFireTimeMonitorEvent(long time, String msg) { Map<String, Object> properties = new HashMap<String, Object>(); properties.put(TimeMonitorEvent.TOTAL_TIME, time); properties.put(TimeMonitorEvent.TIME_UNIT, TimeUnit.MICROSECONDS); properties.put(TimeMonitorEvent.MESSAGE, msg); TimeMonitorEvent event = new TimeMonitorEvent(properties); if (getEventService() != null) { getEventService().postEvent(event); }//from w w w . j av a 2 s. c om }
From source file:org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.java
private HttpClient setupClient(URL url, SampleResult res) { Map<HttpClientKey, HttpClient> mapHttpClientPerHttpClientKey = HTTPCLIENTS_CACHE_PER_THREAD_AND_HTTPCLIENTKEY .get();/*from w ww . java2s .c o m*/ final String host = url.getHost(); String proxyHost = getProxyHost(); int proxyPort = getProxyPortInt(); String proxyPass = getProxyPass(); String proxyUser = getProxyUser(); // static proxy is the globally define proxy eg command line or properties boolean useStaticProxy = isStaticProxy(host); // dynamic proxy is the proxy defined for this sampler boolean useDynamicProxy = isDynamicProxy(proxyHost, proxyPort); boolean useProxy = useStaticProxy || useDynamicProxy; // if both dynamic and static are used, the dynamic proxy has priority over static if (!useDynamicProxy) { proxyHost = PROXY_HOST; proxyPort = PROXY_PORT; proxyUser = PROXY_USER; proxyPass = PROXY_PASS; } // Lookup key - must agree with all the values used to create the HttpClient. HttpClientKey key = new HttpClientKey(url, useProxy, proxyHost, proxyPort, proxyUser, proxyPass); HttpClient httpClient = null; if (this.testElement.isConcurrentDwn()) { httpClient = (HttpClient) JMeterContextService.getContext().getSamplerContext().get(HTTPCLIENT_TOKEN); } if (httpClient == null) { 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 = SystemDefaultDnsResolver.INSTANCE; } MeasuringConnectionManager connManager = new MeasuringConnectionManager(createSchemeRegistry(), resolver, TIME_TO_LIVE, VALIDITY_AFTER_INACTIVITY_TIMEOUT); // Modern browsers use more connections per host than the current httpclient default (2) // when using parallel download the httpclient and connection manager are shared by the downloads threads // to be realistic JMeter must set an higher value to DefaultMaxPerRoute if (this.testElement.isConcurrentDwn()) { try { int maxConcurrentDownloads = Integer.parseInt(this.testElement.getConcurrentPool()); connManager.setDefaultMaxPerRoute( Math.max(maxConcurrentDownloads, connManager.getDefaultMaxPerRoute())); } catch (NumberFormatException nfe) { // no need to log -> will be done by the sampler } } 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); } // see https://issues.apache.org/jira/browse/HTTPCORE-397 ((AbstractHttpClient) httpClient).setReuseStrategy(DefaultClientConnectionReuseStrategy.INSTANCE); ((AbstractHttpClient) httpClient).addResponseInterceptor(RESPONSE_CONTENT_ENCODING); ((AbstractHttpClient) httpClient).addResponseInterceptor(METRICS_SAVER); // HACK ((AbstractHttpClient) httpClient).addRequestInterceptor(METRICS_RESETTER); // Override the default schemes as necessary SchemeRegistry schemeRegistry = httpClient.getConnectionManager().getSchemeRegistry(); if (SLOW_HTTP != null) { schemeRegistry.register(SLOW_HTTP); } // Set up proxy details if (useProxy) { HttpHost proxy = new HttpHost(proxyHost, proxyPort); clientParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); if (proxyUser.length() > 0) { ((AbstractHttpClient) httpClient).getCredentialsProvider().setCredentials( new AuthScope(proxyHost, proxyPort), new NTCredentials(proxyUser, proxyPass, localHost, PROXY_DOMAIN)); } } // Bug 52126 - we do our own cookie handling clientParams.setParameter(ClientPNames.COOKIE_POLICY, CookieSpecs.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()); } } if (this.testElement.isConcurrentDwn()) { JMeterContextService.getContext().getSamplerContext().put(HTTPCLIENT_TOKEN, httpClient); } // 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.netflix.dyno.jedis.DynoJedisPipeline.java
/** * This method is a BinaryRedisPipeline command which dyno does not yet properly * support, therefore the interface is not yet implemented. *//*from www .jav a 2 s . c om*/ public Response<List<byte[]>> hmget(final byte[] key, final byte[]... fields) { return new PipelineOperation<List<byte[]>>() { @Override Response<List<byte[]>> execute(Pipeline jedisPipeline) throws DynoException { long startTime = System.nanoTime() / 1000; try { return jedisPipeline.hmget(key, fields); } finally { long duration = System.nanoTime() / 1000 - startTime; opMonitor.recordSendLatency(OpName.HMGET.name(), duration, TimeUnit.MICROSECONDS); } } }.execute(key, OpName.HMGET); }
From source file:com.twitter.distributedlog.BKLogHandler.java
public Future<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(); final LedgerHandleCache handleCache = LedgerHandleCache.newBuilder().bkc(bookKeeperClient).conf(conf) .build();/*from ww w.ja va2s. com*/ return ReadUtils.asyncReadLastRecord(getFullyQualifiedName(), l, fence, includeControl, includeEndOfStream, firstNumEntriesPerReadLastRecordScan, maxNumEntriesPerReadLastRecordScan, numRecordsScanned, scheduler, handleCache).addEventListener(new FutureEventListener<LogRecordWithDLSN>() { @Override public void onSuccess(LogRecordWithDLSN value) { recoverLastEntryStats .registerSuccessfulEvent(stopwatch.stop().elapsed(TimeUnit.MICROSECONDS)); recoverScannedEntriesStats.registerSuccessfulEvent(numRecordsScanned.get()); } @Override public void onFailure(Throwable cause) { recoverLastEntryStats.registerFailedEvent(stopwatch.stop().elapsed(TimeUnit.MICROSECONDS)); } }).ensure(new AbstractFunction0<BoxedUnit>() { @Override public BoxedUnit apply() { handleCache.clear(); return BoxedUnit.UNIT; } }); }
From source file:com.netflix.dyno.jedis.DynoJedisPipeline.java
@Override public Response<List<String>> hmget(final String key, final String... fields) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { return new PipelineOperation<List<String>>() { @Override/*from w ww . ja va 2s. c om*/ Response<List<String>> execute(Pipeline jedisPipeline) throws DynoException { long startTime = System.nanoTime() / 1000; try { return jedisPipeline.hmget(key, fields); } finally { long duration = System.nanoTime() / 1000 - startTime; opMonitor.recordSendLatency(OpName.HMGET.name(), duration, TimeUnit.MICROSECONDS); } } }.execute(key, OpName.HMGET); } else { return new PipelineCompressionOperation<List<String>>() { @Override Response<List<String>> execute(final Pipeline jedisPipeline) throws DynoException { long startTime = System.nanoTime() / 1000; try { return new PipelineListResponse(null).apply(new Func0<Response<List<String>>>() { @Override public Response<List<String>> call() { return jedisPipeline.hmget(key, fields); } }); } finally { long duration = System.nanoTime() / 1000 - startTime; opMonitor.recordSendLatency(OpName.HMGET.name(), duration, TimeUnit.MICROSECONDS); } } }.execute(key, OpName.HGET); } }