• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Stopwatch类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: pollTimer

import com.netflix.servo.monitor.Stopwatch; //导入依赖的package包/类
public static Stopwatch pollTimer(String taskType) {
	return start("task_poll_time", taskType);

}
 
开发者ID:Netflix,项目名称:conductor,代码行数:5,代码来源:WorkflowTaskMetrics.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RetrieveConf类代码示例发布时间:2022-05-22
下一篇:
Java BiMap类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap