/** * Indicate that we just uploaded a block and record its latency. * @param latency The latency in milliseconds. */ public void blockUploaded(long latency) { currentBlockUploadLatency.addPoint(latency); }
/** * Get the current rolling average of the download latency. * @return rolling average of download latency in milliseconds. */ public long getBlockDownloadLatency() { return currentBlockDownloadLatency.getCurrentAverage(); }
/** * Tests the basic functionality of the class. */ @Test public void testBasicFunctionality() throws Exception { RollingWindowAverage average = new RollingWindowAverage(100); assertEquals(0, average.getCurrentAverage()); // Nothing there yet. average.addPoint(5); assertEquals(5, average.getCurrentAverage()); // One point in there. Thread.sleep(50); average.addPoint(15); assertEquals(10, average.getCurrentAverage()); // Two points in there. Thread.sleep(60); assertEquals(15, average.getCurrentAverage()); // One point retired. Thread.sleep(50); assertEquals(0, average.getCurrentAverage()); // Both points retired. } }
public AzureFileSystemInstrumentation(Configuration conf) { fileSystemInstanceId = UUID.randomUUID(); registry.tag("wasbFileSystemId", "A unique identifier for the file ", fileSystemInstanceId.toString()); final int rollingWindowSizeInSeconds = conf.getInt(KEY_ROLLING_WINDOW_SIZE, DEFAULT_LATENCY_ROLLING_AVERAGE_WINDOW); averageBlockUploadLatencyMs = registry.newGauge( WASB_UPLOAD_LATENCY, String.format("The average latency in milliseconds of uploading a single block" + ". The average latency is calculated over a %d-second rolling" + " window.", rollingWindowSizeInSeconds), 0L); averageBlockDownloadLatencyMs = registry.newGauge( WASB_DOWNLOAD_LATENCY, String.format("The average latency in milliseconds of downloading a single block" + ". The average latency is calculated over a %d-second rolling" + " window.", rollingWindowSizeInSeconds), 0L); currentBlockUploadLatency = new RollingWindowAverage(rollingWindowSizeInSeconds * 1000); currentBlockDownloadLatency = new RollingWindowAverage(rollingWindowSizeInSeconds * 1000); }
/** * Get the current average. * @return The current average. */ public synchronized long getCurrentAverage() { cleanupOldPoints(); if (currentPoints.isEmpty()) { return 0; } long sum = 0; for (DataPoint current : currentPoints) { sum += current.getValue(); } return sum / currentPoints.size(); }
/** * Tests the basic functionality of the class. */ @Test public void testBasicFunctionality() throws Exception { RollingWindowAverage average = new RollingWindowAverage(100); assertEquals(0, average.getCurrentAverage()); // Nothing there yet. average.addPoint(5); assertEquals(5, average.getCurrentAverage()); // One point in there. Thread.sleep(50); average.addPoint(15); assertEquals(10, average.getCurrentAverage()); // Two points in there. Thread.sleep(60); assertEquals(15, average.getCurrentAverage()); // One point retired. Thread.sleep(50); assertEquals(0, average.getCurrentAverage()); // Both points retired. } }
public AzureFileSystemInstrumentation(Configuration conf) { fileSystemInstanceId = UUID.randomUUID(); registry.tag("wasbFileSystemId", "A unique identifier for the file ", fileSystemInstanceId.toString()); final int rollingWindowSizeInSeconds = conf.getInt(KEY_ROLLING_WINDOW_SIZE, DEFAULT_LATENCY_ROLLING_AVERAGE_WINDOW); averageBlockUploadLatencyMs = registry.newGauge( WASB_UPLOAD_LATENCY, String.format("The average latency in milliseconds of uploading a single block" + ". The average latency is calculated over a %d-second rolling" + " window.", rollingWindowSizeInSeconds), 0L); averageBlockDownloadLatencyMs = registry.newGauge( WASB_DOWNLOAD_LATENCY, String.format("The average latency in milliseconds of downloading a single block" + ". The average latency is calculated over a %d-second rolling" + " window.", rollingWindowSizeInSeconds), 0L); currentBlockUploadLatency = new RollingWindowAverage(rollingWindowSizeInSeconds * 1000); currentBlockDownloadLatency = new RollingWindowAverage(rollingWindowSizeInSeconds * 1000); }
/** * Get the current average. * @return The current average. */ public synchronized long getCurrentAverage() { cleanupOldPoints(); if (currentPoints.isEmpty()) { return 0; } long sum = 0; for (DataPoint current : currentPoints) { sum += current.getValue(); } return sum / currentPoints.size(); }
/** * Get the current rolling average of the upload latency. * @return rolling average of upload latency in milliseconds. */ public long getBlockUploadLatency() { return currentBlockUploadLatency.getCurrentAverage(); }
/** * Indicate that we just downloaded a block and record its latency. * @param latency The latency in milliseconds. */ public void blockDownloaded(long latency) { currentBlockDownloadLatency.addPoint(latency); }
/** * Add a new data point that just happened. * @param value The value of the data point. */ public synchronized void addPoint(long value) { currentPoints.offer(new DataPoint(new Date(), value)); cleanupOldPoints(); }
/** * Get the current rolling average of the upload latency. * @return rolling average of upload latency in milliseconds. */ public long getBlockUploadLatency() { return currentBlockUploadLatency.getCurrentAverage(); }
/** * Indicate that we just uploaded a block and record its latency. * @param latency The latency in milliseconds. */ public void blockUploaded(long latency) { currentBlockUploadLatency.addPoint(latency); }
/** * Add a new data point that just happened. * @param value The value of the data point. */ public synchronized void addPoint(long value) { currentPoints.offer(new DataPoint(new Date(), value)); cleanupOldPoints(); }
/** * Get the current rolling average of the download latency. * @return rolling average of download latency in milliseconds. */ public long getBlockDownloadLatency() { return currentBlockDownloadLatency.getCurrentAverage(); }
/** * Indicate that we just downloaded a block and record its latency. * @param latency The latency in milliseconds. */ public void blockDownloaded(long latency) { currentBlockDownloadLatency.addPoint(latency); }
@Override public void getMetrics(MetricsCollector builder, boolean all) { averageBlockDownloadLatencyMs.set( currentBlockDownloadLatency.getCurrentAverage()); averageBlockUploadLatencyMs.set( currentBlockUploadLatency.getCurrentAverage()); registry.snapshot(builder.addRecord(registry.info().name()), true); } }
@Override public void getMetrics(MetricsCollector builder, boolean all) { averageBlockDownloadLatencyMs.set( currentBlockDownloadLatency.getCurrentAverage()); averageBlockUploadLatencyMs.set( currentBlockUploadLatency.getCurrentAverage()); registry.snapshot(builder.addRecord(registry.info().name()), true); } }