/** * {@inheritDoc} */ @Override public void record(long duration, TimeUnit timeUnit) { record(this.timeUnit.convert(duration, timeUnit)); }
public static StatsTimer getStatsTimer(String appName, ServerGroup serverGroup, String metric, String reason, String status) { final String serverGroupName = (serverGroup != null ? serverGroup.getName() : ""); final String metricName = getMetricName(appName, null, metric); final String name = new StringBuilder(128).append(metricName).append(serverGroupName).append(reason).append(status).append("type=StatsTimer").toString(); final StatsTimer duration = (StatsTimer) monitorMap.get(name); if (duration != null) return duration; writeLock.lock(); try { if (monitorMap.containsKey(name)) return (StatsTimer) monitorMap.get(name); else { final StatsConfig statsConfig = new StatsConfig.Builder().withPercentiles(new double[] { 95, 99 }) .withPublishMax(true).withPublishMin(true) .withPublishMean(true).withPublishCount(true).withSampleSize(sampleSize.get()).build(); final StatsTimer _duration = new StatsTimer(getMonitorConfig(metricName, appName, null, serverGroupName, metric, reason, status), statsConfig, TimeUnit.MILLISECONDS); monitorMap.put(name, _duration); DefaultMonitorRegistry.getInstance().register(_duration); return _duration; } } finally { writeLock.unlock(); } }
/** * Get the total time recorded for this timer. */ public long getTotalTime() { return getTotalMeasurement(); } }
@Test public void testNoRecordedValues() throws Exception { final StatsTimer timer = newInstance("novalue"); assertEquals(timer.getCount(), 0L); assertEquals(timer.getTotalTime(), 0L); final long timerValue = timer.getValue(); assertEquals(timerValue, 0L); }
@Test public void testStats() throws Exception { final StatsTimer timer = newInstance("t1"); final Map<String, Number> expectedValues = new HashMap<>(); final int n = 200 * 1000; expectedValues.put("count", (long) n); expectedValues.put("totalTime", (long) n * (n - 1) / 2); expectedValues.put("stdDev", 57735.17); expectedValues.put("percentile_50", 100 * 1000.0); expectedValues.put("percentile_95", 190 * 1000.0); expectedValues.put("percentile_99", 198 * 1000.0); expectedValues.put("percentile_99.50", 199 * 1000.0); for (int i = 0; i < n; ++i) { timer.record(i); } timer.computeStats(); assertStats(timer.getMonitors(), expectedValues); }
@Test public void testStatsTimerRecordMillis() { StatsConfig sc = new StatsConfig.Builder() .withPercentiles(new double[] {50.0, 95.0}) .withPublishCount(true) .withPublishMax(true) .withPublishMean(true) .withSampleSize(10) .build(); StatsTimer d = new StatsTimer(CONFIG, sc); register(d); d.record(42, TimeUnit.MILLISECONDS); d.computeStats(); Id id = ID.withTag("unit", "MILLISECONDS"); assertEquals(1, registry.counter(id.withTag(Statistic.count)).count()); assertEquals(42.0, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12); assertEquals(42.0, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12); assertEquals(42.0, registry.gauge(id.withTag("statistic", "percentile_50")).value(), 1e-12); assertEquals(42.0, registry.gauge(id.withTag("statistic", "percentile_95")).value(), 1e-12); assertEquals(42.0, registry.gauge(id.withTag("statistic", "avg")).value(), 1e-12); }
final Collection<Operation> timedoutOps = new HashSet<Operation>(); final Stopwatch operationDuration = EVCacheMetricsFactory.getStatsTimer(appName, serverGroup, metricName).start(); final long startTime = System.currentTimeMillis(); boolean status = latch.await(to, unit); EVCacheMetricsFactory.getStatsTimer(appName, serverGroup, "Pause-bulk", gcPause ? "GC":"Scheduling", status ? "Succcess":"Fail").record(pauseDuration);
firstKeys.add(key + "_00"); final Stopwatch operationDuration = EVCacheMetricsFactory.getStatsTimer(appName, serverGroup, "LatencyChunk").start(); try { final Map<String, CachedData> metadataMap = evcacheMemcachedClient.asyncGetBulk(firstKeys, chunkingTranscoder, null, "GetChunkMetadataOperation")
public long getGetDuration() { return getGetCallDuration().getValue().longValue(); }
/** * Creates a new instance of the timer with a unit of milliseconds, * using the {@link ScheduledExecutorService} provided by * the user. * To avoid memory leaks the ScheduledExecutorService * should have the policy to remove tasks from the work queue. * See {@link java.util.concurrent.ScheduledThreadPoolExecutor#setRemoveOnCancelPolicy(boolean)} */ public StatsTimer(MonitorConfig config, StatsConfig statsConfig, TimeUnit unit, ScheduledExecutorService executor) { super(config, statsConfig, executor, "totalTime", false, Tags.newTag(UNIT, unit.name())); this.timeUnit = unit; startComputingStats(); }
firstKeys.add(key + "_00"); final Stopwatch operationDuration = EVCacheMetricsFactory.getStatsTimer(appName, serverGroup, "LatencyChunk").start();
public long getBulkDuration() { return getBulkCallDuration().getValue().longValue(); }
/** * Creates a new instance of the timer with a unit of milliseconds, * using the {@link ScheduledExecutorService} provided by * the user. * To avoid memory leaks the ScheduledExecutorService * should have the policy to remove tasks from the work queue. * See {@link java.util.concurrent.ScheduledThreadPoolExecutor#setRemoveOnCancelPolicy(boolean)} */ public StatsTimer(MonitorConfig config, StatsConfig statsConfig, TimeUnit unit, ScheduledExecutorService executor) { super(config, statsConfig, executor, "totalTime", false, Tags.newTag(UNIT, unit.name())); this.timeUnit = unit; startComputingStats(); }
<ID, T> void registerExpiryTimes(List<TaskHolder<ID, T>> holders) { long now = System.currentTimeMillis(); for (TaskHolder<ID, T> holder : holders) { taskWaitingTimeForProcessing.record(now - holder.getSubmitTimestamp(), TimeUnit.MILLISECONDS); } } }
public static StatsTimer getStatsTimer(String appName, ServerGroup serverGroup, String metric) { final String serverGroupName = (serverGroup != null ? serverGroup.getName() : ""); final String metricName = getMetricName(appName, null, metric); final String name = new StringBuilder(128).append( metricName).append(serverGroupName).append("type=StatsTimer").toString(); final StatsTimer duration = (StatsTimer) monitorMap.get(name); if (duration != null) return duration; writeLock.lock(); try { if (monitorMap.containsKey(name)) return (StatsTimer) monitorMap.get(name); else { final StatsConfig statsConfig = new StatsConfig.Builder().withPercentiles(new double[] { 95, 99 }) .withPublishMax(true).withPublishMin(true) .withPublishMean(true).withPublishCount(true).withSampleSize(sampleSize.get()).build(); final StatsTimer _duration = new StatsTimer(getMonitorConfig(metricName, appName, null, serverGroupName, metric), statsConfig, TimeUnit.MILLISECONDS); monitorMap.put(name, _duration); DefaultMonitorRegistry.getInstance().register(_duration); return _duration; } } finally { writeLock.unlock(); } }
private <T> T assembleChunks(String key, boolean touch, int ttl, Transcoder<T> tc, boolean hasZF) { final Stopwatch operationDuration = EVCacheMetricsFactory.getStatsTimer(appName, serverGroup, "LatencyChunk").start(); try {
/** * Get the total time recorded for this timer. */ public long getTotalTime() { return getTotalMeasurement(); } }
<ID, T> void registerExpiryTime(TaskHolder<ID, T> holder) { taskWaitingTimeForProcessing.record(System.currentTimeMillis() - holder.getSubmitTimestamp(), TimeUnit.MILLISECONDS); }
public static StatsTimer getStatsTimer(String appName, String cacheName, String metric) { final String metricName = getMetricName(appName, null, metric); final String name = new StringBuilder(128).append(metricName).append((cacheName == null ? "" : "-" + cacheName + "-")).append("type=StatsTimer").toString(); final StatsTimer duration = (StatsTimer) monitorMap.get(name); if (duration != null) return duration; writeLock.lock(); try { if (monitorMap.containsKey(name)) return (StatsTimer) monitorMap.get(name); else { final StatsConfig statsConfig = new StatsConfig.Builder().withPercentiles(new double[] { 95, 99 }) .withPublishMax(true).withPublishMin(true) .withPublishMean(true).withPublishCount(true).withSampleSize(sampleSize.get()).build(); final StatsTimer _duration = new StatsTimer(getMonitorConfig(metricName, appName, cacheName, metric), statsConfig, TimeUnit.MILLISECONDS); monitorMap.put(name, _duration); DefaultMonitorRegistry.getInstance().register(_duration); return _duration; } } finally { writeLock.unlock(); } }
private <T> Single<T> assembleChunks(String key, boolean touch, int ttl, Transcoder<T> tc, boolean hasZF, Scheduler scheduler) { final Stopwatch operationDuration = EVCacheMetricsFactory.getStatsTimer(appName, serverGroup, "LatencyChunk").start(); return getChunkDetails(key, scheduler).flatMap(cd -> { if (cd == null) return Single.just(null);