当前位置: 首页>>代码示例>>Java>>正文


Java Stopwatch类代码示例

本文整理汇总了Java中com.netflix.servo.monitor.Stopwatch的典型用法代码示例。如果您正苦于以下问题:Java Stopwatch类的具体用法?Java Stopwatch怎么用?Java Stopwatch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Stopwatch类属于com.netflix.servo.monitor包,在下文中一共展示了Stopwatch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendNow

import com.netflix.servo.monitor.Stopwatch; //导入依赖的package包/类
private void sendNow(UpdateTasks updateTasks) {
    if (updateTasks.numMetrics == 0) {
        return;
    }
    pushSizeCount.increment();
    pushSizeTotal.increment(updateTasks.numMetrics);

    final Stopwatch s = updateTimer.start();
    int totalSent = 0;
    try {
        totalSent = RxHttp.sendAll(updateTasks.tasks, updateTasks.numMetrics, sendTimeoutMs);
        LOGGER.debug("Sent {}/{} metrics to atlas", totalSent, updateTasks.numMetrics);
    } finally {
        s.stop();
        int dropped = updateTasks.numMetrics - totalSent;
        numMetricsDroppedSendTimeout.increment(dropped);
    }
}
 
开发者ID:dmuino,项目名称:atlas-oss-plugin,代码行数:19,代码来源:BaseAtlasMetricObserver.java

示例2: execute

import com.netflix.servo.monitor.Stopwatch; //导入依赖的package包/类
@Override
public <T> T execute(
		final HttpHost target,
		final HttpRequest request,
		final ResponseHandler<? extends T> responseHandler,
		final HttpContext context)
				throws IOException, ClientProtocolException {
    Stopwatch sw = tracer.start();
	try{
		// TODO: replaced method.getQueryString() with request.getRequestLine().getUri()
		LOGGER.debug("Executing HTTP method: {}, uri: {}", request.getRequestLine().getMethod(), request.getRequestLine().getUri());
		return super.execute(target, request, responseHandler, context);
	}finally{
		sw.stop();
	}
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:17,代码来源:NFHttpClient.java

示例3: start

import com.netflix.servo.monitor.Stopwatch; //导入依赖的package包/类
private static Stopwatch start(StatsMonitor sm) {

		Stopwatch sw = new BasicStopwatch() {

			@Override
			public void stop() {
				super.stop();
				long duration = getDuration(TimeUnit.MILLISECONDS);
				sm.record(duration);
			}

		};
		sw.start();
		return sw;
	}
 
开发者ID:Netflix,项目名称:conductor,代码行数:16,代码来源:WorkflowTaskMetrics.java

示例4: start

import com.netflix.servo.monitor.Stopwatch; //导入依赖的package包/类
private static Stopwatch start(Timer sm) {

		Stopwatch sw = new BasicStopwatch() {

			@Override
			public void stop() {
				super.stop();
				long duration = getDuration(TimeUnit.MILLISECONDS);
				sm.record(duration, TimeUnit.MILLISECONDS);
			}

		};
		sw.start();
		return sw;
	}
 
开发者ID:Netflix,项目名称:conductor,代码行数:16,代码来源:Monitors.java

示例5: createEntry

import com.netflix.servo.monitor.Stopwatch; //导入依赖的package包/类
@Override
protected BasicPoolEntry createEntry(RouteSpecificPool rospl,
        ClientConnectionOperator op) {
    createEntryCounter.increment();
    Stopwatch stopWatch = creationTimer.start();
    try {
        return super.createEntry(rospl, op);
    } finally {
        stopWatch.stop();
    }
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:12,代码来源:NamedConnectionPool.java

示例6: getEntryBlocking

import com.netflix.servo.monitor.Stopwatch; //导入依赖的package包/类
@Override
protected BasicPoolEntry getEntryBlocking(HttpRoute route, Object state,
        long timeout, TimeUnit tunit, WaitingThreadAborter aborter)
        throws ConnectionPoolTimeoutException, InterruptedException {
    Stopwatch stopWatch = requestTimer.start();
    try {
        return super.getEntryBlocking(route, state, timeout, tunit, aborter);
    } finally {
        stopWatch.stop();
    }
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:12,代码来源:NamedConnectionPool.java

示例7: primeConnections

import com.netflix.servo.monitor.Stopwatch; //导入依赖的package包/类
/**
 * Prime connections, blocking until configured percentage (default is 100%) of target servers are primed 
 * or max time is reached.
 * 
 * @see CommonClientConfigKey#MinPrimeConnectionsRatio
 * @see CommonClientConfigKey#MaxTotalTimeToPrimeConnections
 * 
 */
public void primeConnections(List<Server> servers) {
    if (servers == null || servers.size() == 0) {
        logger.debug("No server to prime");
        return;
    }
    for (Server server: servers) {
        server.setReadyToServe(false);
    }
    int totalCount = (int) (servers.size() * primeRatio); 
    final CountDownLatch latch = new CountDownLatch(totalCount);
    final AtomicInteger successCount = new AtomicInteger(0);
    final AtomicInteger failureCount= new AtomicInteger(0);
    primeConnectionsAsync(servers, new PrimeConnectionListener()  {            
        @Override
        public void primeCompleted(Server s, Throwable lastException) {
            if (lastException == null) {
                successCount.incrementAndGet();
                s.setReadyToServe(true);
            } else {
                failureCount.incrementAndGet();
            }
            latch.countDown();
        }
    }); 
            
    Stopwatch stopWatch = initialPrimeTimer.start();
    try {
        latch.await(maxTotalTimeToPrimeConnections, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
        logger.error("Priming connection interrupted", e);
    } finally {
        stopWatch.stop();
    }

    stats = new PrimeConnectionEndStats(totalCount, successCount.get(), failureCount.get(), stopWatch.getDuration(TimeUnit.MILLISECONDS));

    printStats(stats);
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:47,代码来源:PrimeConnections.java

示例8: asyncGetAndTouch

import com.netflix.servo.monitor.Stopwatch; //导入依赖的package包/类
public <T> EVCacheOperationFuture<CASValue<T>> asyncGetAndTouch(final String key, final int exp, final Transcoder<T> tc) {
    final CountDownLatch latch = new CountDownLatch(1);
    final EVCacheOperationFuture<CASValue<T>> rv = new EVCacheOperationFuture<CASValue<T>>(key, latch, new AtomicReference<CASValue<T>>(null), connectionFactory.getOperationTimeout(), executorService, appName, serverGroup);
    final Stopwatch operationDuration = getTimer(GET_AND_TOUCH_OPERATION_STRING).start();
    Operation op = opFact.getAndTouch(key, exp, new GetAndTouchOperation.Callback() {
        private CASValue<T> val = null;

        public void receivedStatus(OperationStatus status) {
            operationDuration.stop();
            rv.set(val, status);
        }

        public void complete() {
            latch.countDown();
            rv.signalComplete();
        }

        public void gotData(String k, int flags, long cas, byte[] data) {
            if (!key.equals(k)) log.warn("Wrong key returned. Key - {}; Returned Key {}", key, k);
            if (data != null)  {
                if(getAndTouchDataSize == null) getAndTouchDataSize = EVCacheMetricsFactory.getDistributionSummary(appName + "-GATOperation-DataSize", appName, serverGroup.getName());
                if (getAndTouchDataSize != null) getAndTouchDataSize.record(data.length);
            }

            val = new CASValue<T>(cas, tc.decode(new CachedData(flags, data, tc.getMaxSize())));
        }
    });
    rv.setOperation(op);
    mconn.enqueueOperation(key, op);
    return rv;
}
 
开发者ID:Netflix,项目名称:EVCache,代码行数:32,代码来源:EVCacheMemcachedClient.java

示例9: delete

import com.netflix.servo.monitor.Stopwatch; //导入依赖的package包/类
public OperationFuture<Boolean> delete(String key, EVCacheLatch evcacheLatch) {
    final CountDownLatch latch = new CountDownLatch(1);
    final OperationFuture<Boolean> rv = new OperationFuture<Boolean>(key, latch, connectionFactory.getOperationTimeout(), executorService);
    final Stopwatch operationDuration = getTimer(DELETE_STRING).start();
    final DeleteOperation.Callback callback = new DeleteOperation.Callback() {
        @Override
        public void receivedStatus(OperationStatus status) {
            operationDuration.stop();
            rv.set(Boolean.TRUE, status);
            if (status.getStatusCode().equals(StatusCode.SUCCESS)) {
                getCounter(DELETE_OPERATION_SUCCESS_STRING).increment();
            } else {
                getCounter("DeleteOperation-"+ status.getStatusCode().name()).increment();
            }
        }

        @Override
        public void gotData(long cas) {
            rv.setCas(cas);
        }

        @Override
        public void complete() {
            latch.countDown();
            rv.signalComplete();
        }
    };

    final DeleteOperation op = opFact.delete(key, callback);
    rv.setOperation(op);
    if (evcacheLatch != null && evcacheLatch instanceof EVCacheLatchImpl && !client.isInWriteOnly()) ((EVCacheLatchImpl) evcacheLatch).addFuture(rv);
    mconn.enqueueOperation(key, op);
    return rv;
}
 
开发者ID:Netflix,项目名称:EVCache,代码行数:35,代码来源:EVCacheMemcachedClient.java

示例10: touch

import com.netflix.servo.monitor.Stopwatch; //导入依赖的package包/类
public <T> OperationFuture<Boolean> touch(final String key, final int exp, EVCacheLatch evcacheLatch) {
    final CountDownLatch latch = new CountDownLatch(1);
    final OperationFuture<Boolean> rv = new OperationFuture<Boolean>(key, latch, connectionFactory.getOperationTimeout(), executorService);
    final Stopwatch operationDuration = getTimer(TOUCH_OPERATION_STRING).start();
    Operation op = opFact.touch(key, exp, new OperationCallback() {
        @Override
        public void receivedStatus(OperationStatus status) {
            operationDuration.stop();
            rv.set(status.isSuccess(), status);

            if (status.getStatusCode().equals(StatusCode.SUCCESS)) {
                getCounter(TOUCH_OPERATION_SUCCESS_STRING).increment();
            } else {
                getCounter(TOUCH_OPERATION_STRING + "-" + status.getStatusCode().name()).increment();
            }
        }

        @Override
        public void complete() {
            latch.countDown();
            rv.signalComplete();
        }
    });
    rv.setOperation(op);
    if (evcacheLatch != null && evcacheLatch instanceof EVCacheLatchImpl && !client.isInWriteOnly()) ((EVCacheLatchImpl) evcacheLatch).addFuture(rv);
    mconn.enqueueOperation(key, op);
    return rv;
}
 
开发者ID:Netflix,项目名称:EVCache,代码行数:29,代码来源:EVCacheMemcachedClient.java

示例11: incr

import com.netflix.servo.monitor.Stopwatch; //导入依赖的package包/类
public long incr(String key, long by, long def, int exp) {
    final Stopwatch operationDuration = getTimer(INCR_OPERATION_STRING).start();
    long val = 0;
    try {
        val = mutate(Mutator.incr, key, by, def, exp);
    } finally {
        operationDuration.stop();
        if (log.isDebugEnabled()) log.debug("Increment Key : " + key + "; by : " + by + "; default : " + def + "; exp : " + exp 
                + "; val : " + val + "; Elapsed Time - " + operationDuration.getDuration(TimeUnit.MILLISECONDS));
    }
    return val;
}
 
开发者ID:Netflix,项目名称:EVCache,代码行数:13,代码来源:EVCacheMemcachedClient.java

示例12: decr

import com.netflix.servo.monitor.Stopwatch; //导入依赖的package包/类
public long decr(String key, long by, long def, int exp) {
    final Stopwatch operationDuration = getTimer(DECR_OPERATION_STRING).start();
    long val = 0;
    try {
        val = super.decr(key, by, def, exp);
    } finally {
        operationDuration.stop();
        if (log.isDebugEnabled()) log.debug("decrement Key : " + key + "; by : " + by + "; default : " + def + "; exp : " + exp 
                + "; val : " + val + "; Elapsed Time - " + (operationDuration.getDuration(TimeUnit.MILLISECONDS)));
    }
    return val;
}
 
开发者ID:Netflix,项目名称:EVCache,代码行数:13,代码来源:EVCacheMemcachedClient.java

示例13: executionTimer

import com.netflix.servo.monitor.Stopwatch; //导入依赖的package包/类
public static Stopwatch executionTimer(String taskType) {
	return start("task_execute_time", taskType);
}
 
开发者ID:Netflix,项目名称:conductor,代码行数:4,代码来源:WorkflowTaskMetrics.java

示例14: pollForTask

import com.netflix.servo.monitor.Stopwatch; //导入依赖的package包/类
private void pollForTask(Worker worker) {
	
	if(ec != null && !ec.getInstanceRemoteStatus().equals(InstanceStatus.UP)) {
		logger.debug("Instance is NOT UP in discovery - will not poll");
		return;
	}
	
	if(worker.paused()) {
		WorkflowTaskMetrics.paused(worker.getTaskDefName());
		logger.debug("Worker {} has been paused. Not polling anymore!", worker.getClass());
		return;
	}
	String domain = PropertyFactory.getString(worker.getTaskDefName(), DOMAIN, null);		
	if(domain == null){
		domain = PropertyFactory.getString(ALL_WORKERS, DOMAIN, null);		
	}
	logger.debug("Polling {}, domain={}, count = {} timeout = {} ms", worker.getTaskDefName(), domain, worker.getPollCount(), worker.getLongPollTimeoutInMS());
	
	try{

           // get the remaining capacity of worker queue to prevent queue full exception
           int realPollCount = Math.min(workerQueue.remainingCapacity(), worker.getPollCount());
           if (realPollCount <= 0) {
			logger.warn("All workers are busy, not polling.  queue size {}, max {}", workerQueue.size(), workerQueueSize);
			return;
           }
		String taskType = worker.getTaskDefName();
		Stopwatch sw = WorkflowTaskMetrics.pollTimer(worker.getTaskDefName());
		List<Task> tasks = client.poll(taskType, domain, worker.getIdentity(), realPollCount, worker.getLongPollTimeoutInMS());
           sw.stop();
           logger.debug("Polled {}, for domain {} and received {} tasks", worker.getTaskDefName(), domain, tasks.size());
           for(Task task : tasks) {
			es.submit(() -> {
				try {
					execute(worker, task);
				} catch (Throwable t) {
					task.setStatus(Task.Status.FAILED);
					TaskResult result = new TaskResult(task);
					handleException(t, result, worker, true, task);
				}
			});
		}

	}catch(RejectedExecutionException qfe) {
		WorkflowTaskMetrics.queueFull(worker.getTaskDefName());
		logger.error("Execution queue is full", qfe);
	} catch (Exception e) {
		WorkflowTaskMetrics.pollingException(worker.getTaskDefName(), e);
		logger.error("Error when polling for task " + e.getMessage(), e);
	}
}
 
开发者ID:Netflix,项目名称:conductor,代码行数:52,代码来源:WorkflowTaskCoordinator.java

示例15: asyncGet

import com.netflix.servo.monitor.Stopwatch; //导入依赖的package包/类
public <T> EVCacheOperationFuture<T> asyncGet(final String key, final Transcoder<T> tc, EVCacheGetOperationListener<T> listener) {
    final CountDownLatch latch = new CountDownLatch(1);
    final EVCacheOperationFuture<T> rv = new EVCacheOperationFuture<T>(key, latch, new AtomicReference<T>(null), readTimeout.get().intValue(), executorService, appName, serverGroup);
    final Stopwatch operationDuration = getTimer(GET_OPERATION_STRING).start();
    Operation op = opFact.get(key, new GetOperation.Callback() {
        private Future<T> val = null;

        public void receivedStatus(OperationStatus status) {
            operationDuration .stop();
            try {
                if (val != null) {
                    rv.set(val.get(), status);
                } else {
                    rv.set(null, status);
                }
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                rv.set(null, status);
            }
        }

        @SuppressWarnings("unchecked")
        public void gotData(String k, int flags, byte[] data) {

            if (data != null)  {
                if(getDataSize == null) getDataSize = EVCacheMetricsFactory.getDistributionSummary(appName + "-GetOperation-DataSize", appName, serverGroup.getName());
                if (getDataSize != null) getDataSize.record(data.length);
            }
            if (!key.equals(k)) log.warn("Wrong key returned. Key - {}; Returned Key {}", key, k);
            if (tc == null) {
                if (tcService == null) {
                    log.error("tcService is null, will not be able to decode");
                    throw new RuntimeException("TranscoderSevice is null. Not able to decode");
                } else {
                    final Transcoder<T> t = (Transcoder<T>) getTranscoder();
                    val = tcService.decode(t, new CachedData(flags, data, t.getMaxSize()));
                }
            } else {
                if (tcService == null) {
                    log.error("tcService is null, will not be able to decode");
                    throw new RuntimeException("TranscoderSevice is null. Not able to decode");
                } else {
                    val = tcService.decode(tc, new CachedData(flags, data, tc.getMaxSize()));
                }
            }
        }

        public void complete() {
            latch.countDown();
            rv.signalComplete();
        }
    });
    rv.setOperation(op);
    if (listener != null) rv.addListener(listener);
    mconn.enqueueOperation(key, op);
    return rv;
}
 
开发者ID:Netflix,项目名称:EVCache,代码行数:58,代码来源:EVCacheMemcachedClient.java


注:本文中的com.netflix.servo.monitor.Stopwatch类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。